Skip to content

Commit bf35a46

Browse files
author
arjunsk
committed
Final Commit
1 parent c3f4d76 commit bf35a46

File tree

16 files changed

+174
-170
lines changed

16 files changed

+174
-170
lines changed

docs/diagrams/D_CalciteQueryEngine.puml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ package MetadataMgr_TableCatalog
1313
package RW_HeapRecordScan
1414

1515

16-
CalciteEnumerator <...> MetadataMgr_TableCatalog
17-
CalciteEnumerator <...> RW_HeapRecordScan
16+
CalciteEnumerator <..> MetadataMgr_TableCatalog
17+
CalciteEnumerator <..> RW_HeapRecordScan
1818
CalciteEnumerator ---> CalciteTable
1919

2020
MetadataMgr_TableCatalog -> RW_HeapRecordScan

src/main/java/edu/utdallas/tiny_db/server/b_query_engine/common/catalog/MetadataMgr.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package edu.utdallas.tiny_db.server.b_query_engine.common.catalog;
22

3-
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.StatMgr;
4-
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.domain.StatInfo;
3+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.StatMgr;
4+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.domain.StatInfo;
55
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.index.IndexInfo;
66
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.index.IndexMgr;
77
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableMgr;

src/main/java/edu/utdallas/tiny_db/server/b_query_engine/common/catalog/index/IndexInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static java.sql.Types.INTEGER;
44

5-
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.domain.StatInfo;
5+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.domain.StatInfo;
66
import edu.utdallas.tiny_db.server.d_storage_engine.common.transaction.Transaction;
77
import edu.utdallas.tiny_db.server.d_storage_engine.RWIndexScan;
88
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TablePhysicalLayout;
Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
11
package edu.utdallas.tiny_db.server.b_query_engine.common.catalog.index;
22

3-
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.StatMgr;
4-
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.domain.StatInfo;
3+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.StatMgr;
4+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.domain.StatInfo;
5+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableDefinition;
56
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableMgr;
7+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TablePhysicalLayout;
68
import edu.utdallas.tiny_db.server.d_storage_engine.common.transaction.Transaction;
79
import edu.utdallas.tiny_db.server.d_storage_engine.impl.data.heap.HeapRWRecordScan;
8-
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TablePhysicalLayout;
9-
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableDefinition;
10-
1110
import java.util.HashMap;
1211
import java.util.Map;
1312

1413
/**
15-
* The index manager.
16-
* The index manager has similar functionality to the table manager.
14+
* The index manager. The index manager has similar functionality to the table manager.
1715
*
1816
* @author Edward Sciore
1917
*/
2018
public class IndexMgr {
21-
private TablePhysicalLayout recordValueLayout;
22-
private TableMgr tblmgr;
23-
private StatMgr statmgr;
2419

25-
/**
26-
* Create the index manager.
27-
* This constructor is called during system startup.
28-
* If the database is new, then the <i>idxcat</i> table is created.
29-
*
30-
* @param isnew indicates whether this is a new database
31-
* @param tx the system startup transaction
32-
*/
33-
public IndexMgr(boolean isnew, TableMgr tblmgr, StatMgr statmgr, Transaction tx) {
34-
if (isnew) {
35-
TableDefinition sch = new TableDefinition();
36-
sch.addStringField("indexname", TableMgr.MAX_NAME);
37-
sch.addStringField("tablename", TableMgr.MAX_NAME);
38-
sch.addStringField("fieldname", TableMgr.MAX_NAME);
39-
tblmgr.createTable("idxcat", sch, tx);
40-
}
41-
this.tblmgr = tblmgr;
42-
this.statmgr = statmgr;
43-
recordValueLayout = tblmgr.getLayout("idxcat", tx);
44-
}
20+
private TablePhysicalLayout recordValueLayout;
21+
private TableMgr tblmgr;
22+
private StatMgr statmgr;
23+
24+
/**
25+
* Create the index manager. This constructor is called during system startup. If the database is
26+
* new, then the <i>idxcat</i> table is created.
27+
*
28+
* @param isnew indicates whether this is a new database
29+
* @param tx the system startup transaction
30+
*/
31+
public IndexMgr(boolean isnew, TableMgr tblmgr, StatMgr statmgr, Transaction tx) {
32+
if (isnew) {
33+
TableDefinition sch = new TableDefinition();
34+
sch.addStringField("indexname", TableMgr.MAX_NAME);
35+
sch.addStringField("tablename", TableMgr.MAX_NAME);
36+
sch.addStringField("fieldname", TableMgr.MAX_NAME);
4537

46-
/**
47-
* Create an index of the specified type for the specified field.
48-
* A unique ID is assigned to this index, and its information
49-
* is stored in the idxcat table.
50-
*
51-
* @param idxname the name of the index
52-
* @param tblname the name of the indexed table
53-
* @param fldname the name of the indexed field
54-
* @param tx the calling transaction
55-
*/
56-
public void createIndex(String idxname, String tblname, String fldname, Transaction tx) {
57-
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout);
58-
ts.seekToInsertStart();
59-
ts.setString("indexname", idxname);
60-
ts.setString("tablename", tblname);
61-
ts.setString("fieldname", fldname);
62-
ts.close();
38+
tblmgr.createTable("idxcat", sch, tx);
6339
}
40+
this.tblmgr = tblmgr;
41+
this.statmgr = statmgr;
42+
recordValueLayout = tblmgr.getLayout("idxcat", tx);
43+
}
44+
45+
/**
46+
* Create an index of the specified type for the specified field. A unique ID is assigned to this
47+
* index, and its information is stored in the idxcat table.
48+
*
49+
* @param idxname the name of the index
50+
* @param tblname the name of the indexed table
51+
* @param fldname the name of the indexed field
52+
* @param tx the calling transaction
53+
*/
54+
public void createIndex(String idxname, String tblname, String fldname, Transaction tx) {
55+
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout);
56+
ts.seekToInsertStart();
57+
ts.setString("indexname", idxname);
58+
ts.setString("tablename", tblname);
59+
ts.setString("fieldname", fldname);
60+
ts.close();
61+
}
62+
63+
/**
64+
* Return a map containing the index info for all indexes on the specified table.
65+
*
66+
* @param tblname the name of the table
67+
* @param tx the calling transaction
68+
* @return a map of IndexInfo objects, keyed by their field names
69+
*/
70+
public Map<String, IndexInfo> getIndexInfo(String tblname, Transaction tx) {
71+
Map<String, IndexInfo> result = new HashMap<String, IndexInfo>();
72+
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout);
73+
while (ts.next()) {
74+
if (ts.getString("tablename").equals(tblname)) {
75+
String idxname = ts.getString("indexname");
76+
String fldname = ts.getString("fieldname");
77+
TablePhysicalLayout tblRecordValueLayout = tblmgr.getLayout(tblname, tx);
78+
StatInfo tblsi = statmgr.getStatInfo(tblname, tblRecordValueLayout, tx);
6479

65-
/**
66-
* Return a map containing the index info for all indexes
67-
* on the specified table.
68-
*
69-
* @param tblname the name of the table
70-
* @param tx the calling transaction
71-
* @return a map of IndexInfo objects, keyed by their field names
72-
*/
73-
public Map<String, IndexInfo> getIndexInfo(String tblname, Transaction tx) {
74-
Map<String, IndexInfo> result = new HashMap<String, IndexInfo>();
75-
HeapRWRecordScan ts = new HeapRWRecordScan(tx, "idxcat", recordValueLayout);
76-
while (ts.next()) if (ts.getString("tablename").equals(tblname)) {
77-
String idxname = ts.getString("indexname");
78-
String fldname = ts.getString("fieldname");
79-
TablePhysicalLayout tblRecordValueLayout = tblmgr.getLayout(tblname, tx);
80-
StatInfo tblsi = statmgr.getStatInfo(tblname, tblRecordValueLayout, tx);
81-
IndexInfo ii = new IndexInfo(idxname, fldname, tblRecordValueLayout.schema(), tx, tblsi);
82-
result.put(fldname, ii);
83-
}
84-
ts.close();
85-
return result;
80+
IndexInfo ii = new IndexInfo(idxname, fldname, tblRecordValueLayout.schema(), tx, tblsi);
81+
result.put(fldname, ii);
82+
}
8683
}
84+
ts.close();
85+
return result;
86+
}
8787
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager;
1+
package edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats;
22

3-
import edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.domain.StatInfo;
3+
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.domain.StatInfo;
44
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TableMgr;
55
import edu.utdallas.tiny_db.server.d_storage_engine.common.transaction.Transaction;
66
import edu.utdallas.tiny_db.server.b_query_engine.common.catalog.table.TablePhysicalLayout;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package edu.utdallas.tiny_db.server.b_query_engine.impl.basic.b_stats_manager.domain;
1+
package edu.utdallas.tiny_db.server.b_query_engine.common.catalog.stats.domain;
22

33
/**
44
* A StatInfo object holds three pieces of

src/main/java/edu/utdallas/tiny_db/server/b_query_engine/common/catalog/table/TableMgr.java

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,108 +2,110 @@
22

33
import edu.utdallas.tiny_db.server.d_storage_engine.common.transaction.Transaction;
44
import edu.utdallas.tiny_db.server.d_storage_engine.impl.data.heap.HeapRWRecordScan;
5-
65
import java.util.HashMap;
76
import java.util.Map;
87

98
/**
10-
* The table manager.
11-
* There are methods to create a table, save the metadata
12-
* in the catalog, and obtain the metadata of a
13-
* previously-created table.
9+
* The table manager. There are methods to create a table, save the metadata in the catalog, and
10+
* obtain the metadata of a previously-created table.
1411
*
1512
* @author Edward Sciore
1613
*/
1714
public class TableMgr {
18-
// The max characters a tablename or fieldname can have.
19-
public static final int MAX_NAME = 16;
20-
private TablePhysicalLayout tcatRecordValueLayout, fcatRecordValueLayout;
2115

22-
/**
23-
* Create a new catalog manager for the database system.
24-
* If the database is new, the two catalog tables
25-
* are created.
26-
*
27-
* @param isNew has the value true if the database is new
28-
* @param tx the startup transaction
29-
*/
30-
public TableMgr(boolean isNew, Transaction tx) {
31-
TableDefinition tcatTableDefinition = new TableDefinition();
32-
tcatTableDefinition.addStringField("tblname", MAX_NAME);
33-
tcatTableDefinition.addIntField("slotsize");
34-
tcatRecordValueLayout = new TablePhysicalLayout(tcatTableDefinition);
16+
// The max characters a tablename or fieldname can have.
17+
public static final int MAX_NAME = 16;
18+
private TablePhysicalLayout tcatRecordValueLayout, fcatRecordValueLayout;
19+
20+
/**
21+
* Create a new catalog manager for the database system. If the database is new, the two catalog
22+
* tables are created.
23+
*
24+
* @param isNew has the value true if the database is new
25+
* @param tx the startup transaction
26+
*/
27+
public TableMgr(boolean isNew, Transaction tx) {
28+
TableDefinition tcatTableDefinition = new TableDefinition();
29+
tcatTableDefinition.addStringField("tblname", MAX_NAME);
30+
tcatTableDefinition.addIntField("slotsize");
31+
tcatRecordValueLayout = new TablePhysicalLayout(tcatTableDefinition);
3532

36-
TableDefinition fcatTableDefinition = new TableDefinition();
37-
fcatTableDefinition.addStringField("tblname", MAX_NAME);
38-
fcatTableDefinition.addStringField("fldname", MAX_NAME);
39-
fcatTableDefinition.addIntField("type");
40-
fcatTableDefinition.addIntField("length");
41-
fcatTableDefinition.addIntField("offset");
42-
fcatRecordValueLayout = new TablePhysicalLayout(fcatTableDefinition);
33+
TableDefinition fcatTableDefinition = new TableDefinition();
34+
fcatTableDefinition.addStringField("tblname", MAX_NAME);
35+
fcatTableDefinition.addStringField("fldname", MAX_NAME);
36+
fcatTableDefinition.addIntField("type");
37+
fcatTableDefinition.addIntField("length");
38+
fcatTableDefinition.addIntField("offset");
39+
fcatRecordValueLayout = new TablePhysicalLayout(fcatTableDefinition);
4340

44-
if (isNew) {
45-
createTable("tinydb_tables", tcatTableDefinition, tx);
46-
createTable("tinydb_columns", fcatTableDefinition, tx);
47-
}
41+
if (isNew) {
42+
createTable("tinydb_tables", tcatTableDefinition, tx);
43+
createTable("tinydb_columns", fcatTableDefinition, tx);
4844
}
45+
}
4946

50-
/**
51-
* Create a new table having the specified name and schema.
52-
*
53-
* @param tblname the name of the new table
54-
* @param sch the table's schema
55-
* @param tx the transaction creating the table
56-
*/
57-
public void createTable(String tblname, TableDefinition sch, Transaction tx) {
58-
TablePhysicalLayout recordValueLayout = new TablePhysicalLayout(sch);
47+
/**
48+
* Create a new table having the specified name and schema.
49+
*
50+
* @param tblname the name of the new table
51+
* @param sch the table's schema
52+
* @param tx the transaction creating the table
53+
*/
54+
public void createTable(String tblname, TableDefinition sch, Transaction tx) {
55+
TablePhysicalLayout recordValueLayout = new TablePhysicalLayout(sch);
5956

60-
HeapRWRecordScan tcat = new HeapRWRecordScan(tx, "tinydb_tables", tcatRecordValueLayout);
61-
tcat.seekToInsertStart();
62-
tcat.setString("tblname", tblname);
63-
tcat.setInt("slotsize", recordValueLayout.slotSize());
64-
tcat.close();
57+
HeapRWRecordScan tcat = new HeapRWRecordScan(tx, "tinydb_tables", tcatRecordValueLayout);
58+
tcat.seekToInsertStart();
59+
tcat.setString("tblname", tblname);
60+
tcat.setInt("slotsize", recordValueLayout.slotSize());
61+
tcat.close();
6562

66-
HeapRWRecordScan fcat = new HeapRWRecordScan(tx, "tinydb_columns", fcatRecordValueLayout);
67-
for (String fldname : sch.fields()) {
68-
fcat.seekToInsertStart();
69-
fcat.setString("tblname", tblname);
70-
fcat.setString("fldname", fldname);
71-
fcat.setInt("type", sch.type(fldname));
72-
fcat.setInt("length", sch.length(fldname));
73-
fcat.setInt("offset", recordValueLayout.offset(fldname));
74-
}
75-
fcat.close();
63+
HeapRWRecordScan fcat = new HeapRWRecordScan(tx, "tinydb_columns", fcatRecordValueLayout);
64+
for (String fldname : sch.fields()) {
65+
fcat.seekToInsertStart();
66+
fcat.setString("tblname", tblname);
67+
fcat.setString("fldname", fldname);
68+
fcat.setInt("type", sch.type(fldname));
69+
fcat.setInt("length", sch.length(fldname));
70+
fcat.setInt("offset", recordValueLayout.offset(fldname));
7671
}
72+
fcat.close();
73+
}
7774

78-
/**
79-
* Retrieve the layout of the specified table
80-
* from the catalog.
81-
*
82-
* @param tblname the name of the table
83-
* @param tx the transaction
84-
* @return the table's stored metadata
85-
*/
86-
public TablePhysicalLayout getLayout(String tblname, Transaction tx) {
87-
int size = -1;
88-
HeapRWRecordScan tcat = new HeapRWRecordScan(tx, "tinydb_tables", tcatRecordValueLayout);
89-
while (tcat.next()) if (tcat.getString("tblname").equals(tblname)) {
90-
size = tcat.getInt("slotsize");
91-
break;
92-
}
93-
tcat.close();
75+
/**
76+
* Retrieve the layout of the specified table from the catalog.
77+
*
78+
* @param tblname the name of the table
79+
* @param tx the transaction
80+
* @return the table's stored metadata
81+
*/
82+
public TablePhysicalLayout getLayout(String tblname, Transaction tx) {
83+
int size = -1;
84+
HeapRWRecordScan tcat = new HeapRWRecordScan(tx, "tinydb_tables", tcatRecordValueLayout);
85+
// [tableName1, slotsize1] | [tableName2, slotsize2] | [tableName3, slotsize3]
86+
while (tcat.next()) {
87+
if (tcat.getString("tblname").equals(tblname)) {
88+
size = tcat.getInt("slotsize");
89+
break;
90+
}
91+
}
92+
tcat.close();
9493

95-
TableDefinition sch = new TableDefinition();
96-
Map<String, Integer> offsets = new HashMap<String, Integer>();
97-
HeapRWRecordScan fcat = new HeapRWRecordScan(tx, "tinydb_columns", fcatRecordValueLayout);
98-
while (fcat.next()) if (fcat.getString("tblname").equals(tblname)) {
99-
String fldname = fcat.getString("fldname");
100-
int fldtype = fcat.getInt("type");
101-
int fldlen = fcat.getInt("length");
102-
int offset = fcat.getInt("offset");
103-
offsets.put(fldname, offset);
104-
sch.addField(fldname, fldtype, fldlen);
105-
}
106-
fcat.close();
107-
return new TablePhysicalLayout(sch, offsets, size);
94+
TableDefinition sch = new TableDefinition();
95+
Map<String, Integer> offsets = new HashMap<String, Integer>();
96+
HeapRWRecordScan fcat = new HeapRWRecordScan(tx, "tinydb_columns", fcatRecordValueLayout);
97+
// [tableName1, A, int, 4, offset] | [tableName1, B, varchar, 9, offset] | [tableName3, fldname, type, length offset]
98+
while (fcat.next()) {
99+
if (fcat.getString("tblname").equals(tblname)) {
100+
String fldname = fcat.getString("fldname");
101+
int fldtype = fcat.getInt("type");
102+
int fldlen = fcat.getInt("length");
103+
int offset = fcat.getInt("offset");
104+
offsets.put(fldname, offset);
105+
sch.addField(fldname, fldtype, fldlen);
106+
}
108107
}
108+
fcat.close();
109+
return new TablePhysicalLayout(sch, offsets, size);
110+
}
109111
}

0 commit comments

Comments
 (0)