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

Adding ability to install re_data for Greenplum database #102

Merged
merged 2 commits into from
Oct 26, 2022
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
3 changes: 3 additions & 0 deletions macros/db/postgres/postgres_type_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro postgres_type_db() %}
{{ ('postgres', 'greenplum') }}
{% endmacro %}
8 changes: 4 additions & 4 deletions macros/utils/json/to_single_json.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% macro to_json_string_value_or_null(column) %}
(
case
when {{column}} is null then 'null'
when {{ column }} is null then 'null'
else '"' ||
regexp_replace(
replace(cast({{column}} as {{string_type()}}), '"', {{escape_seq_for_json('"') }}),
'\n', {{ quote_new_line() }} {% if target.type == 'postgres' %}, 'g' {% endif %}
replace(cast({{ column }} as {{ string_type() }}), '"', {{ escape_seq_for_json('"') }}),
'\n', {{ quote_new_line() }} {% if target.type in postgres_type_db() %}, 'g' {% endif %}
) || '"'
end
)
Expand All @@ -19,4 +19,4 @@
{%- if not loop.last %} || ',' || {%- endif %}
{%- endfor %}
|| '}'
{% endmacro %}
{% endmacro %}
8 changes: 4 additions & 4 deletions models/metrics/for_anomalies/re_data_last_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ with median_value as (
column_name,
metric,
interval_length_sec,
avg(value) {% if target.type != 'postgres' %} over(partition by {{ columns_to_group_by }}) {% endif %} as last_avg,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To not repeat and make it more extensible, I think macro with those 2 db would be nice. So that we could write something like this:

{% if target.type in postgres_type_db() %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, sounds reasonable. Do you have any recommendations where to place this macro?
For me macros/db/postgres is the best folder for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

avg(value) {% if target.type not in postgres_type_db() %} over(partition by {{ columns_to_group_by }}) {% endif %} as last_avg,
{{ percentile(percentile_field='value', partition_field=columns_to_group_by, percent='0.25') }} as last_first_quartile,
{{ percentile(percentile_field='value', partition_field=columns_to_group_by, percent='0.5') }} as last_median,
{{ percentile(percentile_field='value', partition_field=columns_to_group_by, percent='0.75') }} as last_third_quartile
Expand All @@ -15,7 +15,7 @@ with median_value as (
where
time_window_end > {{- anamaly_detection_time_window_start() -}} and
time_window_end <= {{- time_window_end() -}}
{% if target.type == 'postgres' %}
{% if target.type in postgres_type_db() %}
group by
{{ columns_to_group_by }}
{% endif %}
Expand Down Expand Up @@ -46,11 +46,11 @@ with median_value as (
column_name,
metric,
interval_length_sec,
avg(absolute_deviation_from_mean) {% if target.type != 'postgres' %} over(partition by {{ columns_to_group_by }}) {% endif %} as mean_absolute_deviation,
avg(absolute_deviation_from_mean) {% if target.type not in postgres_type_db() %} over(partition by {{ columns_to_group_by }}) {% endif %} as mean_absolute_deviation,
{{ percentile(percentile_field='absolute_deviation_from_median', partition_field=columns_to_group_by, percent='0.5') }} as median_absolute_deviation
from
abs_deviation
{% if target.type == 'postgres' %}
{% if target.type in postgres_type_db() %}
group by
{{ columns_to_group_by }}
{% endif %}
Expand Down