@@ -732,3 +732,68 @@ def test_insert_in_name_and_field(self, connection):
732732 row = connection .execute (sa .select (tb ).where (tb .c .id == 2 )).fetchone ()
733733
734734 assert row == (2 , "INSERT is my favourite operation" )
735+
736+
737+ class TestSecondaryIndex (TestBase ):
738+ __backend__ = True
739+
740+ def test_column_indexes (self , connection : sa .Connection , metadata : sa .MetaData ):
741+ table = Table (
742+ "test_column_indexes/table" ,
743+ metadata ,
744+ sa .Column ("id" , sa .Integer , primary_key = True ),
745+ sa .Column ("index_col1" , sa .Integer , index = True ),
746+ sa .Column ("index_col2" , sa .Integer , index = True ),
747+ )
748+ table .create (connection )
749+
750+ table_desc : ydb .TableDescription = connection .connection .driver_connection .describe (table .name )
751+ indexes : list [ydb .TableIndex ] = table_desc .indexes
752+ assert len (indexes ) == 2
753+ indexes_map = {idx .name : idx for idx in indexes }
754+
755+ assert "ix_test_column_indexes_table_index_col1" in indexes_map
756+ index1 = indexes_map ["ix_test_column_indexes_table_index_col1" ]
757+ assert index1 .index_columns == ["index_col1" ]
758+
759+ assert "ix_test_column_indexes_table_index_col2" in indexes_map
760+ index1 = indexes_map ["ix_test_column_indexes_table_index_col2" ]
761+ assert index1 .index_columns == ["index_col2" ]
762+
763+ def test_async_index (self , connection : sa .Connection , metadata : sa .MetaData ):
764+ table = Table (
765+ "test_async_index/table" ,
766+ metadata ,
767+ sa .Column ("id" , sa .Integer , primary_key = True ),
768+ sa .Column ("index_col1" , sa .Integer ),
769+ sa .Column ("index_col2" , sa .Integer ),
770+ sa .Index ("test_async_index" , "index_col1" , "index_col2" , ydb_async = True ),
771+ )
772+ table .create (connection )
773+
774+ table_desc : ydb .TableDescription = connection .connection .driver_connection .describe (table .name )
775+ indexes : list [ydb .TableIndex ] = table_desc .indexes
776+ assert len (indexes ) == 1
777+ index = indexes [0 ]
778+ assert index .name == "test_async_index"
779+ assert set (index .index_columns ) == {"index_col1" , "index_col2" }
780+ # TODO: Uncomment after fix https://github.com/ydb-platform/ydb-python-sdk/issues/351
781+ # assert index.to_pb().WhichOneof("type") == "global_async_index"
782+
783+ def test_cover_index (self , connection : sa .Connection , metadata : sa .MetaData ):
784+ table = Table (
785+ "test_cover_index/table" ,
786+ metadata ,
787+ sa .Column ("id" , sa .Integer , primary_key = True ),
788+ sa .Column ("index_col1" , sa .Integer ),
789+ sa .Column ("index_col2" , sa .Integer ),
790+ sa .Index ("test_cover_index" , "index_col1" , ydb_cover = ["index_col2" ]),
791+ )
792+ table .create (connection )
793+
794+ table_desc : ydb .TableDescription = connection .connection .driver_connection .describe (table .name )
795+ indexes : list [ydb .TableIndex ] = table_desc .indexes
796+ assert len (indexes ) == 1
797+ index = indexes [0 ]
798+ assert index .name == "test_cover_index"
799+ assert set (index .index_columns ) == {"index_col1" }
0 commit comments