Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 0d668ad

Browse files
Fix all tests
1 parent 39f1f0f commit 0d668ad

File tree

5 files changed

+39
-37
lines changed

5 files changed

+39
-37
lines changed

src/catalog/layout_catalog.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Peloton
44
//
5-
// column_catalog.h
5+
// layout_catalog.h
66
//
77
// Identification: src/include/catalog/layout_catalog.cpp
88
//
@@ -15,6 +15,7 @@
1515
#include "catalog/catalog.h"
1616
#include "catalog/system_catalogs.h"
1717
#include "concurrency/transaction_context.h"
18+
#include "executor/logical_tile.h"
1819
#include "storage/data_table.h"
1920
#include "storage/layout.h"
2021

@@ -164,24 +165,32 @@ LayoutCatalog::GetLayouts(oid_t table_oid,
164165
auto result_tiles =
165166
GetResultWithIndexScan(column_ids, index_offset, values, txn);
166167

167-
for (auto &tile : (*result_tiles)) {
168-
for (auto tuple_id : *tile) {
169-
oid_t layout_oid =
170-
tile->GetValue(tuple_id, LayoutCatalog::ColumnId::LAYOUT_OID)
171-
.GetAs<oid_t>();
172-
oid_t num_coulmns =
173-
tile->GetValue(tuple_id, LayoutCatalog::ColumnId::NUM_COLUMNS)
174-
.GetAs<oid_t>();
175-
176-
std::string column_map_str =
177-
tile->GetValue(tuple_id, LayoutCatalog::ColumnId::COLUMN_MAP)
178-
.GetAs<std::string>();
179-
auto column_map = storage::Layout::DeserializeColumnMap(num_coulmns,
180-
column_map_str);
181-
auto layout_object =
182-
std::make_shared<const storage::Layout>(column_map, layout_oid);
183-
table_object->InsertLayout(layout_object);
184-
}
168+
// result_tiles should contain only 1 LogicalTile per table
169+
auto result_size = (*result_tiles).size();
170+
PELOTON_ASSERT(result_size <= 1);
171+
if (result_size == 0) {
172+
LOG_DEBUG("No entry for table %u in pg_layout", table_oid);
173+
return table_object->GetLayouts();
174+
}
175+
176+
// Get the LogicalTile
177+
auto tile = (*result_tiles)[0].get();
178+
auto tuple_count = tile->GetTupleCount();
179+
for (oid_t tuple_id = 0; tuple_id < tuple_count; tuple_id++) {
180+
oid_t layout_oid =
181+
tile->GetValue(tuple_id, LayoutCatalog::ColumnId::LAYOUT_OID)
182+
.GetAs<oid_t>();
183+
oid_t num_columns =
184+
tile->GetValue(tuple_id, LayoutCatalog::ColumnId::NUM_COLUMNS)
185+
.GetAs<oid_t>();
186+
std::string column_map_str =
187+
tile->GetValue(tuple_id, LayoutCatalog::ColumnId::COLUMN_MAP)
188+
.ToString();
189+
auto column_map = storage::Layout::DeserializeColumnMap(num_columns,
190+
column_map_str);
191+
auto layout_object =
192+
std::make_shared<const storage::Layout>(column_map, layout_oid);
193+
table_object->InsertLayout(layout_object);
185194
}
186195

187196
return table_object->GetLayouts();

src/include/storage/layout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Peloton
44
//
5-
// tuple.h
5+
// layout.h
66
//
77
// Identification: src/include/storage/layout.h
88
//

src/storage/layout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Peloton
44
//
5-
// tuple.cpp
5+
// layout.cpp
66
//
77
// Identification: src/storage/layout.cpp
88
//

test/catalog/catalog_test.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ TEST_F(CatalogTests, DroppingTable) {
235235
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
236236
auto txn = txn_manager.BeginTransaction();
237237
auto catalog = catalog::Catalog::GetInstance();
238-
// NOTE: everytime we create a database, there will be 8 catalog tables inside
239-
EXPECT_EQ(
240-
11,
238+
// NOTE: everytime we create a database, there will be 9 catalog tables inside
239+
EXPECT_EQ(CATALOG_TABLES_COUNT+3,
241240
(int)catalog->GetDatabaseObject("emp_db", txn)->GetTableObjects().size());
242241
auto database_object =
243242
catalog::Catalog::GetInstance()->GetDatabaseObject("emp_db", txn);
@@ -250,8 +249,7 @@ TEST_F(CatalogTests, DroppingTable) {
250249
EXPECT_NE(nullptr, database_object);
251250
auto department_table_object =
252251
database_object->GetTableObject("department_table", DEFAULT_SCHEMA_NAME);
253-
EXPECT_EQ(
254-
10,
252+
EXPECT_EQ(CATALOG_TABLES_COUNT+2,
255253
(int)catalog->GetDatabaseObject("emp_db", txn)->GetTableObjects().size());
256254
txn_manager.CommitTransaction(txn);
257255

@@ -263,8 +261,7 @@ TEST_F(CatalogTests, DroppingTable) {
263261
"emp_db", DEFAULT_SCHEMA_NAME, "department_table", txn),
264262
CatalogException);
265263
//
266-
EXPECT_EQ(
267-
10,
264+
EXPECT_EQ(CATALOG_TABLES_COUNT+2,
268265
(int)catalog->GetDatabaseObject("emp_db", txn)->GetTableObjects().size());
269266
txn_manager.CommitTransaction(txn);
270267

@@ -273,17 +270,15 @@ TEST_F(CatalogTests, DroppingTable) {
273270
EXPECT_THROW(catalog::Catalog::GetInstance()->DropTable(
274271
"emp_db", DEFAULT_SCHEMA_NAME, "void_table", txn),
275272
CatalogException);
276-
EXPECT_EQ(
277-
10,
273+
EXPECT_EQ(CATALOG_TABLES_COUNT+2,
278274
(int)catalog->GetDatabaseObject("emp_db", txn)->GetTableObjects().size());
279275
txn_manager.CommitTransaction(txn);
280276

281277
// Drop the other table
282278
txn = txn_manager.BeginTransaction();
283279
catalog::Catalog::GetInstance()->DropTable("emp_db", DEFAULT_SCHEMA_NAME,
284280
"emp_table", txn);
285-
EXPECT_EQ(
286-
9,
281+
EXPECT_EQ(CATALOG_TABLES_COUNT+1,
287282
(int)catalog->GetDatabaseObject("emp_db", txn)->GetTableObjects().size());
288283
txn_manager.CommitTransaction(txn);
289284
}

test/executor/drop_test.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,14 @@ TEST_F(DropTests, DroppingTable) {
109109
// NOTE: everytime we create a database, there will be 8 catalog tables inside
110110
EXPECT_EQ((int)catalog->GetDatabaseObject(TEST_DB_NAME, txn)
111111
->GetTableObjects()
112-
.size(),
113-
10);
112+
.size(), (CATALOG_TABLES_COUNT + 2));
114113

115114
// Now dropping the table using the executor
116115
catalog->DropTable(TEST_DB_NAME, DEFAULT_SCHEMA_NAME, "department_table",
117116
txn);
118117
EXPECT_EQ((int)catalog->GetDatabaseObject(TEST_DB_NAME, txn)
119118
->GetTableObjects()
120-
.size(),
121-
9);
119+
.size(), (CATALOG_TABLES_COUNT + 1));
122120

123121
// free the database just created
124122
catalog->DropDatabaseWithName(TEST_DB_NAME, txn);
@@ -214,7 +212,7 @@ TEST_F(DropTests, DroppingTrigger) {
214212
txn = txn_manager.BeginTransaction();
215213
catalog->DropTable(TEST_DB_NAME, DEFAULT_SCHEMA_NAME, "department_table",
216214
txn);
217-
EXPECT_EQ(8, (int)catalog::Catalog::GetInstance()
215+
EXPECT_EQ(CATALOG_TABLES_COUNT, (int)catalog::Catalog::GetInstance()
218216
->GetDatabaseObject(TEST_DB_NAME, txn)
219217
->GetTableObjects()
220218
.size());

0 commit comments

Comments
 (0)