@@ -1000,6 +1000,75 @@ def test_column_descriptions(sushi_context, assert_exp_eq):
10001000 assert model .column_descriptions == {"id" : "primary key" , "foo" : "bar" }
10011001
10021002
1003+ def test_column_descriptions_quoted_identifier ():
1004+ expressions = d .parse (
1005+ """
1006+ MODEL (
1007+ name db.table,
1008+ kind FULL,
1009+ dialect snowflake,
1010+ column_descriptions (
1011+ "myColumn" = 'a case-sensitive column',
1012+ other_column = 'an unquoted column'
1013+ )
1014+ );
1015+
1016+ SELECT 1 AS "myColumn", 2 AS other_column
1017+ """
1018+ )
1019+ model = load_sql_based_model (expressions , dialect = "snowflake" )
1020+
1021+ # A quoted key keeps its case, an unquoted one is still normalized.
1022+ assert model .column_descriptions == {
1023+ "myColumn" : "a case-sensitive column" ,
1024+ "OTHER_COLUMN" : "an unquoted column" ,
1025+ }
1026+ assert set (model .column_descriptions ) <= set (model .columns_to_types )
1027+
1028+
1029+ def test_column_descriptions_dotted_identifier ():
1030+ # A nested field is looked up by its dotted path, so every part normalizes on its own.
1031+ expressions = d .parse (
1032+ """
1033+ MODEL (
1034+ name db.table,
1035+ kind FULL,
1036+ dialect bigquery,
1037+ column_descriptions (
1038+ record.`myField` = 'a nested field'
1039+ )
1040+ );
1041+
1042+ SELECT STRUCT(1 AS `myField`) AS record
1043+ """
1044+ )
1045+ model = load_sql_based_model (expressions , dialect = "bigquery" )
1046+
1047+ assert model .column_descriptions == {"record.myfield" : "a nested field" }
1048+
1049+ expressions = d .parse (
1050+ """
1051+ MODEL (
1052+ name db.table,
1053+ kind FULL,
1054+ dialect snowflake,
1055+ column_descriptions (
1056+ nested.field = 'an unquoted path',
1057+ "MyStruct"."myField" = 'a quoted path'
1058+ )
1059+ );
1060+
1061+ SELECT 1 AS c
1062+ """
1063+ )
1064+ model = load_sql_based_model (expressions , dialect = "snowflake" )
1065+
1066+ assert model .column_descriptions == {
1067+ "NESTED.FIELD" : "an unquoted path" ,
1068+ "MyStruct.myField" : "a quoted path" ,
1069+ }
1070+
1071+
10031072def test_model_jinja_macro_reference_extraction ():
10041073 @macro ()
10051074 def test_macro (** kwargs ) -> None :
0 commit comments