@@ -646,3 +646,61 @@ def test_drop_data_object_materialized_view_calls_correct_drop(mocker: MockFixtu
646646 drop_view_mock .assert_called_once_with (
647647 mv_data_object .to_table (), ignore_if_not_exists = True , materialized = True
648648 )
649+
650+
651+ def test_columns (mocker : MockFixture , make_mocked_engine_adapter : t .Callable ):
652+ adapter = make_mocked_engine_adapter (DatabricksEngineAdapter , default_catalog = "test_catalog" )
653+
654+ # Override/mock get_current_catalog to return default
655+ current_catalog_mock = mocker .patch .object (
656+ adapter , "get_current_catalog" , return_value = "test_catalog"
657+ )
658+ # create long struct columns datatype
659+ long_struct_cols = [f"a_{ i } :int" for i in range (50 )]
660+ adapter .cursor .fetchall .return_value = [
661+ ("bigint_col" , "bigint" ),
662+ ("binary_col" , "binary" ),
663+ ("boolean_col" , "boolean" ),
664+ ("date_col" , "date" ),
665+ ("decimal_col" , "decimal(38,4)" ),
666+ ("double_col" , "double" ),
667+ ("float_col" , "float" ),
668+ ("int_col" , "int" ),
669+ ("small_int" , "smallint" ),
670+ ("string_col" , "string" ),
671+ ("timestamp_col" , "timestamp" ),
672+ ("timestamp_ntz_col" , "timestamp_ntz" ),
673+ ("tinyint_col" , "tinyint" ),
674+ ("array_col" , "array<int>" ),
675+ ("simple_struct_col" , "struct<a:int,b:string>" ),
676+ ("long_struct_col" , f"struct<{ ',' .join (long_struct_cols )} >" ),
677+ ]
678+
679+ resp = adapter .columns ("test_db.test_table" )
680+ assert resp == {
681+ "bigint_col" : exp .DataType .build ("bigint" , dialect = adapter .dialect ),
682+ "binary_col" : exp .DataType .build ("binary" , dialect = adapter .dialect ),
683+ "boolean_col" : exp .DataType .build ("boolean" , dialect = adapter .dialect ),
684+ "date_col" : exp .DataType .build ("date" , dialect = adapter .dialect ),
685+ "decimal_col" : exp .DataType .build ("decimal(38,4)" , dialect = adapter .dialect ),
686+ "double_col" : exp .DataType .build ("double" , dialect = adapter .dialect ),
687+ "float_col" : exp .DataType .build ("float" , dialect = adapter .dialect ),
688+ "int_col" : exp .DataType .build ("int" , dialect = adapter .dialect ),
689+ "small_int" : exp .DataType .build ("smallint" , dialect = adapter .dialect ),
690+ "string_col" : exp .DataType .build ("string" , dialect = adapter .dialect ),
691+ "timestamp_col" : exp .DataType .build ("timestamp" , dialect = adapter .dialect ),
692+ "timestamp_ntz_col" : exp .DataType .build ("timestamp_ntz" , dialect = adapter .dialect ),
693+ "tinyint_col" : exp .DataType .build ("tinyint" , dialect = adapter .dialect ),
694+ "array_col" : exp .DataType .build ("array<int>" , dialect = adapter .dialect ),
695+ "simple_struct_col" : exp .DataType .build ("struct<a:int,b:string>" , dialect = adapter .dialect ),
696+ "long_struct_col" : exp .DataType .build (
697+ f"struct<{ ',' .join (long_struct_cols )} >" , dialect = adapter .dialect
698+ ),
699+ }
700+
701+ adapter .cursor .fetchall .assert_called_once_with (
702+ parse_one (
703+ """SELECT columns.column_name, columns.full_data_type FROM system.information_schema.columns WHERE table_name = 'test_table' AND table_schema = 'test_db' AND table_catalog = 'test_catalog' ORDER BY ordinal_position ASC""" ,
704+ dialect = "databricks" ,
705+ )
706+ )
0 commit comments