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

enhance existed macros to support more range of databases #123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion macros/store/insert_list_to_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
{%- if row[p] is none -%}
NULL
{%- else -%}
{%- if row[p] is string -%}
{%- if row[p] is boolean -%}
cast ({{-row[p]}} as {{ boolean_type()-}})
{%- elif row[p] is string -%}
{%- if dtype and p in dtype -%}
{% set cast_type = dtype[p] %}
cast ({{ re_data.quote_string(row[p]) }} as {{ cast_type }})
Expand Down
6 changes: 3 additions & 3 deletions macros/utils/bool_to_string.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

{% macro bool_to_string(column) %}
(
case when {{ column }} = true then 'true'
when {{ column }} = false then 'false'
case when cast({{ column }} as boolean) = true then 'true'
when cast({{ column }} as boolean) = false then 'false'
end
) as {{ column }}
{% endmacro %}
{% endmacro %}
2 changes: 1 addition & 1 deletion models/alerts/re_data_z_score.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ with z_score_without_id as (
stats.last_third_quartile - stats.last_first_quartile as last_iqr,
stats.last_first_quartile,
stats.last_third_quartile,
{{ time_window_end() }} as time_window_end,
cast( {{ time_window_end() }} as {{ timestamp_type() }}) as time_window_end,
cast( {{dbt.current_timestamp_backcompat()}} as {{ timestamp_type() }} ) as computed_on
from
{{ ref('re_data_last_stats') }} as stats,
Expand Down
2 changes: 1 addition & 1 deletion models/meta/re_data_selected.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ select
name, schema, database, time_filter, metrics, columns, anomaly_detector, owners
from {{ ref('re_data_monitored')}}
where
selected = true
cast(selected as boolean) = true
2 changes: 1 addition & 1 deletion models/metrics/for_anomalies/re_data_last_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ select
from
{{ ref('re_data_base_metrics') }}
where
time_window_end = {{- time_window_end() -}}
cast(time_window_end as timestamp) = {{- time_window_end() -}}

12 changes: 6 additions & 6 deletions models/metrics/for_anomalies/re_data_last_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ with median_value as (
from
{{ ref('re_data_base_metrics') }}
where
time_window_end > {{- anamaly_detection_time_window_start() -}} and
time_window_end <= {{- time_window_end() -}}
cast(time_window_end as timestamp) > {{- anamaly_detection_time_window_start() -}} and
cast(time_window_end as timestamp) <= {{- time_window_end() -}}
{% if target.type in postgres_type_db() %}
group by
{{ columns_to_group_by }}
Expand All @@ -38,8 +38,8 @@ with median_value as (
s.metric = mv.metric and
s.interval_length_sec = mv.interval_length_sec
where
s.time_window_end > {{- anamaly_detection_time_window_start() -}} and
s.time_window_end <= {{- time_window_end() -}}
cast(s.time_window_end as timestamp) > {{- anamaly_detection_time_window_start() -}} and
cast(s.time_window_end as timestamp) <= {{- time_window_end() -}}
), median_abs_deviation as (
select distinct
table_name,
Expand All @@ -66,8 +66,8 @@ with median_value as (
from
{{ ref('re_data_base_metrics') }}
where
time_window_end > {{- anamaly_detection_time_window_start() -}} and
time_window_end <= {{- time_window_end() -}}
cast(time_window_end as timestamp) > {{- anamaly_detection_time_window_start() -}} and
cast(time_window_end as timestamp) <= {{- time_window_end() -}}
group by
{{ columns_to_group_by }}
)
Expand Down