// Test basic functionality TEST_F(SkipListMapTest, BasicTest) { std::vector<catalog::Column> columns; catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER), "A", true); columns.push_back(column1); catalog::Schema *schema(new catalog::Schema(columns)); std::vector<storage::Tuple*> tuples; storage::Tuple *tuple1(new storage::Tuple(schema, true)); tuple1->SetValue(0, ValueFactory::GetIntegerValue(1), nullptr); tuples.push_back(tuple1); storage::Tuple *tuple2(new storage::Tuple(schema, true)); tuple2->SetValue(0, ValueFactory::GetIntegerValue(2), nullptr); tuples.push_back(tuple2); storage::Tuple *tuple3(new storage::Tuple(schema, true)); tuple3->SetValue(0, ValueFactory::GetIntegerValue(3), nullptr); tuples.push_back(tuple3); LOG_INFO("%s", tuple1->GetInfo().c_str()); SkipListMap<key_type, value_type, key_comparator> map; EXPECT_TRUE(map.IsEmpty()); size_t const element_count = tuples.size(); for (size_t element = 0; element < element_count; ++element ) { key_type key; key.SetFromKey(tuples[element]); value_type val = &foo; auto status = map.Insert(key, val); EXPECT_TRUE(status); status = map.Insert(key, val); EXPECT_FALSE(status); } for (size_t element = 0; element < element_count; ++element ) { key_type key; key.SetFromKey(tuples[element]); value_type value = &bar; auto status = map.Find(key, value); EXPECT_TRUE(status); EXPECT_EQ(foo.block, value->block); LOG_INFO("bar : %d %d", value->block, value->offset); } for(auto tuple : tuples) { delete tuple; } delete schema; }
TEST_F(LogicalTileTests, TileMaterializationTest) { const int tuple_count = 4; std::shared_ptr<storage::TileGroup> tile_group( ExecutorTestsUtil::CreateTileGroup(tuple_count)); // Create tuple schema from tile schemas. std::vector<catalog::Schema> &tile_schemas = tile_group->GetTileSchemas(); std::unique_ptr<catalog::Schema> schema( catalog::Schema::AppendSchemaList(tile_schemas)); // Create tuples and insert them into tile group. const bool allocate = true; storage::Tuple tuple1(schema.get(), allocate); storage::Tuple tuple2(schema.get(), allocate); auto pool = tile_group->GetTilePool(1); tuple1.SetValue(0, ValueFactory::GetIntegerValue(1), pool); tuple1.SetValue(1, ValueFactory::GetIntegerValue(1), pool); tuple1.SetValue(2, ValueFactory::GetTinyIntValue(1), pool); tuple1.SetValue(3, ValueFactory::GetStringValue("tuple 1"), pool); tuple2.SetValue(0, ValueFactory::GetIntegerValue(2), pool); tuple2.SetValue(1, ValueFactory::GetIntegerValue(2), pool); tuple2.SetValue(2, ValueFactory::GetTinyIntValue(2), pool); tuple2.SetValue(3, ValueFactory::GetStringValue("tuple 2"), pool); auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); txn_manager.BeginTransaction(); // txn_id_t txn_id = txn->GetTransactionId(); auto tuple_id1 = tile_group->InsertTuple(&tuple1); auto tuple_id2 = tile_group->InsertTuple(&tuple2); auto tuple_id3 = tile_group->InsertTuple(&tuple1); txn_manager.PerformInsert(ItemPointer(tile_group->GetTileGroupId(), tuple_id1)); txn_manager.PerformInsert(ItemPointer(tile_group->GetTileGroupId(), tuple_id2)); txn_manager.PerformInsert(ItemPointer(tile_group->GetTileGroupId(), tuple_id3)); txn_manager.CommitTransaction(); //////////////////////////////////////////////////////////////// // LOGICAL TILE (1 BASE TILE) //////////////////////////////////////////////////////////////// // Don't transfer ownership of any base tile to logical tile. auto base_tile_ref = tile_group->GetTileReference(1); std::vector<oid_t> position_list1 = {0, 1}; std::vector<oid_t> position_list2 = {0, 1}; std::unique_ptr<executor::LogicalTile> logical_tile( executor::LogicalTileFactory::GetTile()); logical_tile->AddPositionList(std::move(position_list1)); logical_tile->AddPositionList(std::move(position_list2)); assert(tile_schemas.size() == 2); catalog::Schema *schema1 = &tile_schemas[0]; catalog::Schema *schema2 = &tile_schemas[1]; oid_t column_count = schema2->GetColumnCount(); for (oid_t column_itr = 0; column_itr < column_count; column_itr++) { logical_tile->AddColumn(base_tile_ref, column_itr, column_itr); } LOG_INFO("%s", logical_tile->GetInfo().c_str()); //////////////////////////////////////////////////////////////// // LOGICAL TILE (2 BASE TILE) //////////////////////////////////////////////////////////////// logical_tile.reset(executor::LogicalTileFactory::GetTile()); auto base_tile_ref1 = tile_group->GetTileReference(0); auto base_tile_ref2 = tile_group->GetTileReference(1); position_list1 = {0, 1}; position_list2 = {0, 1}; std::vector<oid_t> position_list3 = {0, 1}; std::vector<oid_t> position_list4 = {0, 1}; logical_tile->AddPositionList(std::move(position_list1)); logical_tile->AddPositionList(std::move(position_list2)); logical_tile->AddPositionList(std::move(position_list3)); logical_tile->AddPositionList(std::move(position_list4)); oid_t column_count1 = schema1->GetColumnCount(); for (oid_t column_itr = 0; column_itr < column_count1; column_itr++) { logical_tile->AddColumn(base_tile_ref1, column_itr, column_itr); } oid_t column_count2 = schema2->GetColumnCount(); for (oid_t column_itr = 0; column_itr < column_count2; column_itr++) { logical_tile->AddColumn(base_tile_ref2, column_itr, column_count1 + column_itr); } LOG_INFO("%s", logical_tile->GetInfo().c_str()); }
TEST_F(LogicalTileTests, TileMaterializationTest) { const int tuple_count = 4; std::shared_ptr<storage::TileGroup> tile_group( TestingExecutorUtil::CreateTileGroup(tuple_count)); std::vector<const catalog::Schema *> tile_schemas; for (unsigned int i = 0; i < tile_group->NumTiles(); i++) { tile_schemas.push_back(tile_group->GetTile(i)->GetSchema()); } // Create tuple schema from tile schemas. std::unique_ptr<catalog::Schema> schema( catalog::Schema::AppendSchemaPtrList(tile_schemas)); // Create tuples and insert them into tile group. const bool allocate = true; storage::Tuple tuple1(schema.get(), allocate); storage::Tuple tuple2(schema.get(), allocate); auto pool = tile_group->GetTilePool(1); tuple1.SetValue(0, type::ValueFactory::GetIntegerValue(1), pool); tuple1.SetValue(1, type::ValueFactory::GetIntegerValue(1), pool); tuple1.SetValue(2, type::ValueFactory::GetTinyIntValue(1), pool); tuple1.SetValue(3, type::ValueFactory::GetVarcharValue("tuple 1"), pool); tuple2.SetValue(0, type::ValueFactory::GetIntegerValue(2), pool); tuple2.SetValue(1, type::ValueFactory::GetIntegerValue(2), pool); tuple2.SetValue(2, type::ValueFactory::GetTinyIntValue(2), pool); tuple2.SetValue(3, type::ValueFactory::GetVarcharValue("tuple 2"), pool); auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); auto txn = txn_manager.BeginTransaction(); // txn_id_t txn_id = txn->GetTransactionId(); auto tuple_id1 = tile_group->InsertTuple(&tuple1); auto tuple_id2 = tile_group->InsertTuple(&tuple2); auto tuple_id3 = tile_group->InsertTuple(&tuple1); ItemPointer *index_entry_ptr = nullptr; txn_manager.PerformInsert( txn, ItemPointer(tile_group->GetTileGroupId(), tuple_id1), index_entry_ptr); txn_manager.PerformInsert( txn, ItemPointer(tile_group->GetTileGroupId(), tuple_id2), index_entry_ptr); txn_manager.PerformInsert( txn, ItemPointer(tile_group->GetTileGroupId(), tuple_id3), index_entry_ptr); txn_manager.CommitTransaction(txn); //////////////////////////////////////////////////////////////// // LOGICAL TILE (1 BASE TILE) //////////////////////////////////////////////////////////////// // Don't transfer ownership of any base tile to logical tile. auto base_tile_ref = tile_group->GetTileReference(1); std::vector<oid_t> position_list1 = {0, 1}; std::vector<oid_t> position_list2 = {0, 1}; std::unique_ptr<executor::LogicalTile> logical_tile( executor::LogicalTileFactory::GetTile()); logical_tile->AddPositionList(std::move(position_list1)); logical_tile->AddPositionList(std::move(position_list2)); oid_t column_count = tile_schemas[1]->GetColumnCount(); for (oid_t column_itr = 0; column_itr < column_count; column_itr++) { logical_tile->AddColumn(base_tile_ref, column_itr, column_itr); } LOG_TRACE("%s", logical_tile->GetInfo().c_str()); //////////////////////////////////////////////////////////////// // LOGICAL TILE (2 BASE TILE) //////////////////////////////////////////////////////////////// logical_tile.reset(executor::LogicalTileFactory::GetTile()); auto base_tile_ref1 = tile_group->GetTileReference(0); auto base_tile_ref2 = tile_group->GetTileReference(1); position_list1 = {0, 1}; position_list2 = {0, 1}; std::vector<oid_t> position_list3 = {0, 1}; std::vector<oid_t> position_list4 = {0, 1}; logical_tile->AddPositionList(std::move(position_list1)); logical_tile->AddPositionList(std::move(position_list2)); logical_tile->AddPositionList(std::move(position_list3)); logical_tile->AddPositionList(std::move(position_list4)); oid_t column_count1 = tile_schemas[0]->GetColumnCount(); for (oid_t column_itr = 0; column_itr < column_count1; column_itr++) { logical_tile->AddColumn(base_tile_ref1, column_itr, column_itr); } oid_t column_count2 = tile_schemas[1]->GetColumnCount(); for (oid_t column_itr = 0; column_itr < column_count2; column_itr++) { logical_tile->AddColumn(base_tile_ref2, column_itr, column_count1 + column_itr); } LOG_TRACE("%s", logical_tile->GetInfo().c_str()); }