Skip to content

Commit

Permalink
Merge pull request #121 from fishtown-analytics/feature/fix-right-bug
Browse files Browse the repository at this point in the history
made changes to right() function
  • Loading branch information
jthandy authored Feb 26, 2019
2 parents ce8daeb + 1c3934a commit 3be8b25
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion integration_tests/data/cross_db/data_right.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
string_text,length_expression,output
abcdef,3,def
fishtown,4,town
december,5,ember
december,5,ember
december,0,
2 changes: 1 addition & 1 deletion integration_tests/models/cross_db_utils/test_right.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ with data as (
select

{{ dbt_utils.right('string_text', 'length_expression') }} as actual,
output as expected
coalesce(output, '') as expected

from data
25 changes: 21 additions & 4 deletions macros/cross_db_utils/right.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,26 @@

{% macro bigquery__right(string_text, length_expression) %}

substr(
{{ string_text }},
-1 * ({{ length_expression }})
)
case when {{ length_expression }} = 0
then ''
else
substr(
{{ string_text }},
-1 * ({{ length_expression }})
)
end

{%- endmacro -%}

{% macro snowflake__right(string_text, length_expression) %}

case when {{ length_expression }} = 0
then ''
else
right(
{{ string_text }},
{{ length_expression }}
)
end

{%- endmacro -%}

0 comments on commit 3be8b25

Please sign in to comment.