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

Escape character support for string literals #159

Merged
merged 17 commits into from
Dec 22, 2022

Conversation

MitchellGale
Copy link

@MitchellGale MitchellGale commented Nov 9, 2022

Description

Adds support for escape characters \ to be used to escape characters in string literals. Keeps support for double quote to act as an escape if the surrounding quote is matching type (single quote, or double quote).

SELECT "Hello", 'Hello', "It""s", 'It''s', "It's", '"Its"', 'It\'s', 'It\\\'s', "\I\t\s"
fetched rows / total rows = 1/1
+-----------+-----------+-----------+-----------+----------+-----------+-----------+-------------+------------+
| "Hello"   | 'Hello'   | "It""s"   | 'It''s'   | "It's"   | '"Its"'   | 'It\'s'   | 'It\\\'s'   | "\I\t\s"   |
|-----------+-----------+-----------+-----------+----------+-----------+-----------+-------------+------------|
| Hello     | Hello     | It"s      | It's      | It's     | "Its"     | It's      | It\'s       | \I\t\s     |
+-----------+-----------+-----------+-----------+----------+-----------+-----------+-------------+------------+

Issues Resolved

opensearch-project#297

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
@codecov
Copy link

codecov bot commented Nov 9, 2022

Codecov Report

Merging #159 (01f5338) into Integ-escapeCharacters (7a3372e) will not change coverage.
The diff coverage is n/a.

❗ Current head 01f5338 differs from pull request most recent head 251231d. Consider uploading reports for the commit 251231d to get more accurate results

@@                    Coverage Diff                    @@
##             Integ-escapeCharacters     #159   +/-   ##
=========================================================
  Coverage                     98.31%   98.31%           
  Complexity                     3524     3524           
=========================================================
  Files                           342      342           
  Lines                          8711     8711           
  Branches                        555      555           
=========================================================
  Hits                           8564     8564           
  Misses                          142      142           
  Partials                          5        5           
Flag Coverage Δ
sql-engine 98.31% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Signed-off-by: MitchellGale-BitQuill <[email protected]>
@MitchellGale
Copy link
Author

MySQL doesn't support with back ticks for doing fancy escape stuff, but the old implementation did. What should we go with?

Also removed unused StringUtils function

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
build.gradle Outdated Show resolved Hide resolved
if (currentChar == enclosingQuote
&& nextChar == currentChar) {

if ((currentChar == '\\'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic here is very hard to follow (containing both && and || and lots of brackets. I'd suggest simplifying it.

May have one if statement for currentChar == '\\' and another for currentChar == enclosingQuote

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely need to put a set of brackets around

currentChar == nextChar
          && currentChar == enclosingQuote



public class StringLiteralIT extends SQLIntegTestCase {
// @Test

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
if (currentChar == enclosingQuote
&& nextChar == currentChar) {

if ((currentChar == '\\'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely need to put a set of brackets around

currentChar == nextChar
          && currentChar == enclosingQuote

@GumpacG
Copy link

GumpacG commented Dec 20, 2022

Does this make that test in TDVT pass? Might be good to check as that is the issue being solved by this PR.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
Signed-off-by: MitchellGale-BitQuill <[email protected]>
@MitchellGale MitchellGale merged commit 78c1fda into Integ-escapeCharacters Dec 22, 2022
@MaxKsyunz MaxKsyunz deleted the dev-escapeCharacters branch December 22, 2022 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants