From 28a9d0995207ffa40ed051bfb631ee32a7ae4412 Mon Sep 17 00:00:00 2001 From: Grace Goheen <53586774+graciegoheen@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:09:38 -0700 Subject: [PATCH] add escape_single_quotes macro (#573) * add escape_single_quotes macro * added changelog entry * Trim trailing whitespace * Trim trailing whitespace Co-authored-by: Doug Beatty --- .changes/unreleased/Fixes-20221221-092410.yaml | 8 ++++++++ dbt/include/spark/macros/utils/escape_single_quotes.sql | 4 ++++ tests/functional/adapter/utils/test_utils.py | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixes-20221221-092410.yaml create mode 100644 dbt/include/spark/macros/utils/escape_single_quotes.sql 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