@@ -276,7 +276,9 @@ def list_relations_without_caching(
276276 raise
277277
278278 columns = ["database_name" , "schema_name" , "name" , "kind" , "is_dynamic" , "is_iceberg" ]
279-
279+ schema_objects = schema_objects .rename (
280+ column_names = [col .lower () for col in schema_objects .column_names ]
281+ )
280282 return [self ._parse_list_relations_result (obj ) for obj in schema_objects .select (columns )]
281283
282284 def _parse_list_relations_result (self , result : "agate.Row" ) -> SnowflakeRelation :
@@ -482,58 +484,34 @@ def build_catalog_relation(self, model: RelationConfig) -> Optional[CatalogRelat
482484 return None
483485
484486 @available
485- def describe_dynamic_table (self , relation : RelationConfig ) -> Dict [str , Any ]:
487+ def describe_dynamic_table (self , relation : SnowflakeRelation ) -> Dict [str , Any ]:
486488 """
487489 Get all relevant metadata about a dynamic table to return as a dict to Agate Table row
488490
489491 Args:
490492 relation (SnowflakeRelation): the relation to describe
491493 """
492-
493- original_val : Optional [ str ] = None
494- try :
495- # Store old QUOTED_IDENTIFIERS_IGNORE_CASE
496- show_param_sql = "show parameters like 'QUOTED_IDENTIFIERS_IGNORE_CASE ' in SESSION "
497- show_param_res = self . execute ( show_param_sql )
498- if show_param_res :
499- param_qid = show_param_res [ 0 ]. query_id
500- scan_param_sql = f"SELECT * FROM TABLE(RESULT_SCAN(' { param_qid } '))"
501- param_scan_res , rows = self . execute ( scan_param_sql , fetch = True )
502- if param_scan_res and param_scan_res . code == "SUCCESS" :
503- try :
504- original_val = rows [ 0 ][ 1 ]
505- except ( IndexError , TypeError ):
506- original_val = None
507-
508- # falsify QUOTED_IDENTIFIERS_IGNORE_CASE for execution only
509- self . execute ( "alter session set QUOTED_IDENTIFIERS_IGNORE_CASE = FALSE" , fetch = False )
510-
511- show_sql = (
512- f"show dynamic tables like ' { relation . identifier } ' "
513- f"in schema { relation . database } . { relation . schema } "
494+ quoting = relation . quote_policy
495+ schema = f'" { relation . schema } "' if quoting . schema else relation . schema
496+ database = f'" { relation . database } "' if quoting . database else relation . database
497+ show_sql = (
498+ f "show dynamic tables like '{ relation . identifier } ' in schema { database } . { schema } "
499+ )
500+ res , dt_table = self . execute ( show_sql , fetch = True )
501+ if res . code != "SUCCESS" :
502+ raise DbtRuntimeError ( f"Could not get dynamic query metadata: { show_sql } failed" )
503+ # normalize column names to lower case, this still preserves column order
504+ dt_table = dt_table . rename ( column_names = [ name . lower () for name in dt_table . column_names ])
505+ return {
506+ "dynamic_table" : dt_table . select (
507+ [
508+ "name" ,
509+ "schema_name" ,
510+ "database_name" ,
511+ "text" ,
512+ "target_lag" ,
513+ "warehouse" ,
514+ "refresh_mode" ,
515+ ]
514516 )
515- show_res = self .execute (show_sql )
516- if show_res :
517- query_id = show_res [0 ].query_id
518- scan_sql = (
519- "select "
520- ' "name", "schema_name", "database_name", "text", "target_lag", "warehouse", '
521- ' "refresh_mode" '
522- f"from TABLE(RESULT_SCAN('{ query_id } '))"
523- )
524- res , dt_table = self .execute (scan_sql , fetch = True )
525- if res .code != "SUCCESS" :
526- raise DbtRuntimeError (
527- f"Could not get dynamic query metadata: { scan_sql } failed"
528- )
529- return {"dynamic_table" : dt_table }
530-
531- return {"dynamic_table" : None }
532- finally :
533- if original_val is None :
534- self .execute ("ALTER SESSION UNSET QUOTED_IDENTIFIERS_IGNORE_CASE" , fetch = False )
535- else :
536- bool_str = "TRUE" if original_val .strip ().lower () == "true" else "FALSE"
537- self .execute (
538- f"ALTER SESSION SET QUOTED_IDENTIFIERS_IGNORE_CASE = { bool_str } " , fetch = False
539- )
517+ }
0 commit comments