diff --git a/.changes/unreleased/Fixes-20221221-092410.yaml b/.changes/unreleased/Fixes-20221221-092410.yaml new file mode 100644 index 000000000..1aa8001f2 --- /dev/null +++ b/.changes/unreleased/Fixes-20221221-092410.yaml @@ -0,0 +1,8 @@ +kind: Fixes +body: Added escape_single_quotes macro as Spark/Databricks uses a single backslash + instead of a single quote +time: 2022-12-21T09:24:10.952042-06:00 +custom: + Author: graciegoheen + Issue: "572" + PR: "573" diff --git a/dbt/include/spark/macros/utils/escape_single_quotes.sql b/dbt/include/spark/macros/utils/escape_single_quotes.sql new file mode 100644 index 000000000..2572ffb69 --- /dev/null +++ b/dbt/include/spark/macros/utils/escape_single_quotes.sql @@ -0,0 +1,4 @@ +{# /* Spark/Databricks uses a single backslash: they're -> they\'re. The second backslash is to escape it from Jinja */ #} +{% macro spark__escape_single_quotes(expression) -%} +{{ expression | replace("'","\\'") }} +{%- endmacro %} diff --git a/tests/functional/adapter/utils/test_utils.py b/tests/functional/adapter/utils/test_utils.py index 102df731a..6fd6a9121 100644 --- a/tests/functional/adapter/utils/test_utils.py +++ b/tests/functional/adapter/utils/test_utils.py @@ -79,7 +79,7 @@ class TestDateTrunc(BaseDateTrunc): pass -class TestEscapeSingleQuotes(BaseEscapeSingleQuotesQuote): +class TestEscapeSingleQuotes(BaseEscapeSingleQuotesBackslash): pass