From 54c50f6eaca9d72f669e845c4b99198c847ee530 Mon Sep 17 00:00:00 2001 From: Callum McCann Date: Wed, 26 Apr 2023 16:27:05 -0500 Subject: [PATCH 1/5] support for 1.5 --- dbt_project.yml | 3 +- dev-requirements.txt | 28 +++--- .../base_count_distinct_metric.yml | 2 +- macros/calculate.sql | 6 +- macros/develop.sql | 2 +- .../test_invalid_metric_config.py | 92 ------------------- .../test_invalid_metric_config_value.py | 92 ------------------- 7 files changed, 23 insertions(+), 202 deletions(-) delete mode 100644 tests/functional/invalid_configs/test_invalid_metric_config.py delete mode 100644 tests/functional/invalid_configs/test_invalid_metric_config_value.py diff --git a/dbt_project.yml b/dbt_project.yml index f044cb3f..bf2de9e1 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -19,7 +19,8 @@ seed-paths: ["seeds"] macro-paths: ["macros"] snapshot-paths: ["snapshots"] -require-dbt-version: [">=1.4.0-a1", "<1.5.0"] +require-dbt-version: [">=1.5.0-a1", "<1.6.0"] +# require-dbt-version: [">=1.4.0-a1", "<1.5.0"] # require-dbt-version: [">=1.3.0-a1", "<1.4.0"] target-path: "target" # directory which will store compiled SQL files diff --git a/dev-requirements.txt b/dev-requirements.txt index db9468d0..c0f8b582 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -10,18 +10,18 @@ pytest-dotenv # git+https://github.com/dbt-labs/dbt-bigquery.git # git+https://github.com/databricks/dbt-databricks.git -# Most recent release candidates -dbt-tests-adapter -dbt-core -dbt-redshift -dbt-snowflake -dbt-bigquery -dbt-databricks - # Most recent stable release -# dbt-tests-adapter==1.3.0 -# dbt-core==1.3.0 -# dbt-redshift==1.3.0 -# dbt-snowflake==1.3.0 -# dbt-bigquery==1.3.0 -# dbt-databricks==1.3.0 +# dbt-tests-adapter +# dbt-core +# dbt-redshift +# dbt-snowflake +# dbt-bigquery +# dbt-databricks + +# Most recent release candidates +dbt-tests-adapter==1.5.0-rc1 +dbt-core==1.5.0-rc2 +dbt-redshift==1.5.0-rc1 +dbt-snowflake==1.5.0-rc1 +dbt-bigquery==1.5.0-rc1 +dbt-databricks==1.5.0-rc1 diff --git a/integration_tests/models/metric_definitions/base_count_distinct_metric.yml b/integration_tests/models/metric_definitions/base_count_distinct_metric.yml index 9d69db9d..7e0648f2 100644 --- a/integration_tests/models/metric_definitions/base_count_distinct_metric.yml +++ b/integration_tests/models/metric_definitions/base_count_distinct_metric.yml @@ -16,7 +16,7 @@ metrics: period: month filters: - field: had_discount - operator: 'is' + operator: '=' value: 'true' - field: order_country operator: '=' diff --git a/macros/calculate.sql b/macros/calculate.sql index 82abd4c6..3303e3e3 100644 --- a/macros/calculate.sql +++ b/macros/calculate.sql @@ -11,6 +11,10 @@ VARIABLE SETTING - Creating the metric tree and making sure metric list is a list! ############ -#} + {%- if execute %} + {% do exceptions.warn("WARNING: dbt_metrics is going to be deprecated in dbt-core 1.6 on July 31st, 2023 as part of the migration to MetricFlow. This package will continue to work with dbt-core 1.5 but a 1.6 version will not be released.") %} + {%- endif %} + {%- if metric_list is not iterable -%} {%- set metric_list = [metric_list] -%} {%- endif -%} @@ -40,7 +44,7 @@ {%- do metrics.validate_dimension_list(dimensions=dimensions, metric_tree=metric_tree, metrics_dictionary=metrics_dictionary) -%} - {%- do metrics.validate_metric_config(metrics_dictionary=metrics_dictionary) -%} + {# {%- do metrics.validate_metric_config(metrics_dictionary=metrics_dictionary) -%} #} {%- do metrics.validate_where(where=where) -%} diff --git a/macros/develop.sql b/macros/develop.sql index 6f3aea68..d1e17ecf 100644 --- a/macros/develop.sql +++ b/macros/develop.sql @@ -51,7 +51,7 @@ {%- do metrics.validate_dimension_list(dimensions=dimensions, metric_tree=metric_tree, metrics_dictionary=metrics_dictionary) -%} - {%- do metrics.validate_metric_config(metrics_dictionary=metrics_dictionary) -%} + {# {%- do metrics.validate_metric_config(metrics_dictionary=metrics_dictionary) -%} #} {%- do metrics.validate_secondary_calculations(metric_tree=metric_tree, metrics_dictionary=metrics_dictionary, grain=grain, secondary_calculations=secondary_calculations) -%} diff --git a/tests/functional/invalid_configs/test_invalid_metric_config.py b/tests/functional/invalid_configs/test_invalid_metric_config.py deleted file mode 100644 index a7990e96..00000000 --- a/tests/functional/invalid_configs/test_invalid_metric_config.py +++ /dev/null @@ -1,92 +0,0 @@ -from configparser import ParsingError -from struct import pack -import os -import pytest -from dbt.tests.util import run_dbt - -# our file contents -from tests.functional.fixtures import ( - fact_orders_source_csv, - fact_orders_sql, - fact_orders_yml, -) - -# models/invalid_metric_config.sql -invalid_metric_config_sql = """ -select * -from -{{ metrics.calculate(metric('invalid_metric_config'), - grain='month' - ) -}} -""" - -# models/invalid_metric_config.yml -invalid_metric_config_yml = """ -version: 2 -models: - - name: invalid_metric_config - -metrics: - - name: invalid_metric_config - model: ref('fact_orders') - label: Total Discount ($) - timestamp: order_date - time_grains: [day, week, month] - calculation_method: count - expression: order_total - dimensions: - - had_discount - - order_country - config: - did_dave_write_this: true -""" - -class TestInvalidMetricConfig: - - # configuration in dbt_project.yml - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "name": "example", - "models": {"+materialized": "table"} - } - - # install current repo as package - @pytest.fixture(scope="class") - def packages(self): - return { - "packages": [ - {"local": os.getcwd()} - ] - } - - - # everything that goes in the "seeds" directory - @pytest.fixture(scope="class") - def seeds(self): - return { - "fact_orders_source.csv": fact_orders_source_csv - } - - # everything that goes in the "models" directory - @pytest.fixture(scope="class") - def models(self): - return { - "fact_orders.sql": fact_orders_sql, - "fact_orders.yml": fact_orders_yml, - "invalid_metric_config.sql": invalid_metric_config_sql, - "invalid_metric_config.yml": invalid_metric_config_yml - } - - def test_invalid_metric_config(self,project,): - # initial run - results = run_dbt(["deps"]) - - # seed seeds - results = run_dbt(["seed"]) - assert len(results) == 1 - - # Here we expect the run to fail because the value provided - # in the where clause isn't included in the final dataset - run_dbt(["run"], expect_pass = False) \ No newline at end of file diff --git a/tests/functional/invalid_configs/test_invalid_metric_config_value.py b/tests/functional/invalid_configs/test_invalid_metric_config_value.py deleted file mode 100644 index 75aee99a..00000000 --- a/tests/functional/invalid_configs/test_invalid_metric_config_value.py +++ /dev/null @@ -1,92 +0,0 @@ -from configparser import ParsingError -from struct import pack -import os -import pytest -from dbt.tests.util import run_dbt - -# our file contents -from tests.functional.fixtures import ( - fact_orders_source_csv, - fact_orders_sql, - fact_orders_yml, -) - -# models/invalid_metric_config_value.sql -invalid_metric_config_value_sql = """ -select * -from -{{ metrics.calculate(metric('invalid_metric_config_value'), - grain='month' - ) -}} -""" - -# models/invalid_metric_config_value.yml -invalid_metric_config_value_yml = """ -version: 2 -models: - - name: invalid_metric_config_value - -metrics: - - name: invalid_metric_config_value - model: ref('fact_orders') - label: Total Discount ($) - timestamp: order_date - time_grains: [day, week, month] - calculation_method: count - expression: order_total - dimensions: - - had_discount - - order_country - config: - treat_null_values_as_zero: banana -""" - -class TestInvalidMetricConfig: - - # configuration in dbt_project.yml - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "name": "example", - "models": {"+materialized": "table"} - } - - # install current repo as package - @pytest.fixture(scope="class") - def packages(self): - return { - "packages": [ - {"local": os.getcwd()} - ] - } - - - # everything that goes in the "seeds" directory - @pytest.fixture(scope="class") - def seeds(self): - return { - "fact_orders_source.csv": fact_orders_source_csv - } - - # everything that goes in the "models" directory - @pytest.fixture(scope="class") - def models(self): - return { - "fact_orders.sql": fact_orders_sql, - "fact_orders.yml": fact_orders_yml, - "invalid_metric_config_value.sql": invalid_metric_config_value_sql, - "invalid_metric_config_value.yml": invalid_metric_config_value_yml - } - - def test_metric_config_value(self,project,): - # initial run - results = run_dbt(["deps"]) - - # seed seeds - results = run_dbt(["seed"]) - assert len(results) == 1 - - # Here we expect the run to fail because the value provided - # in the where clause isn't included in the final dataset - run_dbt(["run"], expect_pass = False) \ No newline at end of file From f4e7092a1ad969d06353ee40197d6da7d41fdfb9 Mon Sep 17 00:00:00 2001 From: Callum McCann Date: Wed, 26 Apr 2023 16:36:32 -0500 Subject: [PATCH 2/5] Warning Message & Changie --- .changes/unreleased/Breaking Changes-20230426-163623.yaml | 7 +++++++ macros/calculate.sql | 6 +++++- macros/develop.sql | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Breaking Changes-20230426-163623.yaml diff --git a/.changes/unreleased/Breaking Changes-20230426-163623.yaml b/.changes/unreleased/Breaking Changes-20230426-163623.yaml new file mode 100644 index 00000000..459792bd --- /dev/null +++ b/.changes/unreleased/Breaking Changes-20230426-163623.yaml @@ -0,0 +1,7 @@ +kind: Breaking Changes +body: Adding support for dbt-core 1.5 +time: 2023-04-26T16:36:23.710755-05:00 +custom: + Author: callum-mcdata + Issue: "239" + PR: "240" diff --git a/macros/calculate.sql b/macros/calculate.sql index 3303e3e3..45bcf628 100644 --- a/macros/calculate.sql +++ b/macros/calculate.sql @@ -12,7 +12,11 @@ ############ -#} {%- if execute %} - {% do exceptions.warn("WARNING: dbt_metrics is going to be deprecated in dbt-core 1.6 on July 31st, 2023 as part of the migration to MetricFlow. This package will continue to work with dbt-core 1.5 but a 1.6 version will not be released.") %} + {% do exceptions.warn( + "WARNING: dbt_metrics is going to be deprecated in dbt-core 1.6 in \ +July 2023 as part of the migration to MetricFlow. This package will \ +continue to work with dbt-core 1.5 but a 1.6 version will not be \ +released. If you have any questions, please join us in the #dbt-core-metrics in the dbt Community Slack") %} {%- endif %} {%- if metric_list is not iterable -%} diff --git a/macros/develop.sql b/macros/develop.sql index d1e17ecf..cba461ed 100644 --- a/macros/develop.sql +++ b/macros/develop.sql @@ -7,6 +7,14 @@ {#- Need this here, since the actual ref is nested within loops/conditions: -#} -- depends on: {{ ref(var('dbt_metrics_calendar_model', 'dbt_metrics_default_calendar')) }} + {%- if execute %} + {% do exceptions.warn( + "WARNING: dbt_metrics is going to be deprecated in dbt-core 1.6 in \ +July 2023 as part of the migration to MetricFlow. This package will \ +continue to work with dbt-core 1.5 but a 1.6 version will not be \ +released. If you have any questions, please join us in the #dbt-core-metrics in the dbt Community Slack") %} + {%- endif %} + {% if not execute -%} {%- do return("not execute") -%} {%- endif %} From 823dd7bb810247906aebabe2ec3af9c0cc91d7a9 Mon Sep 17 00:00:00 2001 From: Callum McCann Date: Wed, 26 Apr 2023 16:37:58 -0500 Subject: [PATCH 3/5] fixing readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9220f4fb..325b8fd8 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Include in your `package.yml` ```yaml packages: - package: dbt-labs/metrics - version: [">=1.4.0", "<1.5.0"] + version: [">=1.5.0", "<1.6.0"] ``` ## Supported Adapters From 3ccc1d1eac05ac7499799b28cfecd66b7ba7d196 Mon Sep 17 00:00:00 2001 From: Callum McCann Date: Wed, 26 Apr 2023 16:46:40 -0500 Subject: [PATCH 4/5] Removing databricks testing --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index c0f8b582..39d60530 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -24,4 +24,4 @@ dbt-core==1.5.0-rc2 dbt-redshift==1.5.0-rc1 dbt-snowflake==1.5.0-rc1 dbt-bigquery==1.5.0-rc1 -dbt-databricks==1.5.0-rc1 +# dbt-databricks==1.5.0-rc1 From ebf9f248b64185fb9aaaecc9a7bc0ea02119b4ff Mon Sep 17 00:00:00 2001 From: Callum McCann Date: Thu, 27 Apr 2023 08:22:42 -0500 Subject: [PATCH 5/5] updating all to rc1 --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 39d60530..c22c8fab 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -20,7 +20,7 @@ pytest-dotenv # Most recent release candidates dbt-tests-adapter==1.5.0-rc1 -dbt-core==1.5.0-rc2 +dbt-core==1.5.0-rc1 dbt-redshift==1.5.0-rc1 dbt-snowflake==1.5.0-rc1 dbt-bigquery==1.5.0-rc1