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

Resample Query Join and Aggregation Updates #857

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
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 @@ -139,7 +139,7 @@ def _sql_query(parameters_dict: dict) -> str:

def _sample_query(parameters_dict: dict) -> tuple:
sample_query = (
'WITH raw_events AS (SELECT DISTINCT from_utc_timestamp(date_trunc("millisecond",`{{ timestamp_column }}`), "{{ time_zone }}") AS `{{ timestamp_column }}`, `{{ tagname_column }}`, {% if include_status is defined and include_status == true %} `{{ status_column }}`, {% else %} \'Good\' AS `Status`, {% endif %} `{{ value_column }}` FROM '
"WITH raw_events AS (SELECT DISTINCT from_utc_timestamp(date_trunc(\"millisecond\",`{{ timestamp_column }}`), \"{{ time_zone }}\") AS `{{ timestamp_column }}`, `{{ tagname_column }}`, {% if include_status is defined and include_status == true %} `{{ status_column }}`, {% else %} 'Good' AS `Status`, {% endif %} `{{ value_column }}`, window(`{{ timestamp_column }}`, '{{ time_interval_rate + ' ' + time_interval_unit }}') FROM "
"{% if source is defined and source is not none %}"
"`{{ source|lower }}` "
"{% else %}"
Expand All @@ -152,9 +152,8 @@ def _sample_query(parameters_dict: dict) -> tuple:
"{% endif %}"
"{% if include_status is defined and include_status == true and include_bad_data is defined and include_bad_data == false %} AND `{{ status_column }}` <> 'Bad' {% endif %}) "
',date_array AS (SELECT explode(sequence(from_utc_timestamp(to_timestamp("{{ start_date }}"), "{{ time_zone }}"), from_utc_timestamp(to_timestamp("{{ end_date }}"), "{{ time_zone }}"), INTERVAL \'{{ time_interval_rate + \' \' + time_interval_unit }}\')) AS timestamp_array) '
",window_buckets AS (SELECT timestamp_array AS window_start, timestampadd({{ time_interval_unit }}, {{ time_interval_rate }}, timestamp_array) AS window_end FROM date_array) "
",resample AS (SELECT /*+ RANGE_JOIN(d, {{ range_join_seconds }} ) */ d.window_start, d.window_end, e.`{{ tagname_column }}`, {{ agg_method }}(e.`{{ value_column }}`) OVER (PARTITION BY e.`{{ tagname_column }}`, d.window_start ORDER BY e.`{{ timestamp_column }}` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `{{ value_column }}` FROM window_buckets d INNER JOIN raw_events e ON d.window_start <= e.`{{ timestamp_column }}` AND d.window_end > e.`{{ timestamp_column }}`) "
",project AS (SELECT window_start AS `{{ timestamp_column }}`, `{{ tagname_column }}`, `{{ value_column }}` FROM resample GROUP BY window_start, `{{ tagname_column }}`, `{{ value_column }}` "
",window_buckets AS (SELECT timestamp_array AS window_start, window(timestamp_array, '{{ time_interval_rate + ' ' + time_interval_unit }}') FROM date_array) "
",project AS (SELECT d.window_start AS `{{ timestamp_column }}`, e.`{{ tagname_column }}`, {{ agg_method }}(e.`{{ value_column }}`) AS `{{ value_column }}` FROM window_buckets d INNER JOIN raw_events e ON d.window.start = e.window.start AND d.window.end = e.window.end) GROUP BY d.window_start, e.`{{ tagname_column }}` "
"{% if is_resample is defined and is_resample == true %}"
"ORDER BY `{{ tagname_column }}`, `{{ timestamp_column }}` "
"{% endif %}"
Expand Down
Loading
Loading