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 #1206

Merged
merged 25 commits into from
Feb 7, 2023

Conversation

MitchellGale
Copy link
Contributor

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

#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.

MitchellGale and others added 20 commits November 8, 2022 15:30
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Also removed unused StringUtils function

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Escape character support for string literals
@MitchellGale MitchellGale requested a review from a team as a code owner December 22, 2022 01:11
@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2022

Codecov Report

Merging #1206 (16de714) into main (18661b4) will decrease coverage by 2.48%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##               main    #1206      +/-   ##
============================================
- Coverage     98.32%   95.83%   -2.49%     
  Complexity     3552     3552              
============================================
  Files           346      356      +10     
  Lines          8756     9414     +658     
  Branches        554      673     +119     
============================================
+ Hits           8609     9022     +413     
- Misses          142      334     +192     
- Partials          5       58      +53     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 98.32% <ø> (ø)

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

Impacted Files Coverage Δ
workbench/public/components/PPLPage/PPLPage.tsx 56.52% <0.00%> (ø)
workbench/public/components/SQLPage/SQLPage.tsx 100.00% <0.00%> (ø)
workbench/public/utils/PanelWrapper.tsx 100.00% <0.00%> (ø)
workbench/public/application.tsx 0.00% <0.00%> (ø)
workbench/public/components/Main/main.tsx 53.00% <0.00%> (ø)
workbench/public/components/Header/Header.tsx 100.00% <0.00%> (ø)
...ublic/components/QueryResults/QueryResultsBody.tsx 68.32% <0.00%> (ø)
...ch/public/components/QueryResults/QueryResults.tsx 61.60% <0.00%> (ø)
...h/public/components/QueryLanguageSwitch/Switch.tsx 85.71% <0.00%> (ø)
workbench/public/components/app.tsx 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
Signed-off-by: MitchellGale-BitQuill <mitchellg@bitquilltech.com>
@dai-chen dai-chen added enhancement New feature or request backport 2.x labels Dec 23, 2022
@Yury-Fridlyand Yury-Fridlyand requested a review from penghuo January 4, 2023 01:38
@Yury-Fridlyand
Copy link
Collaborator

Isn't a breaking change?

@acarbonetto
Copy link
Collaborator

Isn't a breaking change?

Yes. This should not be a backport change.

@penghuo
Copy link
Collaborator

penghuo commented Jan 25, 2023

could you add more context about breacking change in PR. then during release stage, we can organice all the breaking changes in release notes.

@Yury-Fridlyand
Copy link
Collaborator

1. Add a test index:

curl -X POST "localhost:9200/dbg/_doc/?pretty" -H 'Content-Type: application/json' -d '{"someText": "\\1\\\\2\\\\\\3\\\\\\\\4\\\\\\\\\\5\\\\\\\\\\\\6"}'

(actually there are 1..6 backslashes, but they are escaped)

2. Run a query (without this fix):

opensearchsql> select * from dbg;
fetched rows / total rows = 1/1
+-----------------------------+
| someText                    |
|-----------------------------|
| \1\\2\\\3\\\\4\\\\\5\\\\\\6 |
+-----------------------------+
opensearchsql> select * from dbg where someText = "\1\\2\\\3\\\\4\\\\\5\\\\\\6";
fetched rows / total rows = 1/1
+-----------------------------+
| someText                    |
|-----------------------------|
| \1\\2\\\3\\\\4\\\\\5\\\\\\6 |
+-----------------------------+
opensearchsql> select * from dbg where someText = "\\1\\\\2\\\\\\3\\\\\\\\4\\\\\\\\\\5\\\\\\\\\\\\6";
fetched rows / total rows = 0/0
+------------+
| someText   |
|------------|
+------------+

3. Checkout this PR, build and install

4. Run the query again (with this fix):

opensearchsql> select * from dbg;
fetched rows / total rows = 1/1
+-----------------------------+
| someText                    |
|-----------------------------|
| \1\\2\\\3\\\\4\\\\\5\\\\\\6 |
+-----------------------------+
opensearchsql> select * from dbg where someText = "\1\\2\\\3\\\\4\\\\\5\\\\\\6";
fetched rows / total rows = 0/0
+------------+
| someText   |
|------------|
+------------+
opensearchsql> select * from dbg where someText = "\\1\\\\2\\\\\\3\\\\\\\\4\\\\\\\\\\5\\\\\\\\\\\\6";
fetched rows / total rows = 1/1
+-----------------------------+
| someText                    |
|-----------------------------|
| \1\\2\\\3\\\\4\\\\\5\\\\\\6 |
+-----------------------------+

5. Delete the index:

curl -XDELETE 'http://localhost:9200/dbg'

This PR affects how string literals processed only. Values are still returned as is, without processing escape sequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking enhancement New feature or request v3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants