Uh oh!
There was an error while loading. Please reload this page.
[SPARK-19951][SQL] Add string concatenate operator || to Spark SQL - #17711
[SPARK-19951][SQL] Add string concatenate operator || to Spark SQL#17711maropu wants to merge 11 commits into
Conversation
There was a problem hiding this comment.
isn't this just expression(exprs)?
There was a problem hiding this comment.
oh, I missed.. you're right. I'll fix
rxin
commented
Apr 21, 2017
can you add a test case in sql query file tests? |
SparkQA
commented
Apr 21, 2017
Test build #76009 has finished for PR 17711 at commit
|
maropu
commented
Apr 21, 2017
okay, I'll add soon. |
There was a problem hiding this comment.
Please move this to the end of the file. It can minimize the code changes.
There was a problem hiding this comment.
Because you do Concat(exprs.map(expression)), isn't it Concat(UnresolvedAttribute("a") :: UnresolvedAttribute("b") :: UnresolvedAttribute("c") :: Nil)?
There was a problem hiding this comment.
oh. I see. But I think we may simplify nested Concats in visitConcat.
There was a problem hiding this comment.
aha, I'll re-think a bit more, thanks!
SparkQA
commented
Apr 21, 2017
Test build #76010 has finished for PR 17711 at commit
|
SparkQA
commented
Apr 21, 2017
Test build #76016 has started for PR 17711 at commit |
SparkQA
commented
Apr 21, 2017
Test build #76014 has finished for PR 17711 at commit
|
maropu
commented
Apr 21, 2017
Jenkins, retest this please. |
There was a problem hiding this comment.
Can you move this to the CatalystSqlParser?
There was a problem hiding this comment.
Should we move this to the head of the primaryExpression rule? That seems easier.
I am also trying to figure how this works with other binary operators, for example: a + b || c.
There was a problem hiding this comment.
If we do you suggested, we need to write a rule like primaryExpression (CONCAT_PIPE primaryExpression)+ to avoid left-recursive. But, IIUC this rule parses a || b || c into Concat(a, Concat(b, c))`. So, I fixed in the current way from the suggestion of @viirya.
There was a problem hiding this comment.
Currently, it seems we have the same behaviour with mysql;
mysql> select 1 + 2 || '3';
+--------------+
| 1 + 2 || '3' |
+--------------+
| 24 |
+--------------+
1 row in set (0.00 sec)
postgres=# select 1 + 2 || '3';
?column? ----------
33
(1 row)
scala> sql("""select 1 + 2 || '3'""").show
+------------------------------------------------------------------+
|(CAST(1 AS DOUBLE) + CAST(concat(CAST(2 AS STRING), 3) AS DOUBLE))|
+------------------------------------------------------------------+
| 24.0|
+------------------------------------------------------------------+
There was a problem hiding this comment.
Could you add the test cases to check whether we correctly follow the precedence like Oracle?
Ref: https://docs.oracle.com/cd/A87860_01/doc/server.817/a85397/operator.htm#1003584
There was a problem hiding this comment.
ok. Sorry, but l'll update in a few days because I'm on vacation..
There was a problem hiding this comment.
This is interesting...So seems mysql and postgres has different precedence for it.
SparkQA
commented
Apr 21, 2017
Test build #76020 has finished for PR 17711 at commit
|
SparkQA
commented
Apr 21, 2017
Test build #76030 has finished for PR 17711 at commit
|
maropu
commented
Apr 22, 2017
ping |
maropu
commented
Apr 24, 2017
@hvanhovell ping |
SparkQA
commented
May 8, 2017
Test build #76578 has finished for PR 17711 at commit
|
SparkQA
commented
May 8, 2017
Test build #76580 has finished for PR 17711 at commit
|
maropu
commented
May 8, 2017
Jenkins, retest this please. |
SparkQA
commented
May 9, 2017
Test build #76597 has finished for PR 17711 at commit
|
maropu
commented
May 9, 2017
This failure seems unrelated to this pr? (other prs also hit the same R test failure...). |
maropu
commented
May 9, 2017
Jenkins, retest this please. |
maropu
commented
May 9, 2017
The R test failure seemed to be fixed in 2abfee1 |
SparkQA
commented
May 9, 2017
Test build #76606 has finished for PR 17711 at commit
|
| /** | ||
| * Collapse nested [[Concat]] expressions. | ||
| */ |
There was a problem hiding this comment.
Please move it to org.apache.spark.sql.catalyst.optimizer.expressions.scala
| CollapseRepartition, | ||
| CollapseProject, | ||
| CollapseWindow, | ||
| CollapseConcat, |
There was a problem hiding this comment.
This is not part of Operator combine. Maybe move it to the spot around SimplifyCasts
| }) | ||
| } | ||
| } | ||
| * Collapse nested [[Concat]] expressions. | ||
| */ | ||
| object CollapseConcat extends Rule[LogicalPlan] { | ||
There was a problem hiding this comment.
tail recursion? or using queue/stack?
gatorsmile
commented
May 11, 2017
Please follow the other optimizer rules. We need to add a optimizer test suite. For example, |
This reverts commit c88652c.
SparkQA
commented
May 11, 2017
Test build #76795 has finished for PR 17711 at commit
|
| select 5 % 3; | ||
| select pmod(-7, 3); | ||
| -- check operator precedence |
There was a problem hiding this comment.
Could you add the precedence rules we follow in the comments?
gatorsmile
commented
May 11, 2017
LGTM pending minor comment. We need to add an extra optimizer rule to combine the adjacent concatenate expressions. Thanks! |
maropu
commented
May 12, 2017
I quickly brushed up the Optimizer code based on your advice: Using I checked the spark style-guide and I probably think we'd better to use more readable one. So, |
SparkQA
commented
May 12, 2017
Test build #76840 has finished for PR 17711 at commit
|
There was a problem hiding this comment.
The link could be ineffective in the future. Could you also copy the table contents here? Thanks!
gatorsmile
commented
May 12, 2017
@maropu The solution using |
I feel both are pretty complicated. Can we just do something similar to CombineUnion: It's going to be simpler because you don't need to handle distinct here. |
maropu
commented
May 12, 2017
@rxin ok, thank for the suggestion! |
SparkQA
commented
May 12, 2017
Test build #76850 has started for PR 17711 at commit |
maropu
commented
May 12, 2017
Jenkins, retest this please. |
SparkQA
commented
May 12, 2017
Test build #76856 has finished for PR 17711 at commit
|
gatorsmile
commented
May 12, 2017
Thanks! Merging to master. |
## What changes were proposed in this pull request? This pr added a new Optimizer rule to combine nested Concat. The master supports a pipeline operator '||' to concatenate strings in apache#17711 (This pr is follow-up). Since the parser currently generates nested Concat expressions, the optimizer needs to combine the nested expressions. ## How was this patch tested? Added tests in `CombineConcatSuite` and `SQLQueryTestSuite`. Author: Takeshi Yamamuro <yamamuro@apache.org> Closesapache#17970 from maropu/SPARK-20730.
## What changes were proposed in this pull request? This pr added code to support `||` for string concatenation. This string operation is supported in PostgreSQL and MySQL. ## How was this patch tested? Added tests in `SparkSqlParserSuite` Author: Takeshi Yamamuro <yamamuro@apache.org> Closesapache#17711 from maropu/SPARK-19951.
## What changes were proposed in this pull request? This pr added a new Optimizer rule to combine nested Concat. The master supports a pipeline operator '||' to concatenate strings in apache#17711 (This pr is follow-up). Since the parser currently generates nested Concat expressions, the optimizer needs to combine the nested expressions. ## How was this patch tested? Added tests in `CombineConcatSuite` and `SQLQueryTestSuite`. Author: Takeshi Yamamuro <yamamuro@apache.org> Closesapache#17970 from maropu/SPARK-20730.
## What changes were proposed in this pull request? This pr added code to support `||` for string concatenation. This string operation is supported in PostgreSQL and MySQL. ## How was this patch tested? Added tests in `SparkSqlParserSuite` Author: Takeshi Yamamuro <yamamuro@apache.org> Closesapache#17711 from maropu/SPARK-19951.
## What changes were proposed in this pull request? This pr added a new Optimizer rule to combine nested Concat. The master supports a pipeline operator '||' to concatenate strings in apache#17711 (This pr is follow-up). Since the parser currently generates nested Concat expressions, the optimizer needs to combine the nested expressions. ## How was this patch tested? Added tests in `CombineConcatSuite` and `SQLQueryTestSuite`. Author: Takeshi Yamamuro <yamamuro@apache.org> Closesapache#17970 from maropu/SPARK-20730.
This pr added code to support `||` for string concatenation. This string operation is supported in PostgreSQL and MySQL. Added tests in `SparkSqlParserSuite` Author: Takeshi Yamamuro <yamamuro@apache.org> Closesapache#17711 from maropu/SPARK-19951.
What changes were proposed in this pull request?
This pr added code to support
||for string concatenation. This string operation is supported in PostgreSQL and MySQL.How was this patch tested?
Added tests in
SparkSqlParserSuite