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

[SPARK-12577] [SQL] Better support of parentheses in partition by and order by...

[SPARK-12577] [SQL] Better support of parentheses in partition by and order by clause of window function's over clause

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

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

Closes #10620 from viirya/fix-parentheses.
parent 090d6913
No related branches found
No related tags found
No related merge requests found
......@@ -223,7 +223,12 @@ precedenceUnaryPrefixExpression
;
precedenceUnarySuffixExpression
: precedenceUnaryPrefixExpression (a=KW_IS nullCondition)?
:
(
(LPAREN precedenceUnaryPrefixExpression RPAREN) => LPAREN precedenceUnaryPrefixExpression (a=KW_IS nullCondition)? RPAREN
|
precedenceUnaryPrefixExpression (a=KW_IS nullCondition)?
)
-> {$a != null}? ^(TOK_FUNCTION nullCondition precedenceUnaryPrefixExpression)
-> precedenceUnaryPrefixExpression
;
......
......@@ -20,17 +20,33 @@ package org.apache.spark.sql.catalyst
import org.apache.spark.sql.catalyst.plans.PlanTest
class CatalystQlSuite extends PlanTest {
val parser = new CatalystQl()
test("parse union/except/intersect") {
val paresr = new CatalystQl()
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 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")
parser.createPlan("select * from t1 union all select * from t2")
parser.createPlan("select * from t1 union distinct select * from t2")
parser.createPlan("select * from t1 union select * from t2")
parser.createPlan("select * from t1 except select * from t2")
parser.createPlan("select * from t1 intersect select * from t2")
parser.createPlan("(select * from t1) union all (select * from t2)")
parser.createPlan("(select * from t1) union distinct (select * from t2)")
parser.createPlan("(select * from t1) union (select * from t2)")
parser.createPlan("select * from ((select * from t1) union (select * from t2)) t")
}
test("window function: better support of parentheses") {
parser.createPlan("select sum(product + 1) over (partition by ((1) + (product / 2)) " +
"order by 2) from windowData")
parser.createPlan("select sum(product + 1) over (partition by (1 + (product / 2)) " +
"order by 2) from windowData")
parser.createPlan("select sum(product + 1) over (partition by ((product / 2) + 1) " +
"order by 2) from windowData")
parser.createPlan("select sum(product + 1) over (partition by ((product) + (1)) order by 2) " +
"from windowData")
parser.createPlan("select sum(product + 1) over (partition by ((product) + 1) order by 2) " +
"from windowData")
parser.createPlan("select sum(product + 1) over (partition by (product + (1)) order by 2) " +
"from windowData")
}
}
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