-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-19951][SQL] Add string concatenate operator || to Spark SQL #17711
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5544ff2
Add string concatenate operator || to Spark SQL
maropu 05d490e
Apply comments
maropu afcd950
Apply review comments
maropu f89d131
Brush up parsing rules
maropu 5957545
Move the logic to CatalystSqlParser
maropu cb4b26e
Make the concat precedence the same with +/-
maropu 8890b94
Remove arithmetic.sq.out
maropu df3869a
Rename files
maropu c88652c
Add a new rule to collapse multiple concats in Optimizer
maropu 96db575
Revert "Add a new rule to collapse multiple concats in Optimizer"
maropu de89791
Add comments
maropu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
sql/core/src/test/resources/sql-tests/inputs/arithmetic.sql
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
sql/core/src/test/resources/sql-tests/inputs/operators.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
|
|
||
| -- unary minus and plus | ||
| select -100; | ||
| select +230; | ||
| select -5.2; | ||
| select +6.8e0; | ||
| select -key, +key from testdata where key = 2; | ||
| select -(key + 1), - key + 1, +(key + 5) from testdata where key = 1; | ||
| select -max(key), +max(key) from testdata; | ||
| select - (-10); | ||
| select + (-key) from testdata where key = 32; | ||
| select - (+max(key)) from testdata; | ||
| select - - 3; | ||
| select - + 20; | ||
| select + + 100; | ||
| select - - max(key) from testdata; | ||
| select + - key from testdata where key = 33; | ||
|
|
||
| -- div | ||
| select 5 / 2; | ||
| select 5 / 0; | ||
| select 5 / null; | ||
| select null / 5; | ||
| select 5 div 2; | ||
| select 5 div 0; | ||
| select 5 div null; | ||
| select null div 5; | ||
|
|
||
| -- other arithmetics | ||
| select 1 + 2; | ||
| select 1 - 2; | ||
| select 2 * 5; | ||
| select 5 % 3; | ||
| select pmod(-7, 3); | ||
|
|
||
| -- check operator precedence. | ||
| -- We follow Oracle operator precedence in the table below that lists the levels of precedence | ||
| -- among SQL operators from high to low: | ||
| ------------------------------------------------------------------------------------------ | ||
| -- Operator Operation | ||
| ------------------------------------------------------------------------------------------ | ||
| -- +, - identity, negation | ||
| -- *, / multiplication, division | ||
| -- +, -, || addition, subtraction, concatenation | ||
| -- =, !=, <, >, <=, >=, IS NULL, LIKE, BETWEEN, IN comparison | ||
| -- NOT exponentiation, logical negation | ||
| -- AND conjunction | ||
| -- OR disjunction | ||
| ------------------------------------------------------------------------------------------ | ||
| explain select 'a' || 1 + 2; | ||
| explain select 1 - 2 || 'b'; | ||
| explain select 2 * 4 + 3 || 'b'; | ||
| explain select 3 + 1 || 'a' || 4 / 2; | ||
| explain select 1 == 1 OR 'a' || 'b' == 'ab'; | ||
| explain select 'a' || 'c' == 'ac' AND 2 == 3; |
3 changes: 3 additions & 0 deletions
3
sql/core/src/test/resources/sql-tests/inputs/string-functions.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| -- Argument number exception | ||
| select concat_ws(); | ||
| select format_string(); | ||
|
|
||
| -- A pipe operator for string concatenation | ||
| select 'a' || 'b' || 'c'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is tricky to combine sequential
Concatin parser, maybe we can do it in optimizer later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha, I see. WDYT, @gatorsmile ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I prefer to simpler codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'll try to add a new rule for that. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I am thinking is a follow PR to add the rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I also feel so. Is it okay to remove the rule from this pr? @gatorsmile. If ok, I'll fix the points you reviewed in follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted, thanks