Skip to content

Commit

Permalink
Merge branch 'next/minor'
Browse files Browse the repository at this point in the history
  • Loading branch information
joellabes committed Dec 2, 2021
2 parents e987f9b + baf4053 commit 68b4b4d
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:

integration-postgres:
docker:
- image: circleci/python:3.6.13-stretch
- image: cimg/python:3.9.9
- image: circleci/postgres:9.6.5-alpine-ram

steps:
Expand All @@ -24,7 +24,7 @@ jobs:

integration-redshift:
docker:
- image: circleci/python:3.6.3-stretch
- image: cimg/python:3.9.9
steps:
- checkout
- run:
Expand All @@ -35,7 +35,7 @@ jobs:

integration-snowflake:
docker:
- image: circleci/python:3.6.3-stretch
- image: cimg/python:3.9.9
steps:
- checkout
- run:
Expand All @@ -48,7 +48,7 @@ jobs:
environment:
BIGQUERY_SERVICE_KEY_PATH: "/home/circleci/bigquery-service-key.json"
docker:
- image: circleci/python:3.6.3-stretch
- image: cimg/python:3.9.9
steps:
- checkout
- run:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# dbt-utils v0.8.0
## 🚨 Breaking changes
- dbt ONE POINT OH is here! This version of dbt-utils requires _any_ version (minor and patch) 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 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.

Expand Down Expand Up @@ -28,10 +36,12 @@
- Bump `require-dbt-version` to have an upper bound of `'<=1.0.0'`.
- Url link fixes within the README for `not_constant`, `dateadd`, `datediff` and updated the header `Logger` to `Jinja Helpers`. ([#431](https://github.com/dbt-labs/dbt-utils/pull/431))
- Fully qualified a `cte_name.*` in the `equality` test to avoid an Exasol error ([#420](https://github.com/dbt-labs/dbt-utils/pull/420))
- `get_url_host()` macro now correctly handles URLs beginning with `android-app://` ([#426](https://github.com/dbt-labs/dbt-utils/pull/426))

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

# dbt-utils v0.7.3

Expand Down Expand Up @@ -112,6 +122,7 @@ If you were relying on the position to match up your optional arguments, this ma
## Under the hood
* Update the default implementation of concat macro to use `||` operator ([#373](https://github.com/fishtown-analytics/dbt-utils/pull/314) from [@ChristopheDuong](https://github.com/ChristopheDuong)). Note this may be a breaking change for adapters that support `concat()` but not `||`, such as Apache Spark.
- Use `power()` instead of `pow()` in `generate_series()` and `haversine_distance()` as they are synonyms in most SQL dialects, but some dialects only have `power()` ([#354](https://github.com/fishtown-analytics/dbt-utils/pull/354) from [@swanderz](https://github.com/swanderz))
- Make `get_column_values` return the default value passed as a parameter instead of an empty string before compilation ([#304](https://github.com/dbt-labs/dbt-utils/pull/386) from [@jmriego](https://github.com/jmriego)

# dbt-utils v0.6.6

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ group by 1,2,3
```

#### star ([source](macros/sql/star.sql))
This macro generates a list of all fields that exist in the `from` relation, excluding any fields listed in the `except` argument. The construction is identical to `select * from {{ref('my_model')}}`, replacing star (`*`) with the star macro. This macro also has an optional `relation_alias` argument that will prefix all generated fields with an alias.
This macro generates a list of all fields that exist in the `from` relation, excluding any fields listed in the `except` argument. The construction is identical to `select * from {{ref('my_model')}}`, replacing star (`*`) with the star macro. This macro also has an optional `relation_alias` argument that will prefix all generated fields with an alias (`relation_alias`.`field_name`). The macro also has optional `prefix` and `suffix` arguments, which will be appropriately concatenated to each field name in the output (`prefix` ~ `field_name` ~ `suffix`).

**Usage:**
```sql
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.1.0"]
require-dbt-version: [">=1.0.0", "<2.0.0"]

config-version: 2

target-path: "target"
clean-targets: ["target", "dbt_modules"]
clean-targets: ["target", "dbt_modules", "dbt_packages"]
macro-paths: ["macros"]
log-path: "logs"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prefix_field_1_suffix,prefix_field_2_suffix,prefix_field_3_suffix
a,b,c
d,e,f
g,h,i
10 changes: 5 additions & 5 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 @@ -56,9 +57,8 @@ seeds:
+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 }}"
# this.incorporate() to hardcode the node's type as otherwise dbt doesn't know it yet
+post-hook: "{% do adapter.drop_relation(this.incorporate(type='table')) %}"


schema_tests:
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/models/sql/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ models:
- dbt_utils.equality:
compare_model: ref('data_star_expected')

- name: test_star_prefix_suffix
tests:
- dbt_utils.equality:
compare_model: ref('data_star_prefix_suffix_expected')

- name: test_surrogate_key
tests:
- assert_equal:
Expand Down
13 changes: 13 additions & 0 deletions integration_tests/models/sql/test_star_prefix_suffix.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% set prefix_with = 'prefix_' if target.type != 'snowflake' else 'PREFIX_' %}
{% set suffix_with = '_suffix' if target.type != 'snowflake' else '_SUFFIX' %}

with data as (

select
{{ dbt_utils.star(from=ref('data_star'), prefix=prefix_with, suffix=suffix_with) }}

from {{ ref('data_star') }}

)

select * from data
2 changes: 1 addition & 1 deletion macros/schema_tests/mutually_exclusive_ranges.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ with window_functions as (

select
{% if partition_by %}
{{ partition_by }},
{{ partition_by }} as partition_by_col,
{% endif %}
{{ lower_bound_column }} as lower_bound,
{{ upper_bound_column }} as upper_bound,
Expand Down
6 changes: 4 additions & 2 deletions macros/sql/get_column_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
{% endmacro %}

{% macro default__get_column_values(table, column, order_by='count(*) desc', max_records=none, default=none) -%}

{% if default is none %}
{% set default = [] %}
{% endif %}
{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
{{ return('') }}
{{ return(default) }}
{% endif %}

{# Not all relations are tables. Renaming for internal clarity without breaking functionality for anyone using named arguments #}
Expand Down
8 changes: 4 additions & 4 deletions macros/sql/star.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% macro star(from, relation_alias=False, except=[]) -%}
{{ return(adapter.dispatch('star', 'dbt_utils')(from, relation_alias, except)) }}
{% macro star(from, relation_alias=False, except=[], prefix='', suffix='') -%}
{{ return(adapter.dispatch('star', 'dbt_utils')(from, relation_alias, except, prefix, suffix)) }}
{% endmacro %}

{% macro default__star(from, relation_alias=False, except=[]) -%}
{% macro default__star(from, relation_alias=False, except=[], prefix='', suffix='') -%}
{%- do dbt_utils._is_relation(from, 'star') -%}
{%- do dbt_utils._is_ephemeral(from, 'star') -%}

Expand All @@ -24,7 +24,7 @@

{%- for col in include_cols %}

{%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%}{{ adapter.quote(col)|trim }}
{%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%}{{ adapter.quote(col)|trim }} as {{ adapter.quote(prefix ~ col ~ suffix)|trim }}
{%- if not loop.last %},{{ '\n ' }}{% endif %}

{%- endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion macros/web/get_url_host.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
dbt_utils.type_string()
)}}

{%- endmacro %}
{%- endmacro %}

0 comments on commit 68b4b4d

Please sign in to comment.