Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ingest/snowflake): use system sampling on very large tables #10430

Merged
merged 1 commit into from
May 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ def get_batch_kwargs(
# We are using fraction-based sampling here, instead of fixed-size sampling because
# Fixed-size sampling can be slower than equivalent fraction-based sampling
# as per https://docs.snowflake.com/en/sql-reference/constructs/sample#performance-considerations

sample_method = "BERNOULLI"
if table.rows_count > self.config.profiling.sample_size * 1000:
# If the table is significantly larger than the sample size, we use BLOCK
# sampling for better performance.
sample_method = "BLOCK"

sample_pc = 100 * self.config.profiling.sample_size / table.rows_count
custom_sql = f'select * from "{db_name}"."{schema_name}"."{table.name}" TABLESAMPLE ({sample_pc:.8f})'
custom_sql = f'select * from "{db_name}"."{schema_name}"."{table.name}" TABLESAMPLE {sample_method} ({sample_pc:.8f})'
return {
**super().get_batch_kwargs(table, schema_name, db_name),
# Lowercase/Mixedcase table names in Snowflake do not work by default.
Expand Down
Loading