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

ELE-3465: Sync elementary schema dump batching rows limit #752

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 24 additions & 16 deletions macros/commands/dump_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,33 @@

{% set dedup_by_column = node.meta.dedup_by_column or "unique_id" %}
{% set order_by_dedup_column = "generated_at" %}
{% set query %}
{% if dedup and (dedup_by_column in column_names) and (order_by_dedup_column in column_names) %}
{{ elementary.dedup_by_column_query(dedup_by_column, order_by_dedup_column, column_names, relation) }}
{% else %}
select {{ elementary.escape_select(column_names) }} from {{ relation }}
{% endif %}
{% if timestamp_column %}
{% if since %}
where {{ elementary.edr_cast_as_timestamp(timestamp_column) }} > {{ elementary.edr_cast_as_timestamp(elementary.edr_quote(since)) }}
{% if until %}
and {{ elementary.edr_cast_as_timestamp(timestamp_column) }} <= {{ elementary.edr_cast_as_timestamp(elementary.edr_quote(until)) }}
{% endif %}
{% set batch_size = 200000 %}
{% for item in range(50) %}
{% set query %}
{% if dedup and (dedup_by_column in column_names) and (order_by_dedup_column in column_names) %}
{{ elementary.dedup_by_column_query(dedup_by_column, order_by_dedup_column, column_names, relation) }}
{% else %}
where {{ elementary.edr_datediff(elementary.edr_cast_as_timestamp(timestamp_column), elementary.edr_current_timestamp(), 'day') }} < {{ days_back }}
select {{ elementary.escape_select(column_names) }} from {{ relation }}
{% endif %}
{% if timestamp_column %}
{% if since %}
where {{ elementary.edr_cast_as_timestamp(timestamp_column) }} > {{ elementary.edr_cast_as_timestamp(elementary.edr_quote(since)) }}
{% if until %}
and {{ elementary.edr_cast_as_timestamp(timestamp_column) }} <= {{ elementary.edr_cast_as_timestamp(elementary.edr_quote(until)) }}
{% endif %}
{% else %}
where {{ elementary.edr_datediff(elementary.edr_cast_as_timestamp(timestamp_column), elementary.edr_current_timestamp(), 'day') }} < {{ days_back }}
{% endif %}
{% endif %}
limit {{ batch_size }}
offset {{ batch_size * item }}
{% endset %}
{% set results = elementary.run_query(query) %}
{% do results.to_csv(output_path.split(".")[:-1] | join(".") ~ "_" ~ item ~ "." ~ output_path.split(".")[-1]) %}
{% if (results | length) < batch_size %}
{% break %}
{% endif %}
{% endset %}
{% set results = elementary.run_query(query) %}
{% do results.to_csv(output_path) %}
{% endfor %}
{% do return(results.column_names) %}
{% endmacro %}

Expand Down
Loading