Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions raster_loader/io/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def __init__(
def band_rename_function(self, band_name: str):
return band_name

def add_clustering(self, fqn: str):
"""Add clustering by BLOCK column for query optimization."""
fqn = fqn.upper()
try:
cluster_query = f"ALTER TABLE {fqn} CLUSTER BY (BLOCK)"
self.execute(cluster_query)
except Exception:
# Clustering might fail if table already has clustering,
# so we silently ignore errors
pass

def write_metadata(
self,
metadata,
Expand Down Expand Up @@ -310,6 +321,11 @@ def band_rename_function(x):

self.write_metadata(metadata, append_records, fqn)

# Add clustering on new tables for query optimization
if not append_records:
print("Adding clustering by BLOCK column...")
self.add_clustering(fqn)

except IncompatibleRasterException as e:
raise IOError("Error uploading to Snowflake: {}".format(e.message))

Expand Down