Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-1701] [CT-1700] [Bug] escape_single_quotes is not correct for Spark/Databricks #572

Closed
2 tasks done
b-per opened this issue Dec 21, 2022 · 2 comments · Fixed by #573
Closed
2 tasks done

[CT-1701] [CT-1700] [Bug] escape_single_quotes is not correct for Spark/Databricks #572

b-per opened this issue Dec 21, 2022 · 2 comments · Fixed by #573
Labels
bug Something isn't working good_first_issue Good for newcomers

Comments

@b-per
Copy link
Contributor

b-per commented Dec 21, 2022

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

Currently, escape_single_quotes() is dispatched to {{ expression | replace("'","''") }} for all adapters.

In Spark and Databricks single quotes need to be escaped with \\' (see here) instead of ''.

We fixed the behavior in dbt_project_evaluator but it should most likely be fixed in Core.

Expected Behavior

Single quotes are correctly escaped in Spark/Databricks

Steps To Reproduce

Use {{ dbt.escape_single_quotes("ab'c") }} in Spark/Databricks. The result is abc instead of ab'c

Relevant log output

No response

Environment

No response

Which database adapter are you using with dbt?

spark

Additional Context

No response

@b-per b-per added bug Something isn't working triage labels Dec 21, 2022
@github-actions github-actions bot changed the title [Bug] escape_single_quotes is not correct for Spark/Databricks [CT-1700] [Bug] escape_single_quotes is not correct for Spark/Databricks Dec 21, 2022
@dbeatty10
Copy link
Contributor

Thank you for reporting this @b-per !

Do you or @graciegoheen (or anyone else) have interest in submitting the fix?

It's quite simple:

  1. Create a file named dbt/include/spark/macros/utils/escape_single_quotes.sql with contents similar to here and here (basically the same as the project_evaluator implementation)
  2. Update this line to have BaseEscapeSingleQuotesBackslash instead of BaseEscapeSingleQuotesQuote (like here and here)

@dbeatty10 dbeatty10 transferred this issue from dbt-labs/dbt-core Dec 21, 2022
@github-actions github-actions bot changed the title [CT-1700] [Bug] escape_single_quotes is not correct for Spark/Databricks [CT-1701] [CT-1700] [Bug] escape_single_quotes is not correct for Spark/Databricks Dec 21, 2022
@graciegoheen
Copy link
Contributor

I can take this one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good_first_issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants