diff --git a/tests/sstable_3_x_test.cc b/tests/sstable_3_x_test.cc index dda7000832..74c3f50c58 100644 --- a/tests/sstable_3_x_test.cc +++ b/tests/sstable_3_x_test.cc @@ -122,55 +122,53 @@ static thread_local const schema_ptr UNCOMPRESSED_STATIC_ROW_SCHEMA = .with_column("val", int32_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_static_row_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_STATIC_ROW_SCHEMA, - UNCOMPRESSED_STATIC_ROW_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_STATIC_ROW_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_static_row_read) { + sstable_assertions sst(UNCOMPRESSED_STATIC_ROW_SCHEMA, + UNCOMPRESSED_STATIC_ROW_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_STATIC_ROW_SCHEMA, pk); + }; - auto s_cdef = UNCOMPRESSED_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s")); - BOOST_REQUIRE(s_cdef); - auto val_cdef = UNCOMPRESSED_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("val")); - BOOST_REQUIRE(val_cdef); + auto s_cdef = UNCOMPRESSED_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s")); + BOOST_REQUIRE(s_cdef); + auto val_cdef = UNCOMPRESSED_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("val")); + BOOST_REQUIRE(val_cdef); - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_static_row({{s_cdef, int32_type->decompose(int32_t(105))}}) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(15)), - {{val_cdef, int32_type->decompose(int32_t(1005))}}) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_static_row({{s_cdef, int32_type->decompose(int32_t(101))}}) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(11)), - {{val_cdef, int32_type->decompose(int32_t(1001))}}) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_static_row({{s_cdef, int32_type->decompose(int32_t(102))}}) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(12)), - {{val_cdef, int32_type->decompose(int32_t(1002))}}) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_static_row({{s_cdef, int32_type->decompose(int32_t(104))}}) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(14)), - {{val_cdef, int32_type->decompose(int32_t(1004))}}) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_static_row({{s_cdef, int32_type->decompose(int32_t(103))}}) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(13)), - {{val_cdef, int32_type->decompose(int32_t(1003))}}) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_static_row({{s_cdef, int32_type->decompose(int32_t(105))}}) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(15)), + {{val_cdef, int32_type->decompose(int32_t(1005))}}) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_static_row({{s_cdef, int32_type->decompose(int32_t(101))}}) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(11)), + {{val_cdef, int32_type->decompose(int32_t(1001))}}) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_static_row({{s_cdef, int32_type->decompose(int32_t(102))}}) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(12)), + {{val_cdef, int32_type->decompose(int32_t(1002))}}) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_static_row({{s_cdef, int32_type->decompose(int32_t(104))}}) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(14)), + {{val_cdef, int32_type->decompose(int32_t(1004))}}) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_static_row({{s_cdef, int32_type->decompose(int32_t(103))}}) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(13)), + {{val_cdef, int32_type->decompose(int32_t(1003))}}) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/compound_static_row @@ -209,69 +207,67 @@ static thread_local const schema_ptr UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA = .with_column("val", int32_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_compound_static_row_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA, - UNCOMPRESSED_COMPOUND_STATIC_ROW_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_compound_static_row_read) { + sstable_assertions sst(UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA, + UNCOMPRESSED_COMPOUND_STATIC_ROW_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA, pk); + }; - auto s_int_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s_int")); - BOOST_REQUIRE(s_int_cdef); - auto s_text_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s_text")); - BOOST_REQUIRE(s_text_cdef); - auto s_inet_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s_inet")); - BOOST_REQUIRE(s_inet_cdef); - auto val_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("val")); - BOOST_REQUIRE(val_cdef); + auto s_int_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s_int")); + BOOST_REQUIRE(s_int_cdef); + auto s_text_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s_text")); + BOOST_REQUIRE(s_text_cdef); + auto s_inet_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("s_inet")); + BOOST_REQUIRE(s_inet_cdef); + auto val_cdef = UNCOMPRESSED_COMPOUND_STATIC_ROW_SCHEMA->get_column_definition(to_bytes("val")); + BOOST_REQUIRE(val_cdef); - auto generate = [&] (int int_val, sstring_view text_val, sstring_view inet_val) { - std::vector columns; + auto generate = [&] (int int_val, sstring_view text_val, sstring_view inet_val) { + std::vector columns; - columns.push_back({s_int_cdef, int32_type->decompose(int_val)}); - columns.push_back({s_text_cdef, utf8_type->from_string(text_val)}); - columns.push_back({s_inet_cdef, inet_addr_type->from_string(inet_val)}); + columns.push_back({s_int_cdef, int32_type->decompose(int_val)}); + columns.push_back({s_text_cdef, utf8_type->from_string(text_val)}); + columns.push_back({s_inet_cdef, inet_addr_type->from_string(inet_val)}); - return std::move(columns); - }; + return std::move(columns); + }; - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_static_row(generate(105, "Text for 5", "10.0.0.5")) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(15)), - {{val_cdef, int32_type->decompose(int32_t(1005))}}) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_static_row(generate(101, "Text for 1", "10.0.0.1")) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(11)), - {{val_cdef, int32_type->decompose(int32_t(1001))}}) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_static_row(generate(102, "Text for 2", "10.0.0.2")) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(12)), - {{val_cdef, int32_type->decompose(int32_t(1002))}}) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_static_row(generate(104, "Text for 4", "10.0.0.4")) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(14)), - {{val_cdef, int32_type->decompose(int32_t(1004))}}) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_static_row(generate(103, "Text for 3", "10.0.0.3")) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, - int32_type->decompose(13)), - {{val_cdef, int32_type->decompose(int32_t(1003))}}) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_static_row(generate(105, "Text for 5", "10.0.0.5")) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(15)), + {{val_cdef, int32_type->decompose(int32_t(1005))}}) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_static_row(generate(101, "Text for 1", "10.0.0.1")) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(11)), + {{val_cdef, int32_type->decompose(int32_t(1001))}}) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_static_row(generate(102, "Text for 2", "10.0.0.2")) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(12)), + {{val_cdef, int32_type->decompose(int32_t(1002))}}) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_static_row(generate(104, "Text for 4", "10.0.0.4")) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(14)), + {{val_cdef, int32_type->decompose(int32_t(1004))}}) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_static_row(generate(103, "Text for 3", "10.0.0.3")) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_STATIC_ROW_SCHEMA, + int32_type->decompose(13)), + {{val_cdef, int32_type->decompose(int32_t(1003))}}) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/partition_key_only @@ -295,40 +291,36 @@ static thread_local const schema_ptr UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA = .with_column("pk", int32_type, column_kind::partition_key) .build(); -SEASTAR_TEST_CASE(test_uncompressed_partition_key_only_load) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, UNCOMPRESSED_PARTITION_KEY_ONLY_PATH); - sst.load(); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_partition_key_only_load) { + sstable_assertions sst(UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, UNCOMPRESSED_PARTITION_KEY_ONLY_PATH); + sst.load(); } -SEASTAR_TEST_CASE(test_uncompressed_partition_key_only_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, UNCOMPRESSED_PARTITION_KEY_ONLY_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, pk); - }; - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row_with_key(clustering_key_prefix::make_empty()) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row_with_key(clustering_key_prefix::make_empty()) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row_with_key(clustering_key_prefix::make_empty()) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row_with_key(clustering_key_prefix::make_empty()) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row_with_key(clustering_key_prefix::make_empty()) - .produces_partition_end() - .produces_end_of_stream(); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_partition_key_only_read) { + sstable_assertions sst(UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, UNCOMPRESSED_PARTITION_KEY_ONLY_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_PARTITION_KEY_ONLY_SCHEMA, pk); + }; + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row_with_key(clustering_key_prefix::make_empty()) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row_with_key(clustering_key_prefix::make_empty()) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row_with_key(clustering_key_prefix::make_empty()) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row_with_key(clustering_key_prefix::make_empty()) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row_with_key(clustering_key_prefix::make_empty()) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/partition_key_with_value @@ -353,38 +345,36 @@ static thread_local const schema_ptr UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEM .with_column("val", int32_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_partition_key_with_value_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA, - UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_partition_key_with_value_read) { + sstable_assertions sst(UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA, + UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA, pk); + }; - auto cdef = UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA->get_column_definition(to_bytes("val")); - BOOST_REQUIRE(cdef); + auto cdef = UNCOMPRESSED_PARTITION_KEY_WITH_VALUE_SCHEMA->get_column_definition(to_bytes("val")); + BOOST_REQUIRE(cdef); - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(105))}}) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(101))}}) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(102))}}) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(104))}}) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(103))}}) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(105))}}) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(101))}}) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(102))}}) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(104))}}) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row(clustering_key_prefix::make_empty(), {{cdef, int32_type->decompose(int32_t(103))}}) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/partition_key_with_value_of_different_types @@ -447,96 +437,94 @@ static thread_local const schema_ptr PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPE .with_column("text_val", utf8_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_partition_key_with_values_of_different_types_read) { - return seastar::async([] { - sstable_assertions sst(PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA, - UNCOMPRESSED_PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_partition_key_with_values_of_different_types_read) { + sstable_assertions sst(PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA, + UNCOMPRESSED_PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA, pk); + }; - auto bool_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("bool_val")); - BOOST_REQUIRE(bool_cdef); - auto double_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("double_val")); - BOOST_REQUIRE(double_cdef); - auto float_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("float_val")); - BOOST_REQUIRE(float_cdef); - auto int_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("int_val")); - BOOST_REQUIRE(int_cdef); - auto long_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("long_val")); - BOOST_REQUIRE(long_cdef); - auto timestamp_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("timestamp_val")); - BOOST_REQUIRE(timestamp_cdef); - auto timeuuid_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("timeuuid_val")); - BOOST_REQUIRE(timeuuid_cdef); - auto uuid_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("uuid_val")); - BOOST_REQUIRE(uuid_cdef); - auto text_cdef = - PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("text_val")); - BOOST_REQUIRE(text_cdef); + auto bool_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("bool_val")); + BOOST_REQUIRE(bool_cdef); + auto double_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("double_val")); + BOOST_REQUIRE(double_cdef); + auto float_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("float_val")); + BOOST_REQUIRE(float_cdef); + auto int_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("int_val")); + BOOST_REQUIRE(int_cdef); + auto long_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("long_val")); + BOOST_REQUIRE(long_cdef); + auto timestamp_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("timestamp_val")); + BOOST_REQUIRE(timestamp_cdef); + auto timeuuid_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("timeuuid_val")); + BOOST_REQUIRE(timeuuid_cdef); + auto uuid_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("uuid_val")); + BOOST_REQUIRE(uuid_cdef); + auto text_cdef = + PARTITION_KEY_WITH_VALUES_OF_DIFFERENT_TYPES_SCHEMA->get_column_definition(to_bytes("text_val")); + BOOST_REQUIRE(text_cdef); - auto generate = [&] (bool bool_val, double double_val, float float_val, int int_val, long long_val, - sstring_view timestamp_val, sstring_view timeuuid_val, sstring_view uuid_val, - sstring_view text_val) { - std::vector columns; + auto generate = [&] (bool bool_val, double double_val, float float_val, int int_val, long long_val, + sstring_view timestamp_val, sstring_view timeuuid_val, sstring_view uuid_val, + sstring_view text_val) { + std::vector columns; - columns.push_back({bool_cdef, boolean_type->decompose(bool_val)}); - columns.push_back({double_cdef, double_type->decompose(double_val)}); - columns.push_back({float_cdef, float_type->decompose(float_val)}); - columns.push_back({int_cdef, int32_type->decompose(int_val)}); - columns.push_back({long_cdef, long_type->decompose(long_val)}); - columns.push_back({timestamp_cdef, timestamp_type->from_string(timestamp_val)}); - columns.push_back({timeuuid_cdef, timeuuid_type->from_string(timeuuid_val)}); - columns.push_back({uuid_cdef, uuid_type->from_string(uuid_val)}); - columns.push_back({text_cdef, utf8_type->from_string(text_val)}); + columns.push_back({bool_cdef, boolean_type->decompose(bool_val)}); + columns.push_back({double_cdef, double_type->decompose(double_val)}); + columns.push_back({float_cdef, float_type->decompose(float_val)}); + columns.push_back({int_cdef, int32_type->decompose(int_val)}); + columns.push_back({long_cdef, long_type->decompose(long_val)}); + columns.push_back({timestamp_cdef, timestamp_type->from_string(timestamp_val)}); + columns.push_back({timeuuid_cdef, timeuuid_type->from_string(timeuuid_val)}); + columns.push_back({uuid_cdef, uuid_type->from_string(uuid_val)}); + columns.push_back({text_cdef, utf8_type->from_string(text_val)}); - return std::move(columns); - }; + return std::move(columns); + }; - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row(clustering_key_prefix::make_empty(), - generate(true, 0.55, 0.5, 5, 55, "2015-05-05 13:30:54.234+0000", - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - "variable length text 5")) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row(clustering_key_prefix::make_empty(), - generate(true, 0.11, 0.1, 1, 11, "2015-05-01 09:30:54.234+0000", - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - "variable length text 1")) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row(clustering_key_prefix::make_empty(), - generate(false, 0.22, 0.2, 2, 22, "2015-05-02 10:30:54.234+0000", - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - "variable length text 2")) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row(clustering_key_prefix::make_empty(), - generate(false, 0.44, 0.4, 4, 44, "2015-05-04 12:30:54.234+0000", - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - "variable length text 4")) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row(clustering_key_prefix::make_empty(), - generate(true, 0.33, 0.3, 3, 33, "2015-05-03 11:30:54.234+0000", - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - "variable length text 3")) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row(clustering_key_prefix::make_empty(), + generate(true, 0.55, 0.5, 5, 55, "2015-05-05 13:30:54.234+0000", + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + "variable length text 5")) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row(clustering_key_prefix::make_empty(), + generate(true, 0.11, 0.1, 1, 11, "2015-05-01 09:30:54.234+0000", + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + "variable length text 1")) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row(clustering_key_prefix::make_empty(), + generate(false, 0.22, 0.2, 2, 22, "2015-05-02 10:30:54.234+0000", + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + "variable length text 2")) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row(clustering_key_prefix::make_empty(), + generate(false, 0.44, 0.4, 4, 44, "2015-05-04 12:30:54.234+0000", + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + "variable length text 4")) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row(clustering_key_prefix::make_empty(), + generate(true, 0.33, 0.3, 3, 33, "2015-05-03 11:30:54.234+0000", + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + "variable length text 3")) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/subset_of_columns @@ -590,115 +578,113 @@ static thread_local const schema_ptr UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA = .with_column("text_val", utf8_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_subset_of_columns_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA, - UNCOMPRESSED_SUBSET_OF_COLUMNS_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_subset_of_columns_read) { + sstable_assertions sst(UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA, + UNCOMPRESSED_SUBSET_OF_COLUMNS_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA, pk); + }; - auto bool_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("bool_val")); - BOOST_REQUIRE(bool_cdef); - auto double_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("double_val")); - BOOST_REQUIRE(double_cdef); - auto float_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("float_val")); - BOOST_REQUIRE(float_cdef); - auto int_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("int_val")); - BOOST_REQUIRE(int_cdef); - auto long_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("long_val")); - BOOST_REQUIRE(long_cdef); - auto timestamp_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("timestamp_val")); - BOOST_REQUIRE(timestamp_cdef); - auto timeuuid_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("timeuuid_val")); - BOOST_REQUIRE(timeuuid_cdef); - auto uuid_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("uuid_val")); - BOOST_REQUIRE(uuid_cdef); - auto text_cdef = - UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("text_val")); - BOOST_REQUIRE(text_cdef); + auto bool_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("bool_val")); + BOOST_REQUIRE(bool_cdef); + auto double_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("double_val")); + BOOST_REQUIRE(double_cdef); + auto float_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("float_val")); + BOOST_REQUIRE(float_cdef); + auto int_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("int_val")); + BOOST_REQUIRE(int_cdef); + auto long_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("long_val")); + BOOST_REQUIRE(long_cdef); + auto timestamp_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("timestamp_val")); + BOOST_REQUIRE(timestamp_cdef); + auto timeuuid_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("timeuuid_val")); + BOOST_REQUIRE(timeuuid_cdef); + auto uuid_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("uuid_val")); + BOOST_REQUIRE(uuid_cdef); + auto text_cdef = + UNCOMPRESSED_SUBSET_OF_COLUMNS_SCHEMA->get_column_definition(to_bytes("text_val")); + BOOST_REQUIRE(text_cdef); - auto generate = [&] (std::optional bool_val, std::optional double_val, - std::optional float_val, std::optional int_val, std::optional long_val, - std::optional timestamp_val, std::optional timeuuid_val, - std::optional uuid_val, std::optional text_val) { - std::vector columns; + auto generate = [&] (std::optional bool_val, std::optional double_val, + std::optional float_val, std::optional int_val, std::optional long_val, + std::optional timestamp_val, std::optional timeuuid_val, + std::optional uuid_val, std::optional text_val) { + std::vector columns; - if (bool_val) { - columns.push_back({bool_cdef, boolean_type->decompose(*bool_val)}); - } - if (double_val) { - columns.push_back({double_cdef, double_type->decompose(*double_val)}); - } - if (float_val) { - columns.push_back({float_cdef, float_type->decompose(*float_val)}); - } - if (int_val) { - columns.push_back({int_cdef, int32_type->decompose(*int_val)}); - } - if (long_val) { - columns.push_back({long_cdef, long_type->decompose(*long_val)}); - } - if (timestamp_val) { - columns.push_back({timestamp_cdef, timestamp_type->from_string(*timestamp_val)}); - } - if (timeuuid_val) { - columns.push_back({timeuuid_cdef, timeuuid_type->from_string(*timeuuid_val)}); - } - if (uuid_val) { - columns.push_back({uuid_cdef, uuid_type->from_string(*uuid_val)}); - } - if (text_val) { - columns.push_back({text_cdef, utf8_type->from_string(*text_val)}); - } + if (bool_val) { + columns.push_back({bool_cdef, boolean_type->decompose(*bool_val)}); + } + if (double_val) { + columns.push_back({double_cdef, double_type->decompose(*double_val)}); + } + if (float_val) { + columns.push_back({float_cdef, float_type->decompose(*float_val)}); + } + if (int_val) { + columns.push_back({int_cdef, int32_type->decompose(*int_val)}); + } + if (long_val) { + columns.push_back({long_cdef, long_type->decompose(*long_val)}); + } + if (timestamp_val) { + columns.push_back({timestamp_cdef, timestamp_type->from_string(*timestamp_val)}); + } + if (timeuuid_val) { + columns.push_back({timeuuid_cdef, timeuuid_type->from_string(*timeuuid_val)}); + } + if (uuid_val) { + columns.push_back({uuid_cdef, uuid_type->from_string(*uuid_val)}); + } + if (text_val) { + columns.push_back({text_cdef, utf8_type->from_string(*text_val)}); + } - return std::move(columns); - }; + return std::move(columns); + }; - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row(clustering_key_prefix::make_empty(), - generate({}, {}, {}, 5, 55, {}, - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - {})) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row(clustering_key_prefix::make_empty(), - generate({}, 0.11, 0.1, 1, 11, "2015-05-01 09:30:54.234+0000", - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - "variable length text 1")) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row(clustering_key_prefix::make_empty(), - generate(false, {}, {}, 2, 22, "2015-05-02 10:30:54.234+0000", - "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", - "variable length text 2")) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row(clustering_key_prefix::make_empty(), - generate(false, {}, {}, {}, {}, {}, - {}, {}, - "variable length text 4")) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row(clustering_key_prefix::make_empty(), - generate(true, 0.33, 0.3, {}, 33, "2015-05-03 11:30:54.234+0000", - {}, {}, - "variable length text 3")) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row(clustering_key_prefix::make_empty(), + generate({}, {}, {}, 5, 55, {}, + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + {})) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row(clustering_key_prefix::make_empty(), + generate({}, 0.11, 0.1, 1, 11, "2015-05-01 09:30:54.234+0000", + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + "variable length text 1")) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row(clustering_key_prefix::make_empty(), + generate(false, {}, {}, 2, 22, "2015-05-02 10:30:54.234+0000", + "50554d6e-29bb-11e5-b345-feff819cdc9f", "01234567-0123-0123-0123-0123456789ab", + "variable length text 2")) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row(clustering_key_prefix::make_empty(), + generate(false, {}, {}, {}, {}, {}, + {}, {}, + "variable length text 4")) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row(clustering_key_prefix::make_empty(), + generate(true, 0.33, 0.3, {}, 33, "2015-05-03 11:30:54.234+0000", + {}, {}, + "variable length text 3")) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/large_subset_of_columns_sparse @@ -816,62 +802,60 @@ static thread_local const schema_ptr UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE .with_column("val64", int32_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_large_subset_of_columns_sparse_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA, - UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_large_subset_of_columns_sparse_read) { + sstable_assertions sst(UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA, + UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA, pk); + }; - std::vector column_defs(64); - for (int i = 0; i < 64; ++i) { - column_defs[i] = UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA->get_column_definition(to_bytes(sprint("val%d", (i + 1)))); - BOOST_REQUIRE(column_defs[i]); + std::vector column_defs(64); + for (int i = 0; i < 64; ++i) { + column_defs[i] = UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_SPARSE_SCHEMA->get_column_definition(to_bytes(sprint("val%d", (i + 1)))); + BOOST_REQUIRE(column_defs[i]); + } + + auto generate = [&] (const std::vector>& column_values) { + std::vector columns; + + for (auto& p : column_values) { + columns.push_back({column_defs[p.first - 1], int32_type->decompose(p.second)}); } - auto generate = [&] (const std::vector>& column_values) { - std::vector columns; + return columns; + }; - for (auto& p : column_values) { - columns.push_back({column_defs[p.first - 1], int32_type->decompose(p.second)}); - } - - return columns; - }; - - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{34, 1}, {35, 2}, {36, 3}, {37, 4}, {38, 5}, {39, 6}, {40, 7}, {41, 8}, {42, 9}, - {43, 10}, {44, 11}, {45, 12}, {46, 13}, {47, 14}, {48, 15}, {49, 16}, {50, 17}, - {51, 18}, {52, 19}, {53, 20}, {54, 21}, {55, 22}, {56, 23}, {57, 24}, {58, 25}, - {59, 26}, {60, 27}, {61, 28}, {62, 29}, {63, 30}, {64, 31}})) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{1, 11}})) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{2, 22}, {5, 222}, {6, 2222}, {7, 22222}, {60, 222222}})) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, - {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, - {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, - {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}})) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{32, 33}, {33, 333}})) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{34, 1}, {35, 2}, {36, 3}, {37, 4}, {38, 5}, {39, 6}, {40, 7}, {41, 8}, {42, 9}, + {43, 10}, {44, 11}, {45, 12}, {46, 13}, {47, 14}, {48, 15}, {49, 16}, {50, 17}, + {51, 18}, {52, 19}, {53, 20}, {54, 21}, {55, 22}, {56, 23}, {57, 24}, {58, 25}, + {59, 26}, {60, 27}, {61, 28}, {62, 29}, {63, 30}, {64, 31}})) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{1, 11}})) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{2, 22}, {5, 222}, {6, 2222}, {7, 22222}, {60, 222222}})) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, + {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, + {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, + {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}})) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{32, 33}, {33, 333}})) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/large_subset_of_columns_dense @@ -1028,83 +1012,81 @@ static thread_local const schema_ptr UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_ .with_column("val64", int32_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_large_subset_of_columns_dense_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA, - UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_large_subset_of_columns_dense_read) { + sstable_assertions sst(UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA, + UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA, pk); + }; - std::vector column_defs(64); - for (int i = 0; i < 64; ++i) { - column_defs[i] = UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA->get_column_definition(to_bytes(sprint("val%d", (i + 1)))); - BOOST_REQUIRE(column_defs[i]); + std::vector column_defs(64); + for (int i = 0; i < 64; ++i) { + column_defs[i] = UNCOMPRESSED_LARGE_SUBSET_OF_COLUMNS_DENSE_SCHEMA->get_column_definition(to_bytes(sprint("val%d", (i + 1)))); + BOOST_REQUIRE(column_defs[i]); + } + + auto generate = [&] (const std::vector>& column_values) { + std::vector columns; + + for (auto& p : column_values) { + columns.push_back({column_defs[p.first - 1], int32_type->decompose(p.second)}); } - auto generate = [&] (const std::vector>& column_values) { - std::vector columns; + return columns; + }; - for (auto& p : column_values) { - columns.push_back({column_defs[p.first - 1], int32_type->decompose(p.second)}); - } - - return columns; - }; - - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{33, 1}, {34, 2}, {35, 3}, {36, 4}, {37, 5}, {38, 6}, {39, 7}, {40, 8}, {41, 9}, - {42, 10}, {43, 11}, {44, 12}, {45, 13}, {46, 14}, {47, 15}, {48, 16}, {49, 17}, - {50, 18}, {51, 19}, {52, 20}, {53, 21}, {54, 22}, {55, 23}, {56, 24}, {57, 25}, - {58, 26}, {59, 27}, {60, 28}, {61, 29}, {62, 30}, {63, 31}, {64, 32}})) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, - {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, - {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, - {26, 26}, {27, 27}, {28, 28}, {30, 30}, {31, 31}, {32, 32}, {33, 33}, - {34, 34}, {35, 35}, {36, 36}, {37, 37}, {38, 38}, {39, 39}, {40, 40}, {41, 41}, - {42, 42}, {43, 43}, {44, 44}, {45, 45}, {46, 46}, {47, 47}, {48, 48}, {49, 49}, - {50, 50}, {51, 51}, {52, 52}, {53, 53}, {54, 54}, {55, 55}, {56, 56}, {57, 57}, - {58, 58}, {59, 59}, {60, 60}, {61, 61}, {62, 62}, {63, 63}, {64, 64}})) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, - {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, - {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, - {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}, {32, 32}, {33, 33}, - {34, 34}, {35, 35}, {36, 36}, {37, 37}, {38, 38}, {39, 39}, {40, 40}, {41, 41}, - {42, 42}, {43, 43}, {44, 44}, {45, 45}, {46, 46}, {47, 47}, {48, 48}, {49, 49}, - {50, 50}, {51, 51}, {52, 52}, {53, 53}, {54, 54}, {55, 55}, {56, 56}, {57, 57}, - {58, 58}, {59, 59}, {60, 60}, {61, 61}, {62, 62}, {63, 63}, {64, 64}})) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, - {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, - {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, - {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}, {32, 32}})) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row(clustering_key_prefix::make_empty(), - generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, - {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, - {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, - {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}, {32, 32}, {33, 33}, - {34, 34}, {35, 35}, {36, 36}, {37, 37}, {38, 38}, {39, 39}, {40, 40}, {41, 41}, - {42, 42}, {43, 43}, {44, 44}, {45, 45}, {46, 46}, {47, 47}, {48, 48}, {49, 49}, - {50, 50}, {51, 51}, {52, 52}, {53, 53}, {54, 54}, {55, 55}, {56, 56}, {57, 57}, - {58, 58}, {59, 59}, {60, 60}, {61, 61}, {62, 62}, {63, 63}})) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{33, 1}, {34, 2}, {35, 3}, {36, 4}, {37, 5}, {38, 6}, {39, 7}, {40, 8}, {41, 9}, + {42, 10}, {43, 11}, {44, 12}, {45, 13}, {46, 14}, {47, 15}, {48, 16}, {49, 17}, + {50, 18}, {51, 19}, {52, 20}, {53, 21}, {54, 22}, {55, 23}, {56, 24}, {57, 25}, + {58, 26}, {59, 27}, {60, 28}, {61, 29}, {62, 30}, {63, 31}, {64, 32}})) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, + {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, + {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, + {26, 26}, {27, 27}, {28, 28}, {30, 30}, {31, 31}, {32, 32}, {33, 33}, + {34, 34}, {35, 35}, {36, 36}, {37, 37}, {38, 38}, {39, 39}, {40, 40}, {41, 41}, + {42, 42}, {43, 43}, {44, 44}, {45, 45}, {46, 46}, {47, 47}, {48, 48}, {49, 49}, + {50, 50}, {51, 51}, {52, 52}, {53, 53}, {54, 54}, {55, 55}, {56, 56}, {57, 57}, + {58, 58}, {59, 59}, {60, 60}, {61, 61}, {62, 62}, {63, 63}, {64, 64}})) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, + {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, + {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, + {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}, {32, 32}, {33, 33}, + {34, 34}, {35, 35}, {36, 36}, {37, 37}, {38, 38}, {39, 39}, {40, 40}, {41, 41}, + {42, 42}, {43, 43}, {44, 44}, {45, 45}, {46, 46}, {47, 47}, {48, 48}, {49, 49}, + {50, 50}, {51, 51}, {52, 52}, {53, 53}, {54, 54}, {55, 55}, {56, 56}, {57, 57}, + {58, 58}, {59, 59}, {60, 60}, {61, 61}, {62, 62}, {63, 63}, {64, 64}})) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, + {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, + {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, + {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}, {32, 32}})) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row(clustering_key_prefix::make_empty(), + generate({{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, + {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}, {17, 17}, + {18, 18}, {19, 19}, {20, 20}, {21, 21}, {22, 22}, {23, 23}, {24, 24}, {25, 25}, + {26, 26}, {27, 27}, {28, 28}, {29, 29}, {30, 30}, {31, 31}, {32, 32}, {33, 33}, + {34, 34}, {35, 35}, {36, 36}, {37, 37}, {38, 38}, {39, 39}, {40, 40}, {41, 41}, + {42, 42}, {43, 43}, {44, 44}, {45, 45}, {46, 46}, {47, 47}, {48, 48}, {49, 49}, + {50, 50}, {51, 51}, {52, 52}, {53, 53}, {54, 54}, {55, 55}, {56, 56}, {57, 57}, + {58, 58}, {59, 59}, {60, 60}, {61, 61}, {62, 62}, {63, 63}})) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/simple @@ -1129,105 +1111,91 @@ static thread_local const schema_ptr UNCOMPRESSED_SIMPLE_SCHEMA = .with_column("val", int32_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_simple_read_toc) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); - sst.read_toc(); - using ct = component_type; - sst.assert_toc({ct::Index, - ct::Data, - ct::TOC, - ct::Summary, - ct::Digest, - ct::CRC, - ct::Filter, - ct::Statistics}); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_simple_read_toc) { + sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); + sst.read_toc(); + using ct = component_type; + sst.assert_toc({ct::Index, + ct::Data, + ct::TOC, + ct::Summary, + ct::Digest, + ct::CRC, + ct::Filter, + ct::Statistics}); } -SEASTAR_TEST_CASE(test_uncompressed_simple_read_summary) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); - sst.read_toc(); - sst.read_summary(); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_simple_read_summary) { + sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); + sst.read_toc(); + sst.read_summary(); } -SEASTAR_TEST_CASE(test_uncompressed_simple_read_filter) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); - sst.read_toc(); - sst.read_filter(); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_simple_read_filter) { + sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); + sst.read_toc(); + sst.read_filter(); } -SEASTAR_TEST_CASE(test_uncompressed_simple_read_statistics) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); - sst.read_toc(); - sst.read_statistics(); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_simple_read_statistics) { + sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); + sst.read_toc(); + sst.read_statistics(); } -SEASTAR_TEST_CASE(test_uncompressed_simple_load) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); - sst.load(); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_simple_load) { + sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); + sst.load(); } -SEASTAR_TEST_CASE(test_uncompressed_simple_read_index) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); - auto vec = sst.read_index().get0(); - BOOST_REQUIRE_EQUAL(1, vec.size()); - }); +SEASTAR_THREAD_TEST_CASE(test_uncompressed_simple_read_index) { + sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, UNCOMPRESSED_SIMPLE_PATH); + auto vec = sst.read_index().get0(); + BOOST_REQUIRE_EQUAL(1, vec.size()); } -SEASTAR_TEST_CASE(test_uncompressed_simple_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, - UNCOMPRESSED_SIMPLE_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_SIMPLE_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_simple_read) { + sstable_assertions sst(UNCOMPRESSED_SIMPLE_SCHEMA, + UNCOMPRESSED_SIMPLE_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_SIMPLE_SCHEMA, pk); + }; - auto int_cdef = - UNCOMPRESSED_SIMPLE_SCHEMA->get_column_definition(to_bytes("val")); - BOOST_REQUIRE(int_cdef); + auto int_cdef = + UNCOMPRESSED_SIMPLE_SCHEMA->get_column_definition(to_bytes("val")); + BOOST_REQUIRE(int_cdef); - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, - int32_type->decompose(105)), - {{int_cdef, int32_type->decompose(1005)}}) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, - int32_type->decompose(101)), - {{int_cdef, int32_type->decompose(1001)}}) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, - int32_type->decompose(102)), - {{int_cdef, int32_type->decompose(1002)}}) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, - int32_type->decompose(104)), - {{int_cdef, int32_type->decompose(1004)}}) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, - int32_type->decompose(103)), - {{int_cdef, int32_type->decompose(1003)}}) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, + int32_type->decompose(105)), + {{int_cdef, int32_type->decompose(1005)}}) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, + int32_type->decompose(101)), + {{int_cdef, int32_type->decompose(1001)}}) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, + int32_type->decompose(102)), + {{int_cdef, int32_type->decompose(1002)}}) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, + int32_type->decompose(104)), + {{int_cdef, int32_type->decompose(1004)}}) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row(clustering_key::from_single_value(*UNCOMPRESSED_SIMPLE_SCHEMA, + int32_type->decompose(103)), + {{int_cdef, int32_type->decompose(1003)}}) + .produces_partition_end() + .produces_end_of_stream(); } // Following tests run on files in tests/sstables/3.x/uncompressed/simple @@ -1266,70 +1234,68 @@ static thread_local const schema_ptr UNCOMPRESSED_COMPOUND_CK_SCHEMA = .with_column("val", int32_type) .build(); -SEASTAR_TEST_CASE(test_uncompressed_compound_ck_read) { - return seastar::async([] { - sstable_assertions sst(UNCOMPRESSED_COMPOUND_CK_SCHEMA, - UNCOMPRESSED_COMPOUND_CK_PATH); - sst.load(); - auto to_key = [] (int key) { - auto bytes = int32_type->decompose(int32_t(key)); - auto pk = partition_key::from_single_value(*UNCOMPRESSED_COMPOUND_CK_SCHEMA, bytes); - return dht::global_partitioner().decorate_key(*UNCOMPRESSED_COMPOUND_CK_SCHEMA, pk); - }; +SEASTAR_THREAD_TEST_CASE(test_uncompressed_compound_ck_read) { + sstable_assertions sst(UNCOMPRESSED_COMPOUND_CK_SCHEMA, + UNCOMPRESSED_COMPOUND_CK_PATH); + sst.load(); + auto to_key = [] (int key) { + auto bytes = int32_type->decompose(int32_t(key)); + auto pk = partition_key::from_single_value(*UNCOMPRESSED_COMPOUND_CK_SCHEMA, bytes); + return dht::global_partitioner().decorate_key(*UNCOMPRESSED_COMPOUND_CK_SCHEMA, pk); + }; - auto int_cdef = - UNCOMPRESSED_SIMPLE_SCHEMA->get_column_definition(to_bytes("val")); - BOOST_REQUIRE(int_cdef); + auto int_cdef = + UNCOMPRESSED_SIMPLE_SCHEMA->get_column_definition(to_bytes("val")); + BOOST_REQUIRE(int_cdef); - assert_that(sst.read_rows_flat()) - .produces_partition_start(to_key(5)) - .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { - int32_type->decompose(105), - utf8_type->from_string("This is a string for 5"), - uuid_type->from_string("f1badb6f-80a0-4eef-90df-b3651d9a5578"), - inet_addr_type->from_string("10.0.0.5") - }), - {{int_cdef, int32_type->decompose(1005)}}) - .produces_partition_end() - .produces_partition_start(to_key(1)) - .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { - int32_type->decompose(101), - utf8_type->from_string("This is a string for 1"), - uuid_type->from_string("f7fdcbd2-4544-482c-85fd-d9572adc3cd6"), - inet_addr_type->from_string("10.0.0.1") - }), - {{int_cdef, int32_type->decompose(1001)}}) - .produces_partition_end() - .produces_partition_start(to_key(2)) - .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { - int32_type->decompose(102), - utf8_type->from_string("This is a string for 2"), - uuid_type->from_string("c25ae960-07a2-467d-8f35-5bd38647b367"), - inet_addr_type->from_string("10.0.0.2") - }), - {{int_cdef, int32_type->decompose(1002)}}) - .produces_partition_end() - .produces_partition_start(to_key(4)) - .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { - int32_type->decompose(104), - utf8_type->from_string("This is a string for 4"), - uuid_type->from_string("4549e2c2-786e-4b30-90aa-5dd37ae1db8f"), - inet_addr_type->from_string("10.0.0.4") - }), - {{int_cdef, int32_type->decompose(1004)}}) - .produces_partition_end() - .produces_partition_start(to_key(3)) - .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { - int32_type->decompose(103), - utf8_type->from_string("This is a string for 3"), - uuid_type->from_string("f7e8ebc0-dbae-4c06-bae0-656c23f6af6a"), - inet_addr_type->from_string("10.0.0.3") - }), - {{int_cdef, int32_type->decompose(1003)}}) - .produces_partition_end() - .produces_end_of_stream(); - }); + assert_that(sst.read_rows_flat()) + .produces_partition_start(to_key(5)) + .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { + int32_type->decompose(105), + utf8_type->from_string("This is a string for 5"), + uuid_type->from_string("f1badb6f-80a0-4eef-90df-b3651d9a5578"), + inet_addr_type->from_string("10.0.0.5") + }), + {{int_cdef, int32_type->decompose(1005)}}) + .produces_partition_end() + .produces_partition_start(to_key(1)) + .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { + int32_type->decompose(101), + utf8_type->from_string("This is a string for 1"), + uuid_type->from_string("f7fdcbd2-4544-482c-85fd-d9572adc3cd6"), + inet_addr_type->from_string("10.0.0.1") + }), + {{int_cdef, int32_type->decompose(1001)}}) + .produces_partition_end() + .produces_partition_start(to_key(2)) + .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { + int32_type->decompose(102), + utf8_type->from_string("This is a string for 2"), + uuid_type->from_string("c25ae960-07a2-467d-8f35-5bd38647b367"), + inet_addr_type->from_string("10.0.0.2") + }), + {{int_cdef, int32_type->decompose(1002)}}) + .produces_partition_end() + .produces_partition_start(to_key(4)) + .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { + int32_type->decompose(104), + utf8_type->from_string("This is a string for 4"), + uuid_type->from_string("4549e2c2-786e-4b30-90aa-5dd37ae1db8f"), + inet_addr_type->from_string("10.0.0.4") + }), + {{int_cdef, int32_type->decompose(1004)}}) + .produces_partition_end() + .produces_partition_start(to_key(3)) + .produces_row(clustering_key::from_exploded(*UNCOMPRESSED_SIMPLE_SCHEMA, { + int32_type->decompose(103), + utf8_type->from_string("This is a string for 3"), + uuid_type->from_string("f7e8ebc0-dbae-4c06-bae0-656c23f6af6a"), + inet_addr_type->from_string("10.0.0.3") + }), + {{int_cdef, int32_type->decompose(1003)}}) + .produces_partition_end() + .produces_end_of_stream(); } static void compare_files(sstring filename1, sstring filename2) { @@ -1364,678 +1330,640 @@ static void write_and_compare_sstables(schema_ptr s, lw_shared_ptr mt, static constexpr api::timestamp_type write_timestamp = 1525385507816568; static constexpr gc_clock::time_point write_time_point = gc_clock::time_point{} + gc_clock::duration{1525385507}; -SEASTAR_TEST_CASE(test_write_static_row) { - return seastar::async([] { - sstring table_name = "static_row"; - // CREATE TABLE static_row (pk text, ck int, st1 int static, st2 text static, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", utf8_type, column_kind::partition_key); - builder.with_column("ck", int32_type, column_kind::clustering_key); - builder.with_column("st1", int32_type, column_kind::static_column); - builder.with_column("st2", utf8_type, column_kind::static_column); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); +SEASTAR_THREAD_TEST_CASE(test_write_static_row) { + sstring table_name = "static_row"; + // CREATE TABLE static_row (pk text, ck int, st1 int static, st2 text static, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", utf8_type, column_kind::partition_key); + builder.with_column("ck", int32_type, column_kind::clustering_key); + builder.with_column("st1", int32_type, column_kind::static_column); + builder.with_column("st2", utf8_type, column_kind::static_column); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); - lw_shared_ptr mt = make_lw_shared(s); + lw_shared_ptr mt = make_lw_shared(s); - // INSERT INTO static_row (pk, st1, st2) values ('key1', 1135, 'hello'); + // INSERT INTO static_row (pk, st1, st2) values ('key1', 1135, 'hello'); + auto key = make_dkey(s, {to_bytes("key1")}); + mutation mut{s, key}; + mut.set_static_cell("st1", data_value{1135}, write_timestamp); + mut.set_static_cell("st2", data_value{"hello"}, write_timestamp); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_composite_partition_key) { + sstring table_name = "composite_partition_key"; + // CREATE TABLE composite_partition_key (a int , b text, c boolean, d int, e text, f int, g text, PRIMARY KEY ((a, b, c), d, e)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("a", int32_type, column_kind::partition_key); + builder.with_column("b", utf8_type, column_kind::partition_key); + builder.with_column("c", boolean_type, column_kind::partition_key); + builder.with_column("d", int32_type, column_kind::clustering_key); + builder.with_column("e", utf8_type, column_kind::clustering_key); + builder.with_column("f", int32_type); + builder.with_column("g", utf8_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + // INSERT INTO composite_partition_key (a,b,c,d,e,f,g) values (1, 'hello', true, 2, 'dear', 3, 'world'); + auto key = partition_key::from_deeply_exploded(*s, { data_value{1}, data_value{"hello"}, data_value{true} }); + mutation mut{s, key}; + clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 2, "dear" }); + mut.partition().apply_insert(*s, ckey, write_timestamp); + mut.set_cell(ckey, "f", data_value{3}, write_timestamp); + mut.set_cell(ckey, "g", data_value{"world"}, write_timestamp); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_composite_clustering_key) { + sstring table_name = "composite_clustering_key"; + // CREATE TABLE composite_clustering_key (a int , b text, c int, d text, e int, f text, PRIMARY KEY (a, b, c, d)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("a", int32_type, column_kind::partition_key); + builder.with_column("b", utf8_type, column_kind::clustering_key); + builder.with_column("c", int32_type, column_kind::clustering_key); + builder.with_column("d", utf8_type, column_kind::clustering_key); + builder.with_column("e", int32_type); + builder.with_column("f", utf8_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + // INSERT INTO composite_clustering_key (a,b,c,d,e,f) values (1, 'hello', 2, 'dear', 3, 'world'); + auto key = partition_key::from_deeply_exploded(*s, { 1 }); + mutation mut{s, key}; + clustering_key ckey = clustering_key::from_deeply_exploded(*s, { "hello", 2, "dear" }); + mut.partition().apply_insert(*s, ckey, write_timestamp); + mut.set_cell(ckey, "e", data_value{3}, write_timestamp); + mut.set_cell(ckey, "f", data_value{"world"}, write_timestamp); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_wide_partitions) { + sstring table_name = "wide_partitions"; + // CREATE TABLE wide_partitions (pk text, ck text, st text, rc text, PRIMARY KEY (pk, ck) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", utf8_type, column_kind::partition_key); + builder.with_column("ck", utf8_type, column_kind::clustering_key); + builder.with_column("st", utf8_type, column_kind::static_column); + builder.with_column("rc", utf8_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + api::timestamp_type ts = write_timestamp; + { auto key = make_dkey(s, {to_bytes("key1")}); mutation mut{s, key}; - mut.set_static_cell("st1", data_value{1135}, write_timestamp); - mut.set_static_cell("st2", data_value{"hello"}, write_timestamp); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_composite_partition_key) { - return seastar::async([] { - sstring table_name = "composite_partition_key"; - // CREATE TABLE composite_partition_key (a int , b text, c boolean, d int, e text, f int, g text, PRIMARY KEY ((a, b, c), d, e)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("a", int32_type, column_kind::partition_key); - builder.with_column("b", utf8_type, column_kind::partition_key); - builder.with_column("c", boolean_type, column_kind::partition_key); - builder.with_column("d", int32_type, column_kind::clustering_key); - builder.with_column("e", utf8_type, column_kind::clustering_key); - builder.with_column("f", int32_type); - builder.with_column("g", utf8_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // INSERT INTO composite_partition_key (a,b,c,d,e,f,g) values (1, 'hello', true, 2, 'dear', 3, 'world'); - auto key = partition_key::from_deeply_exploded(*s, { data_value{1}, data_value{"hello"}, data_value{true} }); - mutation mut{s, key}; - clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 2, "dear" }); - mut.partition().apply_insert(*s, ckey, write_timestamp); - mut.set_cell(ckey, "f", data_value{3}, write_timestamp); - mut.set_cell(ckey, "g", data_value{"world"}, write_timestamp); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_composite_clustering_key) { - return seastar::async([] { - sstring table_name = "composite_clustering_key"; - // CREATE TABLE composite_clustering_key (a int , b text, c int, d text, e int, f text, PRIMARY KEY (a, b, c, d)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("a", int32_type, column_kind::partition_key); - builder.with_column("b", utf8_type, column_kind::clustering_key); - builder.with_column("c", int32_type, column_kind::clustering_key); - builder.with_column("d", utf8_type, column_kind::clustering_key); - builder.with_column("e", int32_type); - builder.with_column("f", utf8_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // INSERT INTO composite_clustering_key (a,b,c,d,e,f) values (1, 'hello', 2, 'dear', 3, 'world'); - auto key = partition_key::from_deeply_exploded(*s, { 1 }); - mutation mut{s, key}; - clustering_key ckey = clustering_key::from_deeply_exploded(*s, { "hello", 2, "dear" }); - mut.partition().apply_insert(*s, ckey, write_timestamp); - mut.set_cell(ckey, "e", data_value{3}, write_timestamp); - mut.set_cell(ckey, "f", data_value{"world"}, write_timestamp); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_wide_partitions) { - return seastar::async([] { - sstring table_name = "wide_partitions"; - // CREATE TABLE wide_partitions (pk text, ck text, st text, rc text, PRIMARY KEY (pk, ck) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", utf8_type, column_kind::partition_key); - builder.with_column("ck", utf8_type, column_kind::clustering_key); - builder.with_column("st", utf8_type, column_kind::static_column); - builder.with_column("rc", utf8_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - api::timestamp_type ts = write_timestamp; - { - auto key = make_dkey(s, {to_bytes("key1")}); - mutation mut{s, key}; - mut.set_static_cell("st", data_value{"hello"}, ts); - sstring ck_base(1024, 'a'); - sstring rc_base(1024, 'b'); - for (auto idx: boost::irange(0, 1024)) { - clustering_key ckey = clustering_key::from_deeply_exploded(*s, {format("{}{}", ck_base, idx)}); - mut.partition().apply_insert(*s, ckey, ts); - mut.set_cell(ckey, "rc", data_value{format("{}{}", rc_base, idx)}, ts); - seastar::thread::yield(); - } - mt->apply(std::move(mut)); - ts += 10; - } - { - auto key = make_dkey(s, {to_bytes("key2")}); - mutation mut{s, key}; - mut.set_static_cell("st", data_value{"goodbye"}, ts); - sstring ck_base(1024, 'a'); - sstring rc_base(1024, 'b'); - for (auto idx: boost::irange(0, 1024)) { - clustering_key ckey = clustering_key::from_deeply_exploded(*s, {format("{}{}", ck_base, idx)}); - mut.partition().apply_insert(*s, ckey, ts); - mut.set_cell(ckey, "rc", data_value{format("{}{}", rc_base, idx)}, ts); - seastar::thread::yield(); - } - mt->apply(std::move(mut)); - } - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_ttled_row) { - return seastar::async([] { - sstring table_name = "ttled_row"; - // CREATE TABLE ttled_row (pk int, ck int, rc int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("ck", int32_type, column_kind::clustering_key); - builder.with_column("rc", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // INSERT INTO ttled_row (pk, ck, rc) VALUES ( 1, 2, 3) USING TTL 1135; - auto key = partition_key::from_deeply_exploded(*s, { 1 }); - mutation mut{s, key}; - clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 2 }); - gc_clock::duration ttl{1135}; - mut.partition().apply_insert(*s, ckey, write_timestamp, ttl, write_time_point + ttl); - mut.set_cell(ckey, "rc", data_value{3}, write_timestamp); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_ttled_column) { - return seastar::async([] { - sstring table_name = "ttled_column"; - // CREATE TABLE ttled_column (pk text, rc int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", utf8_type, column_kind::partition_key); - builder.with_column("rc", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // UPDATE ttled_column USING TTL 1135 SET rc = 1 WHERE pk='key'; - auto key = make_dkey(s, {to_bytes("key")}); - mutation mut{s, key}; - - gc_clock::duration ttl{1135}; - auto column_def = s->get_column_definition("rc"); - if (!column_def) { - throw std::runtime_error("no column definition found"); - } - bytes value = column_def->type->decompose(data_value{1}); - auto cell = atomic_cell::make_live(*column_def->type, write_timestamp, value, write_time_point + ttl, ttl); - mut.set_clustered_cell(clustering_key::make_empty(), *column_def, std::move(cell)); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_deleted_column) { - return seastar::async([] { - sstring table_name = "deleted_column"; - // CREATE TABLE deleted_column (pk int, rc int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("rc", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // DELETE rc FROM deleted_column WHERE pk=1; - auto key = partition_key::from_deeply_exploded(*s, { 1 }); - mutation mut{s, key}; - auto column_def = s->get_column_definition("rc"); - if (!column_def) { - throw std::runtime_error("no column definition found"); - } - mut.set_cell(clustering_key::make_empty(), *column_def, atomic_cell::make_dead(write_timestamp, write_time_point)); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_deleted_row) { - return seastar::async([] { - sstring table_name = "deleted_row"; - // CREATE TABLE deleted_row (pk int, ck int, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("ck", int32_type, column_kind::clustering_key); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // DELETE FROM deleted_row WHERE pk=1 and ck=2; - auto key = partition_key::from_deeply_exploded(*s, { 1 }); - mutation mut{s, key}; - clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 2 }); - mut.partition().apply_delete(*s, ckey, tombstone{write_timestamp, write_time_point}); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_collection_wide_update) { - return seastar::async([] { - sstring table_name = "collection_wide_update"; - auto set_of_ints_type = set_type_impl::get_instance(int32_type, true); - // CREATE TABLE collection_wide_update (pk int, col set, PRIMARY KEY (pk)) with compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("col", set_of_ints_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // INSERT INTO collection_wide_update (pk, col) VALUES (1, {2, 3}); - auto key = partition_key::from_deeply_exploded(*s, { 1 }); - mutation mut{s, key}; - - mut.partition().apply_insert(*s, clustering_key::make_empty(), write_timestamp); - set_type_impl::mutation set_values; - set_values.tomb = tombstone {write_timestamp - 1, write_time_point}; - set_values.cells.emplace_back(int32_type->decompose(2), atomic_cell::make_live(*bytes_type, write_timestamp, bytes_view{})); - set_values.cells.emplace_back(int32_type->decompose(3), atomic_cell::make_live(*bytes_type, write_timestamp, bytes_view{})); - - mut.set_clustered_cell(clustering_key::make_empty(), *s->get_column_definition("col"), set_of_ints_type->serialize_mutation_form(set_values)); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_collection_incremental_update) { - return seastar::async([] { - sstring table_name = "collection_incremental_update"; - auto set_of_ints_type = set_type_impl::get_instance(int32_type, true); - // CREATE TABLE collection_incremental_update (pk int, col set, PRIMARY KEY (pk)) with compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("col", set_of_ints_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // UPDATE collection_incremental_update SET col = col + {2} WHERE pk = 1; - auto key = partition_key::from_deeply_exploded(*s, { 1 }); - mutation mut{s, key}; - - set_type_impl::mutation set_values; - set_values.cells.emplace_back(int32_type->decompose(2), atomic_cell::make_live(*bytes_type, write_timestamp, bytes_view{})); - - mut.set_clustered_cell(clustering_key::make_empty(), *s->get_column_definition("col"), set_of_ints_type->serialize_mutation_form(set_values)); - mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_multiple_partitions) { - return seastar::async([] { - sstring table_name = "multiple_partitions"; - // CREATE TABLE multiple_partitions (pk int, rc1 int, rc2 int, rc3 int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("rc1", int32_type); - builder.with_column("rc2", int32_type); - builder.with_column("rc3", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - api::timestamp_type ts = write_timestamp; - // INSERT INTO multiple_partitions (pk, rc1) VALUES (1, 10); - // INSERT INTO multiple_partitions (pk, rc2) VALUES (2, 20); - // INSERT INTO multiple_partitions (pk, rc3) VALUES (3, 30); - for (auto i : boost::irange(1, 4)) { - auto key = partition_key::from_deeply_exploded(*s, {i}); - mutation mut{s, key}; - - clustering_key ckey = clustering_key::make_empty(); + mut.set_static_cell("st", data_value{"hello"}, ts); + sstring ck_base(1024, 'a'); + sstring rc_base(1024, 'b'); + for (auto idx: boost::irange(0, 1024)) { + clustering_key ckey = clustering_key::from_deeply_exploded(*s, {format("{}{}", ck_base, idx)}); mut.partition().apply_insert(*s, ckey, ts); - mut.set_cell(ckey, to_bytes(format("rc{}", i)), data_value{i * 10}, ts); - mt->apply(std::move(mut)); - ts += 10; + mut.set_cell(ckey, "rc", data_value{format("{}{}", rc_base, idx)}, ts); + seastar::thread::yield(); } + mt->apply(std::move(mut)); + ts += 10; + } + { + auto key = make_dkey(s, {to_bytes("key2")}); + mutation mut{s, key}; + mut.set_static_cell("st", data_value{"goodbye"}, ts); + sstring ck_base(1024, 'a'); + sstring rc_base(1024, 'b'); + for (auto idx: boost::irange(0, 1024)) { + clustering_key ckey = clustering_key::from_deeply_exploded(*s, {format("{}{}", ck_base, idx)}); + mut.partition().apply_insert(*s, ckey, ts); + mut.set_cell(ckey, "rc", data_value{format("{}{}", rc_base, idx)}, ts); + seastar::thread::yield(); + } + mt->apply(std::move(mut)); + } - write_and_compare_sstables(s, mt, table_name); - }); + write_and_compare_sstables(s, mt, table_name); } -static future<> test_write_many_partitions(sstring table_name, tombstone partition_tomb, compression_parameters cp) { - return seastar::async([table_name, partition_tomb, cp] { - // CREATE TABLE (pk int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.set_compressor_params(cp); - schema_ptr s = builder.build(schema_builder::compact_storage::no); +SEASTAR_THREAD_TEST_CASE(test_write_ttled_row) { + sstring table_name = "ttled_row"; + // CREATE TABLE ttled_row (pk int, ck int, rc int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("ck", int32_type, column_kind::clustering_key); + builder.with_column("rc", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); - lw_shared_ptr mt = make_lw_shared(s); + lw_shared_ptr mt = make_lw_shared(s); - for (auto i : boost::irange(0, 65536)) { - auto key = partition_key::from_deeply_exploded(*s, {i}); - mutation mut{s, key}; - if (partition_tomb) { - mut.partition().apply(partition_tomb); - } - mt->apply(std::move(mut)); - } + // INSERT INTO ttled_row (pk, ck, rc) VALUES ( 1, 2, 3) USING TTL 1135; + auto key = partition_key::from_deeply_exploded(*s, { 1 }); + mutation mut{s, key}; + clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 2 }); + gc_clock::duration ttl{1135}; + mut.partition().apply_insert(*s, ckey, write_timestamp, ttl, write_time_point + ttl); + mut.set_cell(ckey, "rc", data_value{3}, write_timestamp); + mt->apply(std::move(mut)); - write_and_compare_sstables(s, mt, table_name, cp != compression_parameters{}); - }); + write_and_compare_sstables(s, mt, table_name); } -SEASTAR_TEST_CASE(test_write_many_live_partitions) { - return test_write_many_partitions( +SEASTAR_THREAD_TEST_CASE(test_write_ttled_column) { + sstring table_name = "ttled_column"; + // CREATE TABLE ttled_column (pk text, rc int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", utf8_type, column_kind::partition_key); + builder.with_column("rc", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + // UPDATE ttled_column USING TTL 1135 SET rc = 1 WHERE pk='key'; + auto key = make_dkey(s, {to_bytes("key")}); + mutation mut{s, key}; + + gc_clock::duration ttl{1135}; + auto column_def = s->get_column_definition("rc"); + if (!column_def) { + throw std::runtime_error("no column definition found"); + } + bytes value = column_def->type->decompose(data_value{1}); + auto cell = atomic_cell::make_live(*column_def->type, write_timestamp, value, write_time_point + ttl, ttl); + mut.set_clustered_cell(clustering_key::make_empty(), *column_def, std::move(cell)); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_deleted_column) { + sstring table_name = "deleted_column"; + // CREATE TABLE deleted_column (pk int, rc int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("rc", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + // DELETE rc FROM deleted_column WHERE pk=1; + auto key = partition_key::from_deeply_exploded(*s, { 1 }); + mutation mut{s, key}; + auto column_def = s->get_column_definition("rc"); + if (!column_def) { + throw std::runtime_error("no column definition found"); + } + mut.set_cell(clustering_key::make_empty(), *column_def, atomic_cell::make_dead(write_timestamp, write_time_point)); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_deleted_row) { + sstring table_name = "deleted_row"; + // CREATE TABLE deleted_row (pk int, ck int, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("ck", int32_type, column_kind::clustering_key); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + // DELETE FROM deleted_row WHERE pk=1 and ck=2; + auto key = partition_key::from_deeply_exploded(*s, { 1 }); + mutation mut{s, key}; + clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 2 }); + mut.partition().apply_delete(*s, ckey, tombstone{write_timestamp, write_time_point}); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_collection_wide_update) { + sstring table_name = "collection_wide_update"; + auto set_of_ints_type = set_type_impl::get_instance(int32_type, true); + // CREATE TABLE collection_wide_update (pk int, col set, PRIMARY KEY (pk)) with compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("col", set_of_ints_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + // INSERT INTO collection_wide_update (pk, col) VALUES (1, {2, 3}); + auto key = partition_key::from_deeply_exploded(*s, { 1 }); + mutation mut{s, key}; + + mut.partition().apply_insert(*s, clustering_key::make_empty(), write_timestamp); + set_type_impl::mutation set_values; + set_values.tomb = tombstone {write_timestamp - 1, write_time_point}; + set_values.cells.emplace_back(int32_type->decompose(2), atomic_cell::make_live(*bytes_type, write_timestamp, bytes_view{})); + set_values.cells.emplace_back(int32_type->decompose(3), atomic_cell::make_live(*bytes_type, write_timestamp, bytes_view{})); + + mut.set_clustered_cell(clustering_key::make_empty(), *s->get_column_definition("col"), set_of_ints_type->serialize_mutation_form(set_values)); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_collection_incremental_update) { + sstring table_name = "collection_incremental_update"; + auto set_of_ints_type = set_type_impl::get_instance(int32_type, true); + // CREATE TABLE collection_incremental_update (pk int, col set, PRIMARY KEY (pk)) with compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("col", set_of_ints_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + // UPDATE collection_incremental_update SET col = col + {2} WHERE pk = 1; + auto key = partition_key::from_deeply_exploded(*s, { 1 }); + mutation mut{s, key}; + + set_type_impl::mutation set_values; + set_values.cells.emplace_back(int32_type->decompose(2), atomic_cell::make_live(*bytes_type, write_timestamp, bytes_view{})); + + mut.set_clustered_cell(clustering_key::make_empty(), *s->get_column_definition("col"), set_of_ints_type->serialize_mutation_form(set_values)); + mt->apply(std::move(mut)); + + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_multiple_partitions) { + sstring table_name = "multiple_partitions"; + // CREATE TABLE multiple_partitions (pk int, rc1 int, rc2 int, rc3 int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("rc1", int32_type); + builder.with_column("rc2", int32_type); + builder.with_column("rc3", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + api::timestamp_type ts = write_timestamp; + // INSERT INTO multiple_partitions (pk, rc1) VALUES (1, 10); + // INSERT INTO multiple_partitions (pk, rc2) VALUES (2, 20); + // INSERT INTO multiple_partitions (pk, rc3) VALUES (3, 30); + for (auto i : boost::irange(1, 4)) { + auto key = partition_key::from_deeply_exploded(*s, {i}); + mutation mut{s, key}; + + clustering_key ckey = clustering_key::make_empty(); + mut.partition().apply_insert(*s, ckey, ts); + mut.set_cell(ckey, to_bytes(format("rc{}", i)), data_value{i * 10}, ts); + mt->apply(std::move(mut)); + ts += 10; + } + + write_and_compare_sstables(s, mt, table_name); +} + +static void test_write_many_partitions(sstring table_name, tombstone partition_tomb, compression_parameters cp) { + // CREATE TABLE (pk int, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.set_compressor_params(cp); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + for (auto i : boost::irange(0, 65536)) { + auto key = partition_key::from_deeply_exploded(*s, {i}); + mutation mut{s, key}; + if (partition_tomb) { + mut.partition().apply(partition_tomb); + } + mt->apply(std::move(mut)); + } + + write_and_compare_sstables(s, mt, table_name, cp != compression_parameters{}); +} + +SEASTAR_THREAD_TEST_CASE(test_write_many_live_partitions) { + test_write_many_partitions( "many_live_partitions", tombstone{}, compression_parameters{}); } -SEASTAR_TEST_CASE(test_write_many_deleted_partitions) { - return test_write_many_partitions( +SEASTAR_THREAD_TEST_CASE(test_write_many_deleted_partitions) { + test_write_many_partitions( "many_deleted_partitions", tombstone{write_timestamp, write_time_point}, compression_parameters{}); } -SEASTAR_TEST_CASE(test_write_many_partitions_lz4) { - return test_write_many_partitions( +SEASTAR_THREAD_TEST_CASE(test_write_many_partitions_lz4) { + test_write_many_partitions( "many_partitions_lz4", tombstone{}, compression_parameters{compressor::lz4}); } -SEASTAR_TEST_CASE(test_write_many_partitions_snappy) { - return test_write_many_partitions( +SEASTAR_THREAD_TEST_CASE(test_write_many_partitions_snappy) { + test_write_many_partitions( "many_partitions_snappy", tombstone{}, compression_parameters{compressor::snappy}); } -SEASTAR_TEST_CASE(test_write_many_partitions_deflate) { - return test_write_many_partitions( +SEASTAR_THREAD_TEST_CASE(test_write_many_partitions_deflate) { + test_write_many_partitions( "many_partitions_deflate", tombstone{}, compression_parameters{compressor::deflate}); } -SEASTAR_TEST_CASE(test_write_multiple_rows) { - return seastar::async([] { - sstring table_name = "multiple_rows"; - // CREATE TABLE multiple_rows (pk int, ck int, rc1 int, rc2 int, rc3 int, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("ck", int32_type, column_kind::clustering_key); - builder.with_column("rc1", int32_type); - builder.with_column("rc2", int32_type); - builder.with_column("rc3", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); +SEASTAR_THREAD_TEST_CASE(test_write_multiple_rows) { + sstring table_name = "multiple_rows"; + // CREATE TABLE multiple_rows (pk int, ck int, rc1 int, rc2 int, rc3 int, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("ck", int32_type, column_kind::clustering_key); + builder.with_column("rc1", int32_type); + builder.with_column("rc2", int32_type); + builder.with_column("rc3", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); - lw_shared_ptr mt = make_lw_shared(s); + lw_shared_ptr mt = make_lw_shared(s); - auto key = partition_key::from_deeply_exploded(*s, {0}); - api::timestamp_type ts = write_timestamp; - mutation mut{s, key}; + auto key = partition_key::from_deeply_exploded(*s, {0}); + api::timestamp_type ts = write_timestamp; + mutation mut{s, key}; - // INSERT INTO multiple_rows (pk, ck, rc1) VALUES (0, 1, 10); - // INSERT INTO multiple_rows (pk, ck, rc2) VALUES (0, 2, 20); - // INSERT INTO multiple_rows (pk, ck, rc3) VALUES (0, 3, 30); - for (auto i : boost::irange(1, 4)) { - clustering_key ckey = clustering_key::from_deeply_exploded(*s, { i }); - mut.partition().apply_insert(*s, ckey, ts); - mut.set_cell(ckey, to_bytes(format("rc{}", i)), data_value{i * 10}, ts); - ts += 10; - } + // INSERT INTO multiple_rows (pk, ck, rc1) VALUES (0, 1, 10); + // INSERT INTO multiple_rows (pk, ck, rc2) VALUES (0, 2, 20); + // INSERT INTO multiple_rows (pk, ck, rc3) VALUES (0, 3, 30); + for (auto i : boost::irange(1, 4)) { + clustering_key ckey = clustering_key::from_deeply_exploded(*s, { i }); + mut.partition().apply_insert(*s, ckey, ts); + mut.set_cell(ckey, to_bytes(format("rc{}", i)), data_value{i * 10}, ts); + ts += 10; + } - mt->apply(std::move(mut)); - write_and_compare_sstables(s, mt, table_name); - }); + mt->apply(std::move(mut)); + write_and_compare_sstables(s, mt, table_name); } // Information on missing columns is serialized differently when the number of columns is > 64. // This test checks that this information is encoded correctly. -SEASTAR_TEST_CASE(test_write_missing_columns_large_set) { - return seastar::async([] { - sstring table_name = "missing_columns_large_set"; - // CREATE TABLE missing_columns_large_set (pk int, ck int, rc1 int, ..., rc64 int, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("ck", int32_type, column_kind::clustering_key); - for (auto idx: boost::irange(1, 65)) { - builder.with_column(to_bytes(format("rc{}", idx)), int32_type); +SEASTAR_THREAD_TEST_CASE(test_write_missing_columns_large_set) { + sstring table_name = "missing_columns_large_set"; + // CREATE TABLE missing_columns_large_set (pk int, ck int, rc1 int, ..., rc64 int, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("ck", int32_type, column_kind::clustering_key); + for (auto idx: boost::irange(1, 65)) { + builder.with_column(to_bytes(format("rc{}", idx)), int32_type); + } + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + auto key = partition_key::from_deeply_exploded(*s, {0}); + api::timestamp_type ts = write_timestamp; + mutation mut{s, key}; + + // INSERT INTO missing_columns_large_set (pk, ck, rc1, ..., rc62) VALUES (0, 0, 1, ..., 62); + // For missing columns, the missing ones will be written as majority are present. + { + clustering_key ckey = clustering_key::from_deeply_exploded(*s, {0}); + mut.partition().apply_insert(*s, ckey, ts); + for (auto idx: boost::irange(1, 63)) { + mut.set_cell(ckey, to_bytes(format("rc{}", idx)), data_value{idx}, ts); } - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - auto key = partition_key::from_deeply_exploded(*s, {0}); - api::timestamp_type ts = write_timestamp; - mutation mut{s, key}; - - // INSERT INTO missing_columns_large_set (pk, ck, rc1, ..., rc62) VALUES (0, 0, 1, ..., 62); - // For missing columns, the missing ones will be written as majority are present. - { - clustering_key ckey = clustering_key::from_deeply_exploded(*s, {0}); - mut.partition().apply_insert(*s, ckey, ts); - for (auto idx: boost::irange(1, 63)) { - mut.set_cell(ckey, to_bytes(format("rc{}", idx)), data_value{idx}, ts); - } - mt->apply(std::move(mut)); - } - ts += 10; - // INSERT INTO missing_columns_large_set (pk, ck, rc63, rc64) VALUES (0, 1, 63, 64); - // For missing columns, the present ones will be written as majority are missing. - { - clustering_key ckey = clustering_key::from_deeply_exploded(*s, {1}); - mut.partition().apply_insert(*s, ckey, ts); - mut.set_cell(ckey, to_bytes(format("rc63", 63)), data_value{63}, ts); - mut.set_cell(ckey, to_bytes(format("rc64", 63)), data_value{64}, ts); - mt->apply(std::move(mut)); - } - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_counter_table) { - return seastar::async([] { - sstring table_name = "counter_table"; - // CREATE TABLE counter_table (pk text, ck text, rc1 counter, rc2 counter, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", utf8_type, column_kind::partition_key); - builder.with_column("ck", utf8_type, column_kind::clustering_key); - builder.with_column("rc1", counter_type); - builder.with_column("rc2", counter_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - auto key = partition_key::from_exploded(*s, {to_bytes("key")}); - mutation mut{s, key}; - - // Keep counter ids fixed to produce the same binary output on each run - std::vector ids = { - counter_id{utils::UUID{"19478feb-8e7c-4729-9a78-9b476552f13d"}}, - counter_id{utils::UUID{"e079a6fe-eb79-4bdf-97ca-c87a2c387d5c"}}, - counter_id{utils::UUID{"bbba5897-78b6-4cdc-9a0d-ea9e9a3b833f"}}, - }; - boost::range::sort(ids); - - const column_definition& cdef1 = *s->get_column_definition("rc1"); - const column_definition& cdef2 = *s->get_column_definition("rc2"); - - auto ckey1 = clustering_key::from_exploded(*s, {to_bytes("ck1")}); - - counter_cell_builder b1; - b1.add_shard(counter_shard(ids[0], 5, 1)); - b1.add_shard(counter_shard(ids[1], -4, 1)); - b1.add_shard(counter_shard(ids[2], 9, 1)); - mut.set_clustered_cell(ckey1, cdef1, b1.build(write_timestamp)); - - counter_cell_builder b2; - b2.add_shard(counter_shard(ids[1], -1, 1)); - b2.add_shard(counter_shard(ids[2], 2, 1)); - mut.set_clustered_cell(ckey1, cdef2, b2.build(write_timestamp)); - - auto ckey2 = clustering_key::from_exploded(*s, {to_bytes("ck2")}); - mut.set_clustered_cell(ckey2, cdef1, atomic_cell::make_dead(write_timestamp, write_time_point)); - - mt->apply(mut); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_different_types) { - return seastar::async([] { - sstring table_name = "different_types"; - // CREATE TABLE different_types (pk text, asciival ascii, bigintval bigint, - // blobval blob, boolval boolean, dateval date, decimalval decimal, - // doubleval double, floatval float, inetval inet, intval int, - // smallintval smallint, timeval time, tsval timestamp, timeuuidval timeuuid, - // tinyintval tinyint, uuidval uuid, varcharval varchar, varintval varint, - // durationval duration, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", utf8_type, column_kind::partition_key); - builder.with_column("asciival", ascii_type); - builder.with_column("bigintval", long_type); - builder.with_column("blobval", bytes_type); - builder.with_column("boolval", boolean_type); - builder.with_column("dateval", simple_date_type); - builder.with_column("decimalval", decimal_type); - builder.with_column("doubleval", double_type); - builder.with_column("floatval", float_type); - builder.with_column("inetval", inet_addr_type); - builder.with_column("intval", int32_type); - builder.with_column("smallintval", short_type); - builder.with_column("timeval", time_type); - builder.with_column("tsval", timestamp_type); - builder.with_column("timeuuidval", timeuuid_type); - builder.with_column("tinyintval", byte_type); - builder.with_column("uuidval", uuid_type); - builder.with_column("varcharval", utf8_type); - builder.with_column("varintval", varint_type); - builder.with_column("durationval", duration_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - // INSERT INTO different_types (pk, asciival, bigintval, blobval, boolval, - // dateval, decimalval, doubleval, floatval, inetval, intval, smallintval, - // timeval, tsval, timeuuidval, tinyintval, uuidval, varcharval, varintval, - // durationval) VALUES ('key', 'hello', 9223372036854775807, - // textAsBlob('great'), true, '2017-05-05', - // 5.45, 36.6, 7.62, '192.168.0.110', -2147483648, 32767, '19:45:05.090', - // '2015-05-01 09:30:54.234+0000', 50554d6e-29bb-11e5-b345-feff819cdc9f, 127, - // 01234567-0123-0123-0123-0123456789ab, 'привет', 123, 1h4m48s20ms); - auto key = make_dkey(s, {to_bytes("key")}); - mutation mut{s, key}; - clustering_key ckey = clustering_key::make_empty(); - mut.partition().apply_insert(*s, ckey, write_timestamp); - mut.set_cell(ckey, "asciival", data_value{"hello"}, write_timestamp); - mut.set_cell(ckey, "bigintval", data_value{std::numeric_limits::max()}, write_timestamp); - mut.set_cell(ckey, "blobval", data_value{bytes{'g', 'r', 'e', 'a', 't'}}, write_timestamp); - mut.set_cell(ckey, "boolval", data_value{true}, write_timestamp); - mut.set_cell(ckey, "dateval", simple_date_type->deserialize(simple_date_type->from_string("2017-05-05")), write_timestamp); - mut.set_cell(ckey, "decimalval", decimal_type->deserialize(decimal_type->from_string("5.45")), write_timestamp); - mut.set_cell(ckey, "doubleval", data_value{36.6}, write_timestamp); - mut.set_cell(ckey, "floatval", data_value{7.62f}, write_timestamp); - mut.set_cell(ckey, "inetval", inet_addr_type->deserialize(inet_addr_type->from_string("192.168.0.110")), write_timestamp); - mut.set_cell(ckey, "intval", data_value{std::numeric_limits::min()}, write_timestamp); - mut.set_cell(ckey, "smallintval", data_value{int16_t(32767)}, write_timestamp); - mut.set_cell(ckey, "timeval", time_type->deserialize(time_type->from_string("19:45:05.090")), write_timestamp); - mut.set_cell(ckey, "tsval", timestamp_type->deserialize(timestamp_type->from_string("2015-05-01 09:30:54.234+0000")), write_timestamp); - mut.set_cell(ckey, "timeuuidval", timeuuid_type->deserialize(timeuuid_type->from_string("50554d6e-29bb-11e5-b345-feff819cdc9f")), write_timestamp); - mut.set_cell(ckey, "tinyintval", data_value{int8_t{127}}, write_timestamp); - mut.set_cell(ckey, "uuidval", data_value{utils::UUID(sstring("01234567-0123-0123-0123-0123456789ab"))}, write_timestamp); - mut.set_cell(ckey, "varcharval", data_value{"привет"}, write_timestamp); - mut.set_cell(ckey, "varintval", varint_type->deserialize(varint_type->from_string("123")), write_timestamp); - mut.set_cell(ckey, "durationval", duration_type->deserialize(duration_type->from_string("1h4m48s20ms")), write_timestamp); mt->apply(std::move(mut)); - - write_and_compare_sstables(s, mt, table_name); - }); -} - -SEASTAR_TEST_CASE(test_write_empty_clustering_values) { - return seastar::async([] { - sstring table_name = "empty_clustering_values"; - // CREATE TABLE empty_clustering_values (pk int, ck1 text, ck2 int, ck3 text, rc int, PRIMARY KEY (pk, ck1, ck2, ck3)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("ck1", utf8_type, column_kind::clustering_key); - builder.with_column("ck2", int32_type, column_kind::clustering_key); - builder.with_column("ck3", utf8_type, column_kind::clustering_key); - builder.with_column("rc", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); - - lw_shared_ptr mt = make_lw_shared(s); - - auto key = partition_key::from_deeply_exploded(*s, {0}); - mutation mut{s, key}; - - // INSERT INTO empty_clustering_values (pk, ck1, ck2, ck3, rc) VALUES (0, '', 1, '', 2); - clustering_key ckey = clustering_key::from_deeply_exploded(*s, { "", 1, "" }); - mut.partition().apply_insert(*s, ckey, write_timestamp); - mut.set_cell(ckey, "rc", data_value{2}, write_timestamp); - + } + ts += 10; + // INSERT INTO missing_columns_large_set (pk, ck, rc63, rc64) VALUES (0, 1, 63, 64); + // For missing columns, the present ones will be written as majority are missing. + { + clustering_key ckey = clustering_key::from_deeply_exploded(*s, {1}); + mut.partition().apply_insert(*s, ckey, ts); + mut.set_cell(ckey, to_bytes(format("rc63", 63)), data_value{63}, ts); + mut.set_cell(ckey, to_bytes(format("rc64", 63)), data_value{64}, ts); mt->apply(std::move(mut)); - write_and_compare_sstables(s, mt, table_name); - }); + } + + write_and_compare_sstables(s, mt, table_name); } -SEASTAR_TEST_CASE(test_write_large_clustering_key) { - return seastar::async([] { - sstring table_name = "large_clustering_key"; - // CREATE TABLE large_clustering_key (pk int, ck1 text, ck2 text, ..., ck35 text, rc int, PRIMARY KEY (pk, ck1, ck2, ..., ck35)) WITH compression = {'sstable_compression': ''}; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - for (auto idx: boost::irange(1, 36)) { - builder.with_column(to_bytes(format("ck{}", idx)), utf8_type, column_kind::clustering_key); - } - builder.with_column("rc", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::no); +SEASTAR_THREAD_TEST_CASE(test_write_counter_table) { + sstring table_name = "counter_table"; + // CREATE TABLE counter_table (pk text, ck text, rc1 counter, rc2 counter, PRIMARY KEY (pk, ck)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", utf8_type, column_kind::partition_key); + builder.with_column("ck", utf8_type, column_kind::clustering_key); + builder.with_column("rc1", counter_type); + builder.with_column("rc2", counter_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); - lw_shared_ptr mt = make_lw_shared(s); + lw_shared_ptr mt = make_lw_shared(s); + auto key = partition_key::from_exploded(*s, {to_bytes("key")}); + mutation mut{s, key}; - auto key = partition_key::from_deeply_exploded(*s, {0}); - mutation mut{s, key}; + // Keep counter ids fixed to produce the same binary output on each run + std::vector ids = { + counter_id{utils::UUID{"19478feb-8e7c-4729-9a78-9b476552f13d"}}, + counter_id{utils::UUID{"e079a6fe-eb79-4bdf-97ca-c87a2c387d5c"}}, + counter_id{utils::UUID{"bbba5897-78b6-4cdc-9a0d-ea9e9a3b833f"}}, + }; + boost::range::sort(ids); - // Clustering columns ckX are filled the following way: - // - for even X - // - "X" for odd X - // INSERT INTO large_clustering_key (pk, ck1, ck2, ck3, rc) VALUES (0, '1', '', '3',..., '', '35', 1); - std::vector clustering_values; - for (auto idx: boost::irange(1, 36)) { - clustering_values.emplace_back((idx % 2 == 1) ? std::to_string(idx) : std::string{}); - } - clustering_key ckey = clustering_key::from_deeply_exploded(*s, clustering_values); - mut.partition().apply_insert(*s, ckey, write_timestamp); - mut.set_cell(ckey, "rc", data_value{1}, write_timestamp); + const column_definition& cdef1 = *s->get_column_definition("rc1"); + const column_definition& cdef2 = *s->get_column_definition("rc2"); - mt->apply(std::move(mut)); - write_and_compare_sstables(s, mt, table_name); - }); + auto ckey1 = clustering_key::from_exploded(*s, {to_bytes("ck1")}); + + counter_cell_builder b1; + b1.add_shard(counter_shard(ids[0], 5, 1)); + b1.add_shard(counter_shard(ids[1], -4, 1)); + b1.add_shard(counter_shard(ids[2], 9, 1)); + mut.set_clustered_cell(ckey1, cdef1, b1.build(write_timestamp)); + + counter_cell_builder b2; + b2.add_shard(counter_shard(ids[1], -1, 1)); + b2.add_shard(counter_shard(ids[2], 2, 1)); + mut.set_clustered_cell(ckey1, cdef2, b2.build(write_timestamp)); + + auto ckey2 = clustering_key::from_exploded(*s, {to_bytes("ck2")}); + mut.set_clustered_cell(ckey2, cdef1, atomic_cell::make_dead(write_timestamp, write_time_point)); + + mt->apply(mut); + + write_and_compare_sstables(s, mt, table_name); } -SEASTAR_TEST_CASE(test_write_compact_table) { - return seastar::async([] { - sstring table_name = "compact_table"; - // CREATE TABLE compact_table (pk int, ck1 int, ck2 int, rc int, PRIMARY KEY (pk, ck1, ck2)) WITH compression = {'sstable_compression': ''} AND COMPACT STORAGE; - schema_builder builder("sst3", table_name); - builder.with_column("pk", int32_type, column_kind::partition_key); - builder.with_column("ck1", int32_type, column_kind::clustering_key); - builder.with_column("ck2", int32_type, column_kind::clustering_key); - builder.with_column("rc", int32_type); - builder.set_compressor_params(compression_parameters()); - schema_ptr s = builder.build(schema_builder::compact_storage::yes); +SEASTAR_THREAD_TEST_CASE(test_write_different_types) { + sstring table_name = "different_types"; + // CREATE TABLE different_types (pk text, asciival ascii, bigintval bigint, + // blobval blob, boolval boolean, dateval date, decimalval decimal, + // doubleval double, floatval float, inetval inet, intval int, + // smallintval smallint, timeval time, tsval timestamp, timeuuidval timeuuid, + // tinyintval tinyint, uuidval uuid, varcharval varchar, varintval varint, + // durationval duration, PRIMARY KEY (pk)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", utf8_type, column_kind::partition_key); + builder.with_column("asciival", ascii_type); + builder.with_column("bigintval", long_type); + builder.with_column("blobval", bytes_type); + builder.with_column("boolval", boolean_type); + builder.with_column("dateval", simple_date_type); + builder.with_column("decimalval", decimal_type); + builder.with_column("doubleval", double_type); + builder.with_column("floatval", float_type); + builder.with_column("inetval", inet_addr_type); + builder.with_column("intval", int32_type); + builder.with_column("smallintval", short_type); + builder.with_column("timeval", time_type); + builder.with_column("tsval", timestamp_type); + builder.with_column("timeuuidval", timeuuid_type); + builder.with_column("tinyintval", byte_type); + builder.with_column("uuidval", uuid_type); + builder.with_column("varcharval", utf8_type); + builder.with_column("varintval", varint_type); + builder.with_column("durationval", duration_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); - lw_shared_ptr mt = make_lw_shared(s); + lw_shared_ptr mt = make_lw_shared(s); - auto key = partition_key::from_deeply_exploded(*s, {1}); - mutation mut{s, key}; + // INSERT INTO different_types (pk, asciival, bigintval, blobval, boolval, + // dateval, decimalval, doubleval, floatval, inetval, intval, smallintval, + // timeval, tsval, timeuuidval, tinyintval, uuidval, varcharval, varintval, + // durationval) VALUES ('key', 'hello', 9223372036854775807, + // textAsBlob('great'), true, '2017-05-05', + // 5.45, 36.6, 7.62, '192.168.0.110', -2147483648, 32767, '19:45:05.090', + // '2015-05-01 09:30:54.234+0000', 50554d6e-29bb-11e5-b345-feff819cdc9f, 127, + // 01234567-0123-0123-0123-0123456789ab, 'привет', 123, 1h4m48s20ms); + auto key = make_dkey(s, {to_bytes("key")}); + mutation mut{s, key}; + clustering_key ckey = clustering_key::make_empty(); + mut.partition().apply_insert(*s, ckey, write_timestamp); + mut.set_cell(ckey, "asciival", data_value{"hello"}, write_timestamp); + mut.set_cell(ckey, "bigintval", data_value{std::numeric_limits::max()}, write_timestamp); + mut.set_cell(ckey, "blobval", data_value{bytes{'g', 'r', 'e', 'a', 't'}}, write_timestamp); + mut.set_cell(ckey, "boolval", data_value{true}, write_timestamp); + mut.set_cell(ckey, "dateval", simple_date_type->deserialize(simple_date_type->from_string("2017-05-05")), write_timestamp); + mut.set_cell(ckey, "decimalval", decimal_type->deserialize(decimal_type->from_string("5.45")), write_timestamp); + mut.set_cell(ckey, "doubleval", data_value{36.6}, write_timestamp); + mut.set_cell(ckey, "floatval", data_value{7.62f}, write_timestamp); + mut.set_cell(ckey, "inetval", inet_addr_type->deserialize(inet_addr_type->from_string("192.168.0.110")), write_timestamp); + mut.set_cell(ckey, "intval", data_value{std::numeric_limits::min()}, write_timestamp); + mut.set_cell(ckey, "smallintval", data_value{int16_t(32767)}, write_timestamp); + mut.set_cell(ckey, "timeval", time_type->deserialize(time_type->from_string("19:45:05.090")), write_timestamp); + mut.set_cell(ckey, "tsval", timestamp_type->deserialize(timestamp_type->from_string("2015-05-01 09:30:54.234+0000")), write_timestamp); + mut.set_cell(ckey, "timeuuidval", timeuuid_type->deserialize(timeuuid_type->from_string("50554d6e-29bb-11e5-b345-feff819cdc9f")), write_timestamp); + mut.set_cell(ckey, "tinyintval", data_value{int8_t{127}}, write_timestamp); + mut.set_cell(ckey, "uuidval", data_value{utils::UUID(sstring("01234567-0123-0123-0123-0123456789ab"))}, write_timestamp); + mut.set_cell(ckey, "varcharval", data_value{"привет"}, write_timestamp); + mut.set_cell(ckey, "varintval", varint_type->deserialize(varint_type->from_string("123")), write_timestamp); + mut.set_cell(ckey, "durationval", duration_type->deserialize(duration_type->from_string("1h4m48s20ms")), write_timestamp); + mt->apply(std::move(mut)); - // INSERT INTO compact_table (pk, ck1, rc) VALUES (1, 1, 1); - clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 1 }); - mut.set_cell(ckey, "rc", data_value{1}, write_timestamp); - - mt->apply(std::move(mut)); - write_and_compare_sstables(s, mt, table_name); - }); + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_empty_clustering_values) { + sstring table_name = "empty_clustering_values"; + // CREATE TABLE empty_clustering_values (pk int, ck1 text, ck2 int, ck3 text, rc int, PRIMARY KEY (pk, ck1, ck2, ck3)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("ck1", utf8_type, column_kind::clustering_key); + builder.with_column("ck2", int32_type, column_kind::clustering_key); + builder.with_column("ck3", utf8_type, column_kind::clustering_key); + builder.with_column("rc", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + auto key = partition_key::from_deeply_exploded(*s, {0}); + mutation mut{s, key}; + + // INSERT INTO empty_clustering_values (pk, ck1, ck2, ck3, rc) VALUES (0, '', 1, '', 2); + clustering_key ckey = clustering_key::from_deeply_exploded(*s, { "", 1, "" }); + mut.partition().apply_insert(*s, ckey, write_timestamp); + mut.set_cell(ckey, "rc", data_value{2}, write_timestamp); + + mt->apply(std::move(mut)); + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_large_clustering_key) { + sstring table_name = "large_clustering_key"; + // CREATE TABLE large_clustering_key (pk int, ck1 text, ck2 text, ..., ck35 text, rc int, PRIMARY KEY (pk, ck1, ck2, ..., ck35)) WITH compression = {'sstable_compression': ''}; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + for (auto idx: boost::irange(1, 36)) { + builder.with_column(to_bytes(format("ck{}", idx)), utf8_type, column_kind::clustering_key); + } + builder.with_column("rc", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::no); + + lw_shared_ptr mt = make_lw_shared(s); + + auto key = partition_key::from_deeply_exploded(*s, {0}); + mutation mut{s, key}; + + // Clustering columns ckX are filled the following way: + // - for even X + // - "X" for odd X + // INSERT INTO large_clustering_key (pk, ck1, ck2, ck3, rc) VALUES (0, '1', '', '3',..., '', '35', 1); + std::vector clustering_values; + for (auto idx: boost::irange(1, 36)) { + clustering_values.emplace_back((idx % 2 == 1) ? std::to_string(idx) : std::string{}); + } + clustering_key ckey = clustering_key::from_deeply_exploded(*s, clustering_values); + mut.partition().apply_insert(*s, ckey, write_timestamp); + mut.set_cell(ckey, "rc", data_value{1}, write_timestamp); + + mt->apply(std::move(mut)); + write_and_compare_sstables(s, mt, table_name); +} + +SEASTAR_THREAD_TEST_CASE(test_write_compact_table) { + sstring table_name = "compact_table"; + // CREATE TABLE compact_table (pk int, ck1 int, ck2 int, rc int, PRIMARY KEY (pk, ck1, ck2)) WITH compression = {'sstable_compression': ''} AND COMPACT STORAGE; + schema_builder builder("sst3", table_name); + builder.with_column("pk", int32_type, column_kind::partition_key); + builder.with_column("ck1", int32_type, column_kind::clustering_key); + builder.with_column("ck2", int32_type, column_kind::clustering_key); + builder.with_column("rc", int32_type); + builder.set_compressor_params(compression_parameters()); + schema_ptr s = builder.build(schema_builder::compact_storage::yes); + + lw_shared_ptr mt = make_lw_shared(s); + + auto key = partition_key::from_deeply_exploded(*s, {1}); + mutation mut{s, key}; + + // INSERT INTO compact_table (pk, ck1, rc) VALUES (1, 1, 1); + clustering_key ckey = clustering_key::from_deeply_exploded(*s, { 1 }); + mut.set_cell(ckey, "rc", data_value{1}, write_timestamp); + + mt->apply(std::move(mut)); + write_and_compare_sstables(s, mt, table_name); }