From fcfbc804e4542c833e97e8489495d41dc86d0102 Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Wed, 11 Jul 2018 10:52:38 +0200 Subject: [PATCH] tests: add filtering indexed queries tests Tests covering ALLOW FILTERING usage while using secondary indexes as well are added to cql_query_test. Tests are based on Cassandra's test suite for filtering secondary indexes + some more simple cases. --- tests/cql_query_test.cc | 139 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tests/cql_query_test.cc b/tests/cql_query_test.cc index 3dfe3b423f..e5a07cc3d7 100644 --- a/tests/cql_query_test.cc +++ b/tests/cql_query_test.cc @@ -3331,3 +3331,142 @@ SEASTAR_TEST_CASE(test_allow_filtering_multiple_regular) { }}); }); } + +SEASTAR_TEST_CASE(test_allow_filtering_with_secondary_index) { + return do_with_cql_env_thread([] (cql_test_env& e) { + e.execute_cql("CREATE TABLE t (a int, b int, c int, d int, e int, PRIMARY KEY(a, b));").get(); + e.require_table_exists("ks", "t").get(); + e.execute_cql("CREATE INDEX ON t(c)").get(); + + e.execute_cql("INSERT INTO t (a, b, c, d, e) VALUES (1, 1, 1, 1, 1)").get(); + e.execute_cql("INSERT INTO t (a, b, c, d, e) VALUES (1, 2, 3, 4, 5)").get(); + e.execute_cql("INSERT INTO t (a, b, c, d, e) VALUES (1, 3, 5, 1, 9)").get(); + e.execute_cql("INSERT INTO t (a, b, c, d, e) VALUES (1, 4, 5, 7, 5)").get(); + + auto msg = e.execute_cql("SELECT a, b, c, d, e FROM t WHERE c = 3").get0(); + assert_that(msg).is_rows().with_rows({{ + int32_type->decompose(1), + int32_type->decompose(2), + int32_type->decompose(3), + int32_type->decompose(4), + int32_type->decompose(5) + }}); + + BOOST_CHECK_THROW(e.execute_cql("SELECT * FROM t WHERE c = 5 and d = 1").get(), exceptions::invalid_request_exception); + + msg = e.execute_cql("SELECT a, b, c, d, e FROM t WHERE c = 5 and d = 1 ALLOW FILTERING").get0(); + assert_that(msg).is_rows().with_rows({{ + int32_type->decompose(1), + int32_type->decompose(3), + int32_type->decompose(5), + int32_type->decompose(1), + int32_type->decompose(9) + }}); + + e.execute_cql("CREATE TABLE t2 (pk1 int, pk2 int, c1 int, c2 int, v int, PRIMARY KEY ((pk1, pk2), c1, c2));").get(); + e.execute_cql("CREATE INDEX ON t2(v)").get(); + for (int i = 1; i <= 5; ++i) { + for (int j = 1; j <= 2; ++j) { + e.execute_cql(sprint("INSERT INTO t2 (pk1, pk2, c1, c2, v) VALUES (%s, %s, %s, %s, %s)", j, 1, 1, 1, i)).get(); + e.execute_cql(sprint("INSERT INTO t2 (pk1, pk2, c1, c2, v) VALUES (%s, %s, %s, %s, %s)", j, 1, 1, i, i)).get(); + e.execute_cql(sprint("INSERT INTO t2 (pk1, pk2, c1, c2, v) VALUES (%s, %s, %s, %s, %s)", j, 1, i, i, i)).get(); + e.execute_cql(sprint("INSERT INTO t2 (pk1, pk2, c1, c2, v) VALUES (%s, %s, %s, %s, %s)", j, i, i, i, i)).get(); + } + } + + eventually([&] { + auto msg = e.execute_cql("SELECT * FROM t2 WHERE pk1 = 1 AND c1 > 0 AND c1 < 5 AND c2 = 1 AND v = 3 ALLOW FILTERING;").get0(); + assert_that(msg).is_rows().with_rows({}); + }); + + eventually([&] { + auto msg = e.execute_cql("SELECT * FROM t2 WHERE pk1 = 1 AND c1 > 0 AND c1 < 5 AND c2 = 3 AND v = 3 ALLOW FILTERING;").get0(); + assert_that(msg).is_rows().with_rows({ + { + int32_type->decompose(1), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3) + }, + { + int32_type->decompose(1), + int32_type->decompose(1), + int32_type->decompose(1), + int32_type->decompose(3), + int32_type->decompose(3) + }, + { + int32_type->decompose(1), + int32_type->decompose(1), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3) + } + }); + }); + + eventually([&] { + auto msg = e.execute_cql("SELECT * FROM t2 WHERE pk1 = 1 AND c2 > 1 AND c2 < 5 AND v = 1 ALLOW FILTERING;").get0(); + assert_that(msg).is_rows().with_rows({}); + }); + + eventually([&] { + auto msg = e.execute_cql("SELECT * FROM t2 WHERE pk1 = 1 AND c1 > 1 AND c2 > 2 AND v = 3 ALLOW FILTERING;").get0(); + assert_that(msg).is_rows().with_rows({ + { + int32_type->decompose(1), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3) + }, + { + int32_type->decompose(1), + int32_type->decompose(1), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3) + } + }); + }); + + eventually([&] { + auto msg = e.execute_cql("SELECT * FROM t2 WHERE pk1 = 1 AND pk2 > 1 AND c2 > 2 AND v = 3 ALLOW FILTERING;").get0(); + assert_that(msg).is_rows().with_rows({{ + int32_type->decompose(1), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3), + int32_type->decompose(3) + }}); + }); + + eventually([&] { + auto msg = e.execute_cql("SELECT * FROM t2 WHERE pk1 >= 2 AND pk2 <=3 AND c1 IN(0,1,2) AND c2 IN(0,1,2) AND v < 3 ALLOW FILTERING;").get0(); + assert_that(msg).is_rows().with_rows({ + { + int32_type->decompose(2), + int32_type->decompose(2), + int32_type->decompose(2), + int32_type->decompose(2), + int32_type->decompose(2) + }, + { + int32_type->decompose(2), + int32_type->decompose(1), + int32_type->decompose(1), + int32_type->decompose(2), + int32_type->decompose(2) + }, + { + int32_type->decompose(2), + int32_type->decompose(1), + int32_type->decompose(2), + int32_type->decompose(2), + int32_type->decompose(2) + } + }); + }); + }); +}