From 48a91e7fe29b020d3f17d7a7d46d68e15477007c Mon Sep 17 00:00:00 2001 From: noyaarie Date: Thu, 27 Feb 2025 15:39:01 +0200 Subject: [PATCH 1/2] support filter in dump table --- macros/commands/dump_table.sql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/macros/commands/dump_table.sql b/macros/commands/dump_table.sql index 0bd6c5d96..9cc960160 100644 --- a/macros/commands/dump_table.sql +++ b/macros/commands/dump_table.sql @@ -1,4 +1,4 @@ -{% macro dump_table(model_unique_id, output_path, exclude_deprecated_columns=true, timestamp_column=none, since=none, days_back=7, dedup=false, until=none) %} +{% macro dump_table(model_unique_id, output_path, exclude_deprecated_columns=true, timestamp_column=none, since=none, days_back=7, dedup=false, until=none, filter=none) %} {% set node = graph.nodes.get(model_unique_id) %} {% if not node %} {% do print("Node '{}' does not exist.".format(model_unique_id)) %} @@ -35,6 +35,13 @@ where {{ elementary.edr_datediff(elementary.edr_cast_as_timestamp(timestamp_column), elementary.edr_current_timestamp(), 'day') }} < {{ days_back }} {% endif %} {% endif %} + {% if filter %} + {% if timestamp_column %} + and {{ filter }} + {% else %} + where {{ filter }} + {% endif %} + {% endif %} {% endset %} {% set results = elementary.run_query(query) %} {% do results.to_csv(output_path) %} From 81423b5c1c2bf0abe1aa5ee81aa6f463c4f69bee Mon Sep 17 00:00:00 2001 From: noyaarie Date: Thu, 27 Feb 2025 15:58:23 +0200 Subject: [PATCH 2/2] rename to table_filter --- macros/commands/dump_table.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/macros/commands/dump_table.sql b/macros/commands/dump_table.sql index 9cc960160..680588348 100644 --- a/macros/commands/dump_table.sql +++ b/macros/commands/dump_table.sql @@ -1,4 +1,4 @@ -{% macro dump_table(model_unique_id, output_path, exclude_deprecated_columns=true, timestamp_column=none, since=none, days_back=7, dedup=false, until=none, filter=none) %} +{% macro dump_table(model_unique_id, output_path, exclude_deprecated_columns=true, timestamp_column=none, since=none, days_back=7, dedup=false, until=none, table_filter=none) %} {% set node = graph.nodes.get(model_unique_id) %} {% if not node %} {% do print("Node '{}' does not exist.".format(model_unique_id)) %} @@ -35,11 +35,11 @@ where {{ elementary.edr_datediff(elementary.edr_cast_as_timestamp(timestamp_column), elementary.edr_current_timestamp(), 'day') }} < {{ days_back }} {% endif %} {% endif %} - {% if filter %} + {% if table_filter %} {% if timestamp_column %} - and {{ filter }} + and {{ table_filter }} {% else %} - where {{ filter }} + where {{ table_filter }} {% endif %} {% endif %} {% endset %}