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

chore/apply 717530c #967

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d1a5bac
fix: extra brace typo in insert_by_period_materialization
tconbeer Jan 21, 2022
fba1cf9
Merge branch 'dbt-labs:main' into main
tconbeer May 5, 2022
7c4d7f2
chore: apply sqlfmt 0.8.0
tconbeer May 5, 2022
dbbc827
chore: apply sqlfmt 59e52a1073180668ddc6c53a2d1eb9450ebff329
tconbeer May 11, 2022
ddbb104
Merge branch 'main' into fix/trailing-commas
tconbeer May 11, 2022
a219241
Merge pull request #1 from tconbeer/fix/trailing-commas
tconbeer May 11, 2022
f6671f5
chore: apply sqlfmt 138e98e
tconbeer May 14, 2022
dd71818
Merge branch 'main' into chore/apply-138e98e
tconbeer May 14, 2022
7196170
Merge pull request #2 from tconbeer/chore/apply-138e98e
tconbeer May 14, 2022
cc17535
chore: apply sqlfmt d0e14b9 (#3)
tconbeer May 18, 2022
0695ce6
chore: apply sqlfmt aca4b6a (#4)
tconbeer Jun 13, 2022
a617b80
chore: apply sqlfmt e406e35 (#5)
tconbeer Jul 15, 2022
1afba0e
chore: apply sqlfmt fb99833 (#6)
tconbeer Jul 19, 2022
bfe3e2d
chore: apply sqlfmt bcf660d (#8)
tconbeer Aug 2, 2022
98ef570
chore: apply sqlfmt 6d33371 (#9)
tconbeer Aug 8, 2022
f676241
chore: apply sqlfmt 8b20379 (#10)
tconbeer Aug 17, 2022
55c9199
chore: apply sqlfmt 3e0f900 (#11)
tconbeer Aug 19, 2022
a70e75d
chore: apply sqlfmt b792a79 (#13)
tconbeer Nov 14, 2022
749446c
chore: apply sqlfmt a7ed980 (#14)
tconbeer Nov 30, 2022
eb7aec4
chore: apply sqlfmt 4f9a917 (#16)
tconbeer Dec 11, 2022
6170f77
chore: apply sqlfmt d620ac8 (#17)
tconbeer Jan 17, 2023
664fd68
chore: apply sqlfmt e6f9f4c (#18)
tconbeer Jan 17, 2023
8d81899
chore: apply sqlfmt d97af4e (#19)
tconbeer Jan 24, 2023
ab55e10
chore: apply sqlfmt 124890d (#20)
tconbeer Jan 26, 2023
ae160c9
chore: apply sqlfmt 54b8edd (#21)
tconbeer Apr 14, 2023
c62b99f
chore: apply sqlfmt 6e9615c (#22)
tconbeer May 10, 2023
72fe12f
chore: apply sqlfmt 717530c
tconbeer Nov 22, 2024
425b90a
Merge branch 'main' into chore/apply-717530c
tconbeer Nov 22, 2024
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
21 changes: 9 additions & 12 deletions integration_tests/macros/assert_equal_values.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{% macro assert_equal_values(actual_object, expected_object) %}
{% if not execute %}
{% if not execute %}

{# pass #}
{% elif actual_object != expected_object %}

{% elif actual_object != expected_object %}

{% set msg %}
{% set msg %}
Expected did not match actual

-----------
Expand All @@ -18,15 +17,13 @@
-----------
--->{{ expected_object }}<---

{% endset %}

{{ log(msg, info=True) }}
{% endset %}

select 'fail'
{{ log(msg, info=True) }}

{% else %}
select 'fail'

select 'ok' {{ limit_zero() }}
{% else %} select 'ok' {{ limit_zero() }}

{% endif %}
{% endmacro %}
{% endif %}
{% endmacro %}
10 changes: 3 additions & 7 deletions integration_tests/macros/limit_zero.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{% macro my_custom_macro() %}
whatever
{% endmacro %}
{% macro my_custom_macro() %} whatever {% endmacro %}

{% macro limit_zero() %}
{{ return(adapter.dispatch('limit_zero', 'dbt_utils')()) }}
{{ return(adapter.dispatch("limit_zero", "dbt_utils")()) }}
{% endmacro %}

{% macro default__limit_zero() %}
{{ return('limit 0') }}
{% endmacro %}
{% macro default__limit_zero() %} {{ return("limit 0") }} {% endmacro %}
5 changes: 2 additions & 3 deletions integration_tests/macros/tests.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

{% test assert_equal(model, actual, expected) %}
select * from {{ model }} where {{ actual }} != {{ expected }}
select * from {{ model }} where {{ actual }} != {{ expected }}

{% endtest %}


{% test not_empty_string(model, column_name) %}

select * from {{ model }} where {{ column_name }} = ''
select * from {{ model }} where {{ column_name }} = ''

{% endtest %}
41 changes: 24 additions & 17 deletions integration_tests/models/cross_db_utils/test_any_value.sql
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
with some_model as (
select 1 as id, 'abc' as key_name, 'dbt' as static_col union all
select 2 as id, 'abc' as key_name, 'dbt' as static_col union all
select 3 as id, 'jkl' as key_name, 'dbt' as static_col union all
select 4 as id, 'jkl' as key_name, 'dbt' as static_col union all
select 5 as id, 'jkl' as key_name, 'dbt' as static_col union all
select 6 as id, 'xyz' as key_name, 'test' as static_col
),
with
some_model as (
select 1 as id, 'abc' as key_name, 'dbt' as static_col
union all
select 2 as id, 'abc' as key_name, 'dbt' as static_col
union all
select 3 as id, 'jkl' as key_name, 'dbt' as static_col
union all
select 4 as id, 'jkl' as key_name, 'dbt' as static_col
union all
select 5 as id, 'jkl' as key_name, 'dbt' as static_col
union all
select 6 as id, 'xyz' as key_name, 'test' as static_col
),

final as (
select
key_name,
{{ dbt_utils.any_value('static_col') }} as static_col,
count(id) as num_rows
from some_model
group by key_name
)
final as (
select
key_name,
{{ dbt_utils.any_value("static_col") }} as static_col,
count(id) as num_rows
from some_model
group by key_name
)

select * from final
select *
from final
8 changes: 3 additions & 5 deletions integration_tests/models/cross_db_utils/test_bool_or.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
select
key,
{{ dbt_utils.bool_or('val1 = val2') }} as value
from {{ ref('data_bool_or' )}}
group by key
select key, {{ dbt_utils.bool_or("val1 = val2") }} as value
from {{ ref("data_bool_or") }}
group by key
11 changes: 2 additions & 9 deletions integration_tests/models/cross_db_utils/test_concat.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
with data as (select * from {{ ref("data_concat") }})

with data as (

select * from {{ ref('data_concat') }}

)

select
{{ dbt_utils.concat(['input_1', 'input_2']) }} as actual,
output as expected
select {{ dbt_utils.concat(["input_1", "input_2"]) }} as actual, output as expected

from data
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

-- how can we test this better?
select
{{ dbt_utils.current_timestamp() }} as actual,
{{ dbt_utils.current_timestamp() }} as expected

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

-- how can we test this better?
select
{{ dbt_utils.current_timestamp_in_utc() }} as actual,
{{ dbt_utils.current_timestamp_in_utc() }} as expected
{{ dbt_utils.current_timestamp_in_utc() }} as expected
11 changes: 3 additions & 8 deletions integration_tests/models/cross_db_utils/test_date_trunc.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@

with data as (

select * from {{ ref('data_date_trunc') }}

)
with data as (select * from {{ ref("data_date_trunc") }})

select
cast({{dbt_utils.date_trunc('day', 'updated_at') }} as date) as actual,
cast({{ dbt_utils.date_trunc("day", "updated_at") }} as date) as actual,
day as expected

from data

union all

select
cast({{ dbt_utils.date_trunc('month', 'updated_at') }} as date) as actual,
cast({{ dbt_utils.date_trunc("month", "updated_at") }} as date) as actual,
month as expected

from data
35 changes: 25 additions & 10 deletions integration_tests/models/cross_db_utils/test_dateadd.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@

with data as (

select * from {{ ref('data_dateadd') }}

)
with data as (select * from {{ ref("data_dateadd") }})

select
case
when datepart = 'hour' then cast({{ dbt_utils.dateadd('hour', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}})
when datepart = 'day' then cast({{ dbt_utils.dateadd('day', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}})
when datepart = 'month' then cast({{ dbt_utils.dateadd('month', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}})
when datepart = 'year' then cast({{ dbt_utils.dateadd('year', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}})
when datepart = 'hour'
then
cast(
{{ dbt_utils.dateadd("hour", "interval_length", "from_time") }}
as {{ dbt_utils.type_timestamp() }}
)
when datepart = 'day'
then
cast(
{{ dbt_utils.dateadd("day", "interval_length", "from_time") }}
as {{ dbt_utils.type_timestamp() }}
)
when datepart = 'month'
then
cast(
{{ dbt_utils.dateadd("month", "interval_length", "from_time") }}
as {{ dbt_utils.type_timestamp() }}
)
when datepart = 'year'
then
cast(
{{ dbt_utils.dateadd("year", "interval_length", "from_time") }}
as {{ dbt_utils.type_timestamp() }}
)
else null
end as actual,
result as expected
Expand Down
113 changes: 89 additions & 24 deletions integration_tests/models/cross_db_utils/test_datediff.sql
Original file line number Diff line number Diff line change
@@ -1,35 +1,100 @@

with data as (

select * from {{ ref('data_datediff') }}

)
with data as (select * from {{ ref("data_datediff") }})

select

case
when datepart = 'second' then {{ dbt_utils.datediff('first_date', 'second_date', 'second') }}
when datepart = 'minute' then {{ dbt_utils.datediff('first_date', 'second_date', 'minute') }}
when datepart = 'hour' then {{ dbt_utils.datediff('first_date', 'second_date', 'hour') }}
when datepart = 'day' then {{ dbt_utils.datediff('first_date', 'second_date', 'day') }}
when datepart = 'week' then {{ dbt_utils.datediff('first_date', 'second_date', 'week') }}
when datepart = 'month' then {{ dbt_utils.datediff('first_date', 'second_date', 'month') }}
when datepart = 'year' then {{ dbt_utils.datediff('first_date', 'second_date', 'year') }}
when datepart = 'second'
then {{ dbt_utils.datediff("first_date", "second_date", "second") }}
when datepart = 'minute'
then {{ dbt_utils.datediff("first_date", "second_date", "minute") }}
when datepart = 'hour'
then {{ dbt_utils.datediff("first_date", "second_date", "hour") }}
when datepart = 'day'
then {{ dbt_utils.datediff("first_date", "second_date", "day") }}
when datepart = 'week'
then {{ dbt_utils.datediff("first_date", "second_date", "week") }}
when datepart = 'month'
then {{ dbt_utils.datediff("first_date", "second_date", "month") }}
when datepart = 'year'
then {{ dbt_utils.datediff("first_date", "second_date", "year") }}
else null
end as actual,
result as expected

from data

-- Also test correct casting of literal values.

union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "microsecond") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "millisecond") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "second") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "minute") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "hour") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "day") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-03 00:00:00.000000'", "week") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "month") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "quarter") }} as actual, 1 as expected
union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "year") }} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'",
"'2000-01-01 00:00:00.000000'",
"microsecond",
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'",
"'2000-01-01 00:00:00.000000'",
"millisecond",
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "second"
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "minute"
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "hour"
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "day"
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-03 00:00:00.000000'", "week"
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "month"
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "quarter"
)
}} as actual, 1 as expected
union all
select
{{
dbt_utils.datediff(
"'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "year"
)
}} as actual, 1 as expected
11 changes: 2 additions & 9 deletions integration_tests/models/cross_db_utils/test_hash.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
with data as (select * from {{ ref("data_hash") }})

with data as (

select * from {{ ref('data_hash') }}

)

select
{{ dbt_utils.hash('input_1') }} as actual,
output as expected
select {{ dbt_utils.hash("input_1") }} as actual, output as expected

from data
16 changes: 7 additions & 9 deletions integration_tests/models/cross_db_utils/test_last_day.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

with data as (

select * from {{ ref('data_last_day') }}

)
with data as (select * from {{ ref("data_last_day") }})

select
case
when date_part = 'month' then {{ dbt_utils.last_day('date_day', 'month') }}
when date_part = 'quarter' then {{ dbt_utils.last_day('date_day', 'quarter') }}
when date_part = 'year' then {{ dbt_utils.last_day('date_day', 'year') }}
when date_part = 'month'
then {{ dbt_utils.last_day("date_day", "month") }}
when date_part = 'quarter'
then {{ dbt_utils.last_day("date_day", "quarter") }}
when date_part = 'year'
then {{ dbt_utils.last_day("date_day", "year") }}
else null
end as actual,
result as expected
Expand Down
13 changes: 3 additions & 10 deletions integration_tests/models/cross_db_utils/test_length.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
with data as (
with data as (select * from {{ ref("data_length") }})

select * from {{ ref('data_length') }}
select {{ dbt_utils.length("expression") }} as actual, output as expected

)

select

{{ dbt_utils.length('expression') }} as actual,
output as expected

from data
from data
Loading