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/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 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..c22c8fab 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-rc1 +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..45bcf628 100644 --- a/macros/calculate.sql +++ b/macros/calculate.sql @@ -11,6 +11,14 @@ 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 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 -%} {%- set metric_list = [metric_list] -%} {%- endif -%} @@ -40,7 +48,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..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 %} @@ -51,7 +59,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