Skip to content

Commit

Permalink
Create BQ version of string_literal with correct quoting (dbt-labs#1089)
Browse files Browse the repository at this point in the history
* Create BQ version of string_literal with correct quoting

* Fix macro for whitespace and add test.

---------

Co-authored-by: dave-connors-3 <[email protected]>
Co-authored-by: Mike Alfare <[email protected]>
Co-authored-by: Mila Page <[email protected]>
Co-authored-by: Mila Page <[email protected]>
  • Loading branch information
5 people authored Apr 17, 2024
1 parent bd1eb66 commit 55689b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240205-102954.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix dbt.string_literal for BQ when there are newlines
time: 2024-02-05T10:29:54.145326+01:00
custom:
Author: b-per
Issue: "1088"
3 changes: 3 additions & 0 deletions dbt/include/bigquery/macros/utils/string_literal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{%- macro bigquery__string_literal(value) -%}
'''{{ value }}'''
{%- endmacro -%}
17 changes: 17 additions & 0 deletions tests/functional/adapter/test_string_literal_macro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest
from dbt.tests.util import run_dbt


_MODEL_SQL = """
select {{ dbt.string_literal('my multiline
string') }} as test
"""


class TestStringLiteralQuoting:
@pytest.fixture(scope="class")
def models(self):
return {"my_model.sql": _MODEL_SQL}

def test_string_literal_quoting(self, project):
run_dbt()

0 comments on commit 55689b9

Please sign in to comment.