Skip to content

Commit a976cdf

Browse files
authored
Final 0 9 0 prep (#643)
* Move deprecated macros to a deprecated folder * Move width_bucket into sql generators * Warn that some more macros will be removed in future * Fix BQ seed
1 parent 58f80c4 commit a976cdf

37 files changed

Lines changed: 50 additions & 37 deletions

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ For compatibility details between versions of dbt-core and dbt-utils, [see this
4848
- [safe_add](#safe_add-source)
4949
- [pivot](#pivot-source)
5050
- [unpivot](#unpivot-source)
51+
- [width_bucket](#width_bucket-source)
52+
5153

5254
- [Web macros](#web-macros)
5355
- [get_url_parameter](#get_url_parameter-source)
@@ -60,7 +62,6 @@ For compatibility details between versions of dbt-core and dbt-utils, [see this
6062
- [datediff](#datediff-source)
6163
- [split_part](#split_part-source)
6264
- [last_day](#last_day-source)
63-
- [width_bucket](#width_bucket-source)
6465
- [listagg](#listagg-source)
6566
- [array_construct](#array_construct-source)
6667
- [array_append](#array_append-source)
@@ -1005,6 +1006,31 @@ Boolean values are replaced with the strings 'true'|'false'
10051006
- `field_name`: column name in the resulting table for field
10061007
- `value_name`: column name in the resulting table for value
10071008

1009+
#### width_bucket ([source](macros/cross_db_utils/width_bucket.sql))
1010+
This macro is modeled after the `width_bucket` function natively available in Snowflake.
1011+
1012+
From the original Snowflake [documentation](https://docs.snowflake.net/manuals/sql-reference/functions/width_bucket.html):
1013+
1014+
Constructs equi-width histograms, in which the histogram range is divided into intervals of identical size, and returns the bucket number into which the value of an expression falls, after it has been evaluated. The function returns an integer value or null (if any input is null).
1015+
Notes:
1016+
1017+
**Args:**
1018+
- `expr`: The expression for which the histogram is created. This expression must evaluate to a numeric value or to a value that can be implicitly converted to a numeric value.
1019+
1020+
- `min_value` and `max_value`: The low and high end points of the acceptable range for the expression. The end points must also evaluate to numeric values and not be equal.
1021+
1022+
- `num_buckets`: The desired number of buckets; must be a positive integer value. A value from the expression is assigned to each bucket, and the function then returns the corresponding bucket number.
1023+
1024+
When an expression falls outside the range, the function returns:
1025+
- `0` if the expression is less than min_value.
1026+
- `num_buckets + 1` if the expression is greater than or equal to max_value.
1027+
1028+
1029+
**Usage:**
1030+
```
1031+
{{ dbt_utils.width_bucket(expr, min_value, max_value, num_buckets) }}
1032+
```
1033+
10081034
### Web macros
10091035
#### get_url_parameter ([source](macros/web/get_url_parameter.sql))
10101036
This macro extracts a url parameter from a column containing a url.
@@ -1092,31 +1118,6 @@ Gets the last day for a given date and datepart. Notes:
10921118
{{ dbt_utils.last_day(date, datepart) }}
10931119
```
10941120

1095-
#### width_bucket ([source](macros/cross_db_utils/width_bucket.sql))
1096-
This macro is modeled after the `width_bucket` function natively available in Snowflake.
1097-
1098-
From the original Snowflake [documentation](https://docs.snowflake.net/manuals/sql-reference/functions/width_bucket.html):
1099-
1100-
Constructs equi-width histograms, in which the histogram range is divided into intervals of identical size, and returns the bucket number into which the value of an expression falls, after it has been evaluated. The function returns an integer value or null (if any input is null).
1101-
Notes:
1102-
1103-
**Args:**
1104-
- `expr`: The expression for which the histogram is created. This expression must evaluate to a numeric value or to a value that can be implicitly converted to a numeric value.
1105-
1106-
- `min_value` and `max_value`: The low and high end points of the acceptable range for the expression. The end points must also evaluate to numeric values and not be equal.
1107-
1108-
- `num_buckets`: The desired number of buckets; must be a positive integer value. A value from the expression is assigned to each bucket, and the function then returns the corresponding bucket number.
1109-
1110-
When an expression falls outside the range, the function returns:
1111-
- `0` if the expression is less than min_value.
1112-
- `num_buckets + 1` if the expression is greater than or equal to max_value.
1113-
1114-
1115-
**Usage:**
1116-
```
1117-
{{ dbt_utils.width_bucket(expr, min_value, max_value, num_buckets) }}
1118-
```
1119-
11201121
#### listagg ([source](macros/cross_db_utils/listagg.sql))
11211122
This macro returns the concatenated input values from a group of rows separated by a specified deliminator.
11221123

File renamed without changes.

integration_tests/dbt_project.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ seeds:
4646
first_date: timestamp
4747
second_date: timestamp
4848

49-
data_width_bucket:
50-
+column_types:
51-
num_buckets: integer
52-
min_value: float
53-
max_value: float
5449

5550
sql:
5651
data_events_20180103:
@@ -60,6 +55,12 @@ seeds:
6055
# this.incorporate() to hardcode the node's type as otherwise dbt doesn't know it yet
6156
+post-hook: "{% do adapter.drop_relation(this.incorporate(type='table')) %}"
6257

58+
data_width_bucket:
59+
+column_types:
60+
num_buckets: integer
61+
min_value: float
62+
max_value: float
63+
6364
schema_tests:
6465
data_test_sequential_timestamps:
6566
+column_types:

integration_tests/models/cross_db_utils/schema.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ models:
108108
expected: expected
109109

110110
- name: test_position
111-
tests:
112-
- assert_equal:
113-
actual: actual
114-
expected: expected
115-
116-
- name: test_width_bucket
117111
tests:
118112
- assert_equal:
119113
actual: actual

integration_tests/models/sql/schema.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,9 @@ models:
182182
tests:
183183
- dbt_utils.equality:
184184
compare_model: ref('data_deduplicate_expected')
185+
186+
- name: test_width_bucket
187+
tests:
188+
- assert_equal:
189+
actual: actual
190+
expected: expected

integration_tests/models/cross_db_utils/test_width_bucket.sql renamed to integration_tests/models/sql/test_width_bucket.sql

File renamed without changes.

macros/cross_db_utils/array_append.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% macro array_append(array, new_element) -%}
2+
{% do dbt_utils.xdb_deprecation_warning_without_replacement('array_append', model.package_name, model.name) %}
23
{{ return(adapter.dispatch('array_append', 'dbt_utils')(array, new_element)) }}
34
{%- endmacro %}
45

macros/cross_db_utils/array_concat.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% macro array_concat(array_1, array_2) -%}
2+
{% do dbt_utils.xdb_deprecation_warning_without_replacement('array_concat', model.package_name, model.name) %}
23
{{ return(adapter.dispatch('array_concat', 'dbt_utils')(array_1, array_2)) }}
34
{%- endmacro %}
45

macros/cross_db_utils/array_construct.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% macro array_construct(inputs = [], data_type = api.Column.translate_type('integer')) -%}
2+
{% do dbt_utils.xdb_deprecation_warning_without_replacement('array_construct', model.package_name, model.name) %}
23
{{ return(adapter.dispatch('array_construct', 'dbt_utils')(inputs, data_type)) }}
34
{%- endmacro %}
45

macros/cross_db_utils/cast_array_to_string.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% macro cast_array_to_string(array) %}
2+
{% do dbt_utils.xdb_deprecation_warning_without_replacement('cast_array_to_string', model.package_name, model.name) %}
23
{{ adapter.dispatch('cast_array_to_string', 'dbt_utils') (array) }}
34
{% endmacro %}
45

0 commit comments

Comments
 (0)