Skip to content

Commit

Permalink
add escape_single_quotes macro (#573)
Browse files Browse the repository at this point in the history
* add escape_single_quotes macro

* added changelog entry

* Trim trailing whitespace

* Trim trailing whitespace

Co-authored-by: Doug Beatty <doug.beatty@dbtlabs.com>
  • Loading branch information
graciegoheen and dbeatty10 authored Jan 11, 2023
1 parent d9a3d76 commit 28a9d09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changes/unreleased/Fixes-20221221-092410.yaml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions dbt/include/spark/macros/utils/escape_single_quotes.sql
Original file line number Diff line number Diff line change
@@ -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 %}
2 changes: 1 addition & 1 deletion tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class TestDateTrunc(BaseDateTrunc):
pass


class TestEscapeSingleQuotes(BaseEscapeSingleQuotesQuote):
class TestEscapeSingleQuotes(BaseEscapeSingleQuotesBackslash):
pass


Expand Down

0 comments on commit 28a9d09

Please sign in to comment.