@@ -1470,8 +1470,14 @@ def columns(
14701470 }
14711471
14721472 def table_exists (self , table_name : TableName ) -> bool :
1473+ table = exp .to_table (table_name )
1474+ data_object_cache_key = _get_data_object_cache_key (table .catalog , table .db , table .name )
1475+ if data_object_cache_key in self ._data_object_cache :
1476+ logger .debug ("Table existence cache hit: %s" , data_object_cache_key )
1477+ return self ._data_object_cache [data_object_cache_key ] is not None
1478+
14731479 try :
1474- self .execute (exp .Describe (this = exp . to_table ( table_name ) , kind = "TABLE" ))
1480+ self .execute (exp .Describe (this = table , kind = "TABLE" ))
14751481 return True
14761482 except Exception :
14771483 return False
@@ -2301,11 +2307,13 @@ def get_data_objects(
23012307 target_schema .catalog , target_schema .db , name
23022308 )
23032309 if cache_key in self ._data_object_cache :
2310+ logger .debug ("Data object cache hit: %s" , cache_key )
23042311 data_object = self ._data_object_cache [cache_key ]
23052312 # If the object is none, then the table was previously looked for but not found
23062313 if data_object :
23072314 cached_objects .append (data_object )
23082315 else :
2316+ logger .debug ("Data object cache miss: %s" , cache_key )
23092317 missing_names .add (name )
23102318
23112319 # Fetch missing objects from database
@@ -2321,7 +2329,6 @@ def get_data_objects(
23212329 for obj in self ._get_data_objects (schema_name , set (batch ))
23222330 ]
23232331
2324- # Cache the fetched objects
23252332 for obj in fetched_objects :
23262333 cache_key = _get_data_object_cache_key (obj .catalog , obj .schema_name , obj .name )
23272334 self ._data_object_cache [cache_key ] = obj
@@ -2336,7 +2343,12 @@ def get_data_objects(
23362343 return cached_objects + fetched_objects
23372344
23382345 return cached_objects
2339- return self ._get_data_objects (schema_name )
2346+
2347+ fetched_objects = self ._get_data_objects (schema_name )
2348+ for obj in fetched_objects :
2349+ cache_key = _get_data_object_cache_key (obj .catalog , obj .schema_name , obj .name )
2350+ self ._data_object_cache [cache_key ] = obj
2351+ return fetched_objects
23402352
23412353 def fetchone (
23422354 self ,
@@ -2746,10 +2758,12 @@ def _to_sql(self, expression: exp.Expression, quote: bool = True, **kwargs: t.An
27462758 def _clear_data_object_cache (self , table_name : t .Optional [TableName ] = None ) -> None :
27472759 """Clears the cache entry for the given table name, or clears the entire cache if table_name is None."""
27482760 if table_name is None :
2761+ logger .debug ("Clearing entire data object cache" )
27492762 self ._data_object_cache .clear ()
27502763 else :
27512764 table = exp .to_table (table_name )
27522765 cache_key = _get_data_object_cache_key (table .catalog , table .db , table .name )
2766+ logger .debug ("Clearing data object cache key: %s" , cache_key )
27532767 self ._data_object_cache .pop (cache_key , None )
27542768
27552769 def _get_data_objects (
@@ -3003,7 +3017,5 @@ def _decoded_str(value: t.Union[str, bytes]) -> str:
30033017
30043018def _get_data_object_cache_key (catalog : t .Optional [str ], schema_name : str , object_name : str ) -> str :
30053019 """Returns a cache key for a data object based on its fully qualified name."""
3006- catalog_part = catalog .lower () if catalog else ""
3007- schema_part = schema_name .lower ()
3008- object_part = object_name .lower ()
3009- return f"{ catalog_part } .{ schema_part } .{ object_part } "
3020+ catalog = catalog or ""
3021+ return f"{ catalog } .{ schema_name } .{ object_name } "
0 commit comments