Skip to content

Conversation

@turboFei
Copy link
Member

@turboFei turboFei commented Jan 5, 2021

Backport below PR as dependencies:
#25018

#27321

#28393

#27920

wangyum and others added 4 commits January 5, 2021 17:35
…ithin quoted string literals

This pr port [HIVE-15297](https://issues.apache.org/jira/browse/HIVE-15297) to fix **spark-sql** should not split semicolon within quoted string literals.

unit tests and manual tests:
![image](https://user-images.githubusercontent.com/5399861/60395592-5666ea00-9b68-11e9-99dc-0e8ea98de32b.png)

Closes apache#25018 from wangyum/SPARK-26321.

Authored-by: Yuming Wang <[email protected]>
Signed-off-by: Yuming Wang <[email protected]>
…hed quote character

A SQL statement that contains a comment with an unmatched quote character can lead to a parse error:
- Added a insideComment flag in the splitter method to avoid checking single and double quotes within a comment:
```
spark-sql> SELECT 1 -- someone's comment here
         > ;
Error in query:
extraneous input ';' expecting <EOF>(line 2, pos 0)

== SQL ==
SELECT 1 -- someone's comment here
;
^^^
```

This misbehaviour was not present on previous spark versions.

- No

- New tests were added.

Closes apache#27321 from javierivanov/SPARK-30049B.

Lead-authored-by: Javier <[email protected]>
Co-authored-by: Javier Fuentes <[email protected]>
Signed-off-by: Thomas Graves <[email protected]>
…ted string

### What changes were proposed in this pull request?
`def splitSemiColon` cannot handle unescaped quote mark like "'" or '"' correctly. When there are unmatched quotes in a string, `splitSemiColon` will not drop off semicolon as expected.

### Why are the changes needed?
Some regex expression will use quote mark in string. We should process semicolon correctly.

### Does this PR introduce any user-facing change?
No

### How was this patch tested?
Added Unit test and also manual test.

Closes apache#28393 from adrian-wang/unescaped.

Authored-by: Daoyuan Wang <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
This PR introduces a change to false for the insideComment flag on a newline. Fixing the issue introduced by SPARK-30049.

Previously on SPARK-30049 a comment containing an unclosed quote produced the following issue:
```
spark-sql> SELECT 1 -- someone's comment here
         > ;
Error in query:
extraneous input ';' expecting <EOF>(line 2, pos 0)

== SQL ==
SELECT 1 -- someone's comment here
;
^^^
```

This was caused because there was no flag for comment sections inside the splitSemiColon method to ignore quotes. SPARK-30049 added that flag and fixed the issue, but introduced the follwoing problem:
```
spark-sql> select
         >   1,
         >   -- two
         >   2;
Error in query:
mismatched input '<EOF>' expecting {'(', 'ADD', 'AFTER', 'ALL', 'ALTER', ...}(line 3, pos 2)
== SQL ==
select
  1,
--^^^
```
This issue is generated by a missing turn-off for the insideComment flag with a newline.

No

- For previous tests using line-continuity(`\`) it was added a line-continuity rule in the SqlBase.g4 file to add the functionality to the SQL context.
- A new test for inline comments was added.

Closes apache#27920 from javierivanov/SPARK-31102.

Authored-by: Javier Fuentes <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
@turboFei
Copy link
Member Author

turboFei commented Jan 5, 2021

gentle ping @maropu

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

…park-sql

Now the spark-sql does not support parse the sql statements with bracketed comments.
For the sql statements:
```
/* SELECT 'test'; */
SELECT 'test';
```
Would be split to two statements:
The first one: `/* SELECT 'test'`
The second one: `*/ SELECT 'test'`

Then it would throw an exception because the first one is illegal.
In this PR, we ignore the content in bracketed comments while splitting the sql statements.
Besides, we ignore the comment without any content.

Spark-sql might split the statements inside bracketed comments and it is not correct.

No.

Added UT.

Closes apache#29982 from turboFei/SPARK-33110.

Lead-authored-by: fwang12 <[email protected]>
Co-authored-by: turbofei <[email protected]>
Signed-off-by: Takeshi Yamamuro <[email protected]>
runCliWithin(2.minute)(
"CREATE TEMPORARY VIEW t AS SELECT * FROM VALUES(1, 2) AS t(k, v);" -> "",
"EXPLAIN EXTENDED SELECT /*+ broadcast(t) */ * from t;"
-> "ResolvedHint (strategy=broadcast)"
Copy link
Member Author

Choose a reason for hiding this comment

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

because spark-2.4 does not support mergeJoin hint, so I modify this ut

@maropu
Copy link
Member

maropu commented Jan 5, 2021

I will close this for now and see the comment: #31033 (comment)

@maropu maropu closed this Jan 5, 2021
@maropu maropu changed the title [SPARK-33100][SQL] Ignore a semicolon inside a bracketed comment in spark-sql [SPARK-33100][SQL][2.4] Ignore a semicolon inside a bracketed comment in spark-sql Jan 5, 2021
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.

6 participants