File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,17 @@ def __init__(
8686 def band_rename_function (self , band_name : str ):
8787 return band_name
8888
89+ def add_clustering (self , fqn : str ):
90+ """Add clustering by BLOCK column for query optimization."""
91+ fqn = fqn .upper ()
92+ try :
93+ cluster_query = f"ALTER TABLE { fqn } CLUSTER BY (BLOCK)"
94+ self .execute (cluster_query )
95+ except Exception :
96+ # Clustering might fail if table already has clustering,
97+ # so we silently ignore errors
98+ pass
99+
89100 def write_metadata (
90101 self ,
91102 metadata ,
@@ -310,6 +321,11 @@ def band_rename_function(x):
310321
311322 self .write_metadata (metadata , append_records , fqn )
312323
324+ # Add clustering on new tables for query optimization
325+ if not append_records :
326+ print ("Adding clustering by BLOCK column..." )
327+ self .add_clustering (fqn )
328+
313329 except IncompatibleRasterException as e :
314330 raise IOError ("Error uploading to Snowflake: {}" .format (e .message ))
315331
You can’t perform that action at this time.
0 commit comments