11from databricks .sql .backend .sea .utils .result_column import ResultColumn
2+ from databricks .sql .backend .sea .utils .metadata_transformations import (
3+ transform_table_type ,
4+ transform_is_nullable ,
5+ transform_nullable_to_int ,
6+ transform_remarks_default ,
7+ transform_numeric_default_zero ,
8+ transform_ordinal_position_offset ,
9+ calculate_data_type ,
10+ calculate_buffer_length ,
11+ always_null ,
12+ always_null_int ,
13+ always_null_smallint ,
14+ identity
15+ )
216
317
418class MetadataColumnMappings :
519 """Column mappings for metadata queries following JDBC specification."""
620
721 # Common columns used across multiple metadata queries
8- CATALOG_COLUMN = ResultColumn ("TABLE_CAT" , "catalog" , "string" )
9- CATALOG_COLUMN_FOR_TABLES = ResultColumn ("TABLE_CAT" , "catalogName" , "string" )
10- SCHEMA_COLUMN = ResultColumn ("TABLE_SCHEM" , "namespace" , "string" )
11- SCHEMA_COLUMN_FOR_GET_SCHEMA = ResultColumn ("TABLE_SCHEM" , "databaseName" , "string" )
12- TABLE_NAME_COLUMN = ResultColumn ("TABLE_NAME" , "tableName" , "string" )
13- TABLE_TYPE_COLUMN = ResultColumn ("TABLE_TYPE" , "tableType" , "string" )
14- REMARKS_COLUMN = ResultColumn ("REMARKS" , "remarks" , "string" )
22+ # FIX 1: Catalog columns - swap the mappings
23+ CATALOG_COLUMN = ResultColumn ("TABLE_CAT" , "catalogName" , "string" , transform_value = identity )
24+ CATALOG_COLUMN_FOR_GET_CATALOGS = ResultColumn ("TABLE_CAT" , "catalog" , "string" , transform_value = identity )
25+ # Remove CATALOG_COLUMN_FOR_TABLES - will use CATALOG_COLUMN instead
26+
27+ SCHEMA_COLUMN = ResultColumn ("TABLE_SCHEM" , "namespace" , "string" , transform_value = identity )
28+ SCHEMA_COLUMN_FOR_GET_SCHEMA = ResultColumn ("TABLE_SCHEM" , "databaseName" , "string" , transform_value = identity )
29+ TABLE_NAME_COLUMN = ResultColumn ("TABLE_NAME" , "tableName" , "string" , transform_value = identity )
30+ TABLE_TYPE_COLUMN = ResultColumn ("TABLE_TYPE" , "tableType" , "string" , transform_value = transform_table_type )
31+ REMARKS_COLUMN = ResultColumn ("REMARKS" , "remarks" , "string" , transform_value = transform_remarks_default )
1532
1633 # Columns specific to getColumns()
17- COLUMN_NAME_COLUMN = ResultColumn ("COLUMN_NAME" , "col_name" , "string" )
34+ COLUMN_NAME_COLUMN = ResultColumn ("COLUMN_NAME" , "col_name" , "string" , transform_value = identity )
1835 DATA_TYPE_COLUMN = ResultColumn (
19- "DATA_TYPE" , None , "int"
20- ) # SEA doesn't provide this
21- TYPE_NAME_COLUMN = ResultColumn ("TYPE_NAME" , "columnType" , "string" )
22- COLUMN_SIZE_COLUMN = ResultColumn ("COLUMN_SIZE" , None , "int" )
23- DECIMAL_DIGITS_COLUMN = ResultColumn ("DECIMAL_DIGITS" , None , "int" )
24- NUM_PREC_RADIX_COLUMN = ResultColumn ("NUM_PREC_RADIX" , None , "int" )
25- NULLABLE_COLUMN = ResultColumn ("NULLABLE" , None , "int" )
36+ "DATA_TYPE" , None , "int" , transform_value = calculate_data_type
37+ ) # Calculated from columnType
38+ TYPE_NAME_COLUMN = ResultColumn ("TYPE_NAME" , "columnType" , "string" , transform_value = identity )
39+
40+ # FIX 5: SEA actually provides these columns
41+ COLUMN_SIZE_COLUMN = ResultColumn ("COLUMN_SIZE" , "columnSize" , "int" , transform_value = identity )
42+ DECIMAL_DIGITS_COLUMN = ResultColumn ("DECIMAL_DIGITS" , "decimalDigits" , "int" , transform_value = transform_numeric_default_zero )
43+ NUM_PREC_RADIX_COLUMN = ResultColumn ("NUM_PREC_RADIX" , "radix" , "int" , transform_value = transform_numeric_default_zero )
44+ ORDINAL_POSITION_COLUMN = ResultColumn ("ORDINAL_POSITION" , "ordinalPosition" , "int" , transform_value = transform_ordinal_position_offset )
45+
46+ NULLABLE_COLUMN = ResultColumn ("NULLABLE" , None , "int" , transform_value = transform_nullable_to_int ) # Calculated from isNullable
2647 COLUMN_DEF_COLUMN = ResultColumn (
27- "COLUMN_DEF" , "columnType" , "string"
48+ "COLUMN_DEF" , "columnType" , "string" , transform_value = identity
2849 ) # Note: duplicate mapping
29- SQL_DATA_TYPE_COLUMN = ResultColumn ("SQL_DATA_TYPE" , None , "int" )
30- SQL_DATETIME_SUB_COLUMN = ResultColumn ("SQL_DATETIME_SUB" , None , "int" )
31- CHAR_OCTET_LENGTH_COLUMN = ResultColumn ("CHAR_OCTET_LENGTH" , None , "int" )
32- ORDINAL_POSITION_COLUMN = ResultColumn ("ORDINAL_POSITION" , None , "int" )
33- IS_NULLABLE_COLUMN = ResultColumn ("IS_NULLABLE" , "isNullable" , "string" )
50+ SQL_DATA_TYPE_COLUMN = ResultColumn ("SQL_DATA_TYPE" , None , "int" , transform_value = always_null_int )
51+ SQL_DATETIME_SUB_COLUMN = ResultColumn ("SQL_DATETIME_SUB" , None , "int" , transform_value = always_null_int )
52+ CHAR_OCTET_LENGTH_COLUMN = ResultColumn ("CHAR_OCTET_LENGTH" , None , "int" , transform_value = always_null_int )
53+ IS_NULLABLE_COLUMN = ResultColumn ("IS_NULLABLE" , "isNullable" , "string" , transform_value = transform_is_nullable )
3454
3555 # Columns for getTables() that don't exist in SEA
36- TYPE_CAT_COLUMN = ResultColumn ("TYPE_CAT" , None , "string" )
37- TYPE_SCHEM_COLUMN = ResultColumn ("TYPE_SCHEM" , None , "string" )
38- TYPE_NAME_COLUMN = ResultColumn ("TYPE_NAME" , None , "string" )
56+ TYPE_CAT_COLUMN = ResultColumn ("TYPE_CAT" , None , "string" , transform_value = always_null )
57+ TYPE_SCHEM_COLUMN = ResultColumn ("TYPE_SCHEM" , None , "string" , transform_value = always_null )
58+ TYPE_NAME_COLUMN = ResultColumn ("TYPE_NAME" , None , "string" , transform_value = always_null )
3959 SELF_REFERENCING_COL_NAME_COLUMN = ResultColumn (
40- "SELF_REFERENCING_COL_NAME" , None , "string"
60+ "SELF_REFERENCING_COL_NAME" , None , "string" , transform_value = always_null
4161 )
42- REF_GENERATION_COLUMN = ResultColumn ("REF_GENERATION" , None , "string" )
62+ REF_GENERATION_COLUMN = ResultColumn ("REF_GENERATION" , None , "string" , transform_value = always_null )
63+
64+ # FIX 8: Scope columns (always null per JDBC)
65+ SCOPE_CATALOG_COLUMN = ResultColumn ("SCOPE_CATALOG" , None , "string" , transform_value = always_null )
66+ SCOPE_SCHEMA_COLUMN = ResultColumn ("SCOPE_SCHEMA" , None , "string" , transform_value = always_null )
67+ SCOPE_TABLE_COLUMN = ResultColumn ("SCOPE_TABLE" , None , "string" , transform_value = always_null )
68+ SOURCE_DATA_TYPE_COLUMN = ResultColumn ("SOURCE_DATA_TYPE" , None , "smallint" , transform_value = always_null_smallint )
69+
70+ # FIX 9 & 10: Auto increment and generated columns
71+ IS_AUTO_INCREMENT_COLUMN = ResultColumn ("IS_AUTOINCREMENT" , "isAutoIncrement" , "string" , transform_value = identity ) # No underscore!
72+ IS_GENERATED_COLUMN = ResultColumn ("IS_GENERATEDCOLUMN" , "isGenerated" , "string" , transform_value = identity ) # SEA provides this
73+
74+ # FIX 11: Buffer length column
75+ BUFFER_LENGTH_COLUMN = ResultColumn ("BUFFER_LENGTH" , None , "int" , transform_value = always_null_int ) # Always null per JDBC
4376
4477 # Column lists for each metadata operation
45- CATALOG_COLUMNS = [CATALOG_COLUMN ]
78+ CATALOG_COLUMNS = [CATALOG_COLUMN_FOR_GET_CATALOGS ] # Use specific catalog column
4679
4780 SCHEMA_COLUMNS = [
4881 SCHEMA_COLUMN_FOR_GET_SCHEMA ,
49- ResultColumn ("TABLE_CATALOG" , None , "string" ), # SEA doesn't return this
82+ ResultColumn ("TABLE_CATALOG" , None , "string" , transform_value = always_null ), # Will need special population logic
5083 ]
5184
5285 TABLE_COLUMNS = [
53- CATALOG_COLUMN_FOR_TABLES ,
86+ CATALOG_COLUMN , # Use general catalog column (catalogName)
5487 SCHEMA_COLUMN ,
5588 TABLE_NAME_COLUMN ,
5689 TABLE_TYPE_COLUMN ,
@@ -62,15 +95,16 @@ class MetadataColumnMappings:
6295 REF_GENERATION_COLUMN ,
6396 ]
6497
98+ # FIX 13: Remove IS_GENERATEDCOLUMN from list (should be 23 columns, not 24)
6599 COLUMN_COLUMNS = [
66- CATALOG_COLUMN_FOR_TABLES ,
100+ CATALOG_COLUMN , # Use general catalog column (catalogName)
67101 SCHEMA_COLUMN ,
68102 TABLE_NAME_COLUMN ,
69103 COLUMN_NAME_COLUMN ,
70104 DATA_TYPE_COLUMN ,
71105 TYPE_NAME_COLUMN ,
72106 COLUMN_SIZE_COLUMN ,
73- ResultColumn ( "BUFFER_LENGTH" , None , "int" ) ,
107+ BUFFER_LENGTH_COLUMN ,
74108 DECIMAL_DIGITS_COLUMN ,
75109 NUM_PREC_RADIX_COLUMN ,
76110 NULLABLE_COLUMN ,
@@ -81,10 +115,10 @@ class MetadataColumnMappings:
81115 CHAR_OCTET_LENGTH_COLUMN ,
82116 ORDINAL_POSITION_COLUMN ,
83117 IS_NULLABLE_COLUMN ,
84- ResultColumn ( "SCOPE_CATALOG" , None , "string" ) ,
85- ResultColumn ( "SCOPE_SCHEMA" , None , "string" ) ,
86- ResultColumn ( "SCOPE_TABLE" , None , "string" ) ,
87- ResultColumn ( "SOURCE_DATA_TYPE" , None , "smallint" ) ,
88- ResultColumn ( "IS_AUTO_INCREMENT" , None , "string" ) ,
89- ResultColumn ( "IS_GENERATEDCOLUMN" , None , "string" ),
118+ SCOPE_CATALOG_COLUMN ,
119+ SCOPE_SCHEMA_COLUMN ,
120+ SCOPE_TABLE_COLUMN ,
121+ SOURCE_DATA_TYPE_COLUMN ,
122+ IS_AUTO_INCREMENT_COLUMN ,
123+ # DO NOT INCLUDE IS_GENERATED_COLUMN - Thrift returns 23 columns
90124 ]
0 commit comments