Skip to content
Snippets Groups Projects
Commit cfe1ba56 authored by Liang-Chi Hsieh's avatar Liang-Chi Hsieh Committed by Davies Liu
Browse files

[SPARK-12687] [SQL] Support from clause surrounded by `()`.

JIRA: https://issues.apache.org/jira/browse/SPARK-12687

Some queries such as `(select 1 as a) union (select 2 as a)` can't work. This patch fixes it.

Author: Liang-Chi Hsieh <viirya@gmail.com>

Closes #10660 from viirya/fix-union.
parent b9c83533
No related branches found
No related tags found
No related merge requests found
......@@ -151,8 +151,8 @@ fromSource
@after { gParent.popMsg(state); }
:
(LPAREN KW_VALUES) => fromSource0
| (LPAREN) => LPAREN joinSource RPAREN -> joinSource
| fromSource0
| (LPAREN joinSource) => LPAREN joinSource RPAREN -> joinSource
;
......
......@@ -2216,6 +2216,8 @@ regularBody[boolean topLevel]
selectStatement[boolean topLevel]
:
(
(
LPAREN
s=selectClause
f=fromClause?
w=whereClause?
......@@ -2227,6 +2229,20 @@ selectStatement[boolean topLevel]
sort=sortByClause?
win=window_clause?
l=limitClause?
RPAREN
|
s=selectClause
f=fromClause?
w=whereClause?
g=groupByClause?
h=havingClause?
o=orderByClause?
c=clusterByClause?
d=distributeByClause?
sort=sortByClause?
win=window_clause?
l=limitClause?
)
-> ^(TOK_QUERY $f? ^(TOK_INSERT ^(TOK_DESTINATION ^(TOK_DIR TOK_TMP_FILE))
$s $w? $g? $h? $o? $c?
$d? $sort? $win? $l?))
......@@ -2241,7 +2257,10 @@ selectStatement[boolean topLevel]
setOpSelectStatement[CommonTree t, boolean topLevel]
:
(u=setOperator b=simpleSelectStatement
((
u=setOperator LPAREN b=simpleSelectStatement RPAREN
|
u=setOperator b=simpleSelectStatement)
-> {$setOpSelectStatement.tree != null && $u.tree.getType()==SparkSqlParser.TOK_UNIONDISTINCT}?
^(TOK_QUERY
^(TOK_FROM
......
......@@ -28,5 +28,9 @@ class CatalystQlSuite extends PlanTest {
paresr.createPlan("select * from t1 union select * from t2")
paresr.createPlan("select * from t1 except select * from t2")
paresr.createPlan("select * from t1 intersect select * from t2")
paresr.createPlan("(select * from t1) union all (select * from t2)")
paresr.createPlan("(select * from t1) union distinct (select * from t2)")
paresr.createPlan("(select * from t1) union (select * from t2)")
paresr.createPlan("select * from ((select * from t1) union (select * from t2)) t")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment