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

dbt v1 compat #453

Merged
merged 15 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 12 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
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# dbt-utils v0.8.0
## 🚨 Breaking changes
- dbt ONE POINT OH is here! This version of dbt-utils requires `dbt-core ~=1.0.0` (any minor and patch version of v1), which means far less need for compatibility releases in the future.
- The partition column in the `mutually_exclusive_ranges` test is now always called `partition_by_col`. This enables compatibility with `--store-failures` when multiple columns are concatenated together. If you have models built on top of the failures table, update them to reflect the new column name. ([#423](https://github.com/dbt-labs/dbt-utils/issues/423), [#430](https://github.com/dbt-labs/dbt-utils/pull/430))

## Contributors:
- [codigo-ergo-sum](https://github.com/codigo-ergo-sum) (#430)

# dbt-utils v0.7.4
# dbt-utils 0.7.5
🚨 This is a compatibility release in preparation for `dbt-core` v1.0.0 (🎉). Projects using dbt-utils 0.7.4 with dbt-core v1.0.0 can expect to see a deprecation warning. This will be resolved in dbt_utils v0.8.0.

## Fixes
- Regression in `get_column_values()` where the default would not be respected if the model didn't exist. ([#444](https://github.com/dbt-labs/dbt-utils/issues/444), [#448](https://github.com/dbt-labs/dbt-utils/pull/448))

## Under the hood
- get_url_host() macro now correctly handles URLs beginning with android-app:// (#426)

## Contributors:
- [foundinblank](https://github.com/foundinblank)

# dbt-utils v0.7.4
## Fixes
- `get_column_values()` now works correctly with mixed-quoting styles on Snowflake ([#424](https://github.com/dbt-labs/dbt-utils/issues/424), [#440](https://github.com/dbt-labs/dbt-utils/pull/440))
- Remove extra semicolon in `insert_by_period` materialization that was causing errors ([#439](https://github.com/dbt-labs/dbt-utils/pull/439))
Expand Down
6 changes: 3 additions & 3 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: 'dbt_utils'
version: '0.7.0'
version: '0.1.0'

require-dbt-version: [">=0.20.0", "<=1.0.0"]
require-dbt-version: [">=1.0.0-rc", "<2.0.0"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about switching this to [">=1.0.0", "<2.0.0"] once we have a final release of dbt-core v1.0.0? In which case, this feels fine for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't really want to have to release 0.8.1 in a week that just drops the release candidates. Since

  • 0.7.5 supports <= 1.0 as its upper bound, which does include the RCs, and
  • 1.0 final is on the cusp of release anyway,

I think I'm happy to say that 0.8 is only going to cover the final released version of 1.0

Copy link
Contributor Author

@joellabes joellabes Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With that said, that means that when I merge this in, Circle CI will give it a ❌ until 1.0 final actually ships. Do we feel OK about that? (cc @jasnonaz)

keeping in mind that there are like a dozen packages that will all need changed, so I really don't wanna do that twice


config-version: 2

target-path: "target"
clean-targets: ["target", "dbt_modules"]
clean-targets: ["target", "dbt_modules", "dbt_packages"]
macro-paths: ["macros"]
log-path: "logs"
12 changes: 12 additions & 0 deletions integration_tests/data/sql/data_get_column_values_dropped.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
field
a
b
c
d
e
f
g
g
g
g
g
2 changes: 1 addition & 1 deletion integration_tests/data/web/data_url_host.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ http://witanddelight.com/2018/01/tips-tricks-how-run-half-marathon-first-time/,w
https://www.nytimes.com/2018/01/01/blog,www.nytimes.com
android-app://m.facebook.com/,m.facebook.com
docs.nytimes.com/2021/01/01/index.js?utm_source=google,docs.nytimes.com
https://m.facebook.com/,m.facebook.com
https://m.facebook.com/,m.facebook.com
11 changes: 9 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ profile: 'integration_tests'

config-version: 2

source-paths: ["models"]
model-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
seed-paths: ["data"]
macro-paths: ["macros"]

target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_modules"
- "dbt_packages"

dispatch:
- macro_namespace: 'dbt_utils'
Expand Down Expand Up @@ -54,6 +55,12 @@ seeds:
sql:
data_events_20180103:
+schema: events

data_get_column_values_dropped:
# TODO: Ideally this would use the adapter, but it gives a "Tried to drop relation, but its type is null" error.
#+post-hook: "{% do adapter.drop_relation(this) %}"
+post-hook: "drop table {{ this }}"
Copy link
Contributor

@jtcohen6 jtcohen6 Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you know that this is a table, you could try something like (pseudo-code):

    +post-hook: "{% do adapter.drop_relation(this.incorporate(type='table')) %}"



schema_tests:
data_test_sequential_timestamps:
Expand Down
26 changes: 26 additions & 0 deletions integration_tests/tests/sql/test_get_column_values_use_default.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

{% set column_values = dbt_utils.get_column_values(ref('data_get_column_values_dropped'), 'field', default=['y', 'z'], order_by="field") %}

with expected as (
select {{ dbt_utils.safe_cast("'y'", dbt_utils.type_string()) }} as expected_column_value union all
select {{ dbt_utils.safe_cast("'z'", dbt_utils.type_string()) }} as expected_column_value
),

actual as (

{% for val in column_values %}
select {{ dbt_utils.safe_cast("'" ~ val ~ "'", dbt_utils.type_string()) }} as actual_column_value
{% if not loop.last %}
union all
{% endif %}
{% endfor %}
),

failures as (
select * from actual
where actual.actual_column_value not in (
select expected.expected_column_value from expected
)
)

select * from failures
11 changes: 7 additions & 4 deletions macros/sql/get_column_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
{# TODO: Change the method signature in a future 0.x.0 release #}
{%- set target_relation = table -%}

{# adapter.load_relation is a convenience wrapper to avoid building a Relation when we already have one #}
{% set relation_exists = (load_relation(target_relation)) is not none %}

{%- call statement('get_column_values', fetch_result=true) %}

{%- if not target_relation and default is none -%}
{%- if not relation_exists and default is none -%}

{{ exceptions.raise_compiler_error("In get_column_values(): relation " ~ table ~ " does not exist and no default value was provided.") }}
{{ exceptions.raise_compiler_error("In get_column_values(): relation " ~ target_relation ~ " does not exist and no default value was provided.") }}

{%- elif not target_relation and default is not none -%}
{%- elif not relation_exists and default is not none -%}

{{ log("Relation " ~ table ~ " does not exist. Returning the default value: " ~ default) }}
{{ log("Relation " ~ target_relation ~ " does not exist. Returning the default value: " ~ default) }}

{{ return(default) }}

Expand Down