From dd8f56ad3a7aa550d01bc6c02fbb53ded4100126 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 12 Nov 2024 14:57:26 +0300 Subject: [PATCH] test: Move test_query_built_indexes_virtual_table from boost to cqlpy And split it into two -- one for materialized view, another for secondary index. This is to fit current cqlpy layout that has different files for views and indexes. refs: #21552 refs: #21551 (detached this patch from there, as that PR needs fix in the core code) Signed-off-by: Pavel Emelyanov Closes scylladb/scylladb#21677 --- test/boost/virtual_reader_test.cc | 28 ---------------------------- test/cqlpy/test_materialized_view.py | 10 ++++++++++ test/cqlpy/test_secondary_index.py | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/test/boost/virtual_reader_test.cc b/test/boost/virtual_reader_test.cc index 66fdd55f68..d6fb666871 100644 --- a/test/boost/virtual_reader_test.cc +++ b/test/boost/virtual_reader_test.cc @@ -212,31 +212,3 @@ SEASTAR_TEST_CASE(test_query_view_built_progress_virtual_table) { assert_that(rs).is_rows().with_size(0); }); } - -SEASTAR_TEST_CASE(test_query_built_indexes_virtual_table) { - return do_with_cql_env_thread([] (cql_test_env& e) { - auto idx = secondary_index::index_table_name("idx"); - e.execute_cql("create table cf(p int PRIMARY KEY, v int);").get(); - auto f1 = e.local_view_builder().wait_until_built("ks", "vcf"); - auto f2 = e.local_view_builder().wait_until_built("ks", idx); - e.execute_cql("create materialized view vcf as select * from cf " - "where v is not null and p is not null " - "primary key (v, p)").get(); - e.execute_cql("create index idx on cf (v)").get(); - f1.get(); - f2.get(); - auto rs = e.execute_cql("select * from system.built_views").get(); - assert_that(rs).is_rows().with_rows_ignore_order({ - { {utf8_type->decompose(sstring("ks"))}, {utf8_type->decompose(idx)} }, - { {utf8_type->decompose(sstring("ks"))}, {"vcf"} }, - }); - rs = e.execute_cql("select * from system.\"IndexInfo\"").get(); - assert_that(rs).is_rows().with_rows_ignore_order({ - { {utf8_type->decompose(sstring("ks"))}, {utf8_type->decompose(sstring("idx"))} }, - }); - rs = e.execute_cql("select * from system.\"IndexInfo\" where table_name = 'ks' and index_name = 'idx'").get(); - assert_that(rs).is_rows().with_size(1); - rs = e.execute_cql("select * from system.\"IndexInfo\" where table_name = 'ks' and index_name = 'vcf'").get(); - assert_that(rs).is_rows().with_size(0); - }); -} diff --git a/test/cqlpy/test_materialized_view.py b/test/cqlpy/test_materialized_view.py index 11b5d6d4c6..f948096337 100644 --- a/test/cqlpy/test_materialized_view.py +++ b/test/cqlpy/test_materialized_view.py @@ -1569,3 +1569,13 @@ def test_views_with_future_tombstones(cql, test_keyspace): cql.execute(f'insert into {table} (a,b,c,d,e) values (3,4,5,6,7) using timestamp 18') assert [] == list(cql.execute(f'select * from {table}')) assert [] == list(cql.execute(f'select * from {mv}')) + +# Test view representation in system.* tables +def test_view_in_system_tables(cql, test_keyspace): + with new_test_table(cql, test_keyspace, "p int PRIMARY KEY, v int") as base: + with new_materialized_view(cql, base, '*', 'v,p', 'v is not null and p is not null') as view: + wait_for_view_built(cql, view) + res = [ f'{r.keyspace_name}.{r.view_name}' for r in cql.execute('select * from system.built_views')] + assert view in res + res = [ f'{r.table_name}.{r.index_name}' for r in cql.execute('select * from system."IndexInfo"')] + assert view not in res diff --git a/test/cqlpy/test_secondary_index.py b/test/cqlpy/test_secondary_index.py index ed8cf4ead3..9e5eefaf31 100644 --- a/test/cqlpy/test_secondary_index.py +++ b/test/cqlpy/test_secondary_index.py @@ -14,7 +14,7 @@ from cassandra.protocol import SyntaxException, AlreadyExists, InvalidRequest, C from cassandra.query import SimpleStatement from .cassandra_tests.porting import assert_rows, assert_row_count, assert_rows_ignoring_order, assert_empty -from .util import new_test_table, unique_name, unique_key_int +from .util import new_test_table, unique_name, unique_key_int, is_scylla # A reproducer for issue #7443: Normally, when the entire table is SELECTed, # the partitions are returned sorted by the partitions' token. When there @@ -1956,3 +1956,18 @@ def test_paging_and_drop_index_no_allow_filtering(cql, test_keyspace): assert len(r.current_rows) <= page_size got.extend(r.current_rows) assert expected == got + + +# Test index representation in system.* tables +def test_index_in_system_tables(cql, test_keyspace): + with new_test_table(cql, test_keyspace, "p int PRIMARY KEY, v int") as table: + index_name = unique_name() + cql.execute(f"CREATE INDEX {index_name} ON {table}(v)") + wait_for_index(cql, test_keyspace, index_name) + if is_scylla(cql): + res = [ f'{r.keyspace_name}.{r.view_name}' for r in cql.execute('select * from system.built_views')] + assert f'{test_keyspace}.{index_name}_index' in res + res = [ f'{r.table_name}::{r.index_name}' for r in cql.execute('select * from system."IndexInfo"')] + assert f'{test_keyspace}::{index_name}' in res + res = cql.execute(f'select * from system."IndexInfo" where table_name = \'{test_keyspace}\' AND index_name = \'{index_name}\'').one() + assert (test_keyspace, index_name) == (res.table_name, res.index_name)