Skip to content

Commit

Permalink
Merge pull request #1411 from elementary-data/ele-2506-fix-alerts_v2-…
Browse files Browse the repository at this point in the history
…for-redshift

Fix alerts_v2 for redshift - handle columns exceeding limit
  • Loading branch information
IDoneShaveIt authored Feb 14, 2024
2 parents c9b0fc9 + d765877 commit b549e31
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
{% set unhandled_alerts = [] %}
{% for alert in all_alerts %}
{% if alert.get('alert_id') not in backward_already_handled_alert_ids %}
{% do elementary_cli.handle_exceeding_limit_alert_data(alert) %}
{% do unhandled_alerts.append(alert) %}
{% endif %}
{% endfor %}

{% do elementary.insert_rows(alerts_v2_relation, unhandled_alerts, on_query_exceed=populate_alerts_on_query_exceed) %}
{% do elementary.insert_rows(alerts_v2_relation, unhandled_alerts, on_query_exceed=elementary_cli.handle_exceeding_limit_alert_data) %}
{% endif %}
{% do return('') %}
{% endmacro %}
Expand Down Expand Up @@ -59,16 +60,21 @@
{% endmacro %}


{% macro populate_alerts_on_query_exceed(alert_row) %}
{% macro handle_exceeding_limit_alert_data(alert_row) %}
{% set row_max_size = elementary.get_config_var('query_max_size') %}
{% set column_max_size = elementary.get_column_size() %}

{# alert data contains data that could exceed the query size limit #}
{# We remove the problematic fields to insure the query is in the right size #}
{% set alert_data = alert_row['data'] %}
{% set alert_data_dict = fromjson(alert_data) %}
{% set risky_fields = ['test_rows_sample', 'test_results_query'] %}
{% for risky_field in risky_fields %}
{% if (tojson(alert_data_dict[risky_field]) | length) > (row_max_size / 3) %}
{% set field_length = tojson(alert_data_dict.get(risky_field, {})) | length %}
{% set exceeding_row_size = field_length > (row_max_size / 3) %}
{# For some DWH there is no column size limitation #}
{% set exceeding_column_size = column_max_size and field_length > (column_max_size / 3) %}
{% if exceeding_row_size or exceeding_column_size %}
{% do alert_data_dict.update({risky_field: none}) %}
{% endif %}
{% endfor %}
Expand Down

0 comments on commit b549e31

Please sign in to comment.