Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -9475,7 +9475,6 @@ PlainSelect PlainSelect() #PlainSelect:
OracleHierarchicalExpression oracleHierarchicalQueryClause = null;
PreferringClause preferringClause = null;
ExpressionList expressionList = null;
boolean partitionByBrackets = false;
List<Table> intoTables = null;
MySqlSelectIntoClause mySqlSelectIntoClause = null;
MySqlProcedureAnalyse mySqlProcedureAnalyse = null;
Expand Down Expand Up @@ -9581,13 +9580,9 @@ PlainSelect PlainSelect() #PlainSelect:
[ LOOKAHEAD(2) oracleHierarchicalQueryClause=OracleHierarchicalQueryClause() { plainSelect.setOracleHierarchical(oracleHierarchicalQueryClause); } ]
[ LOOKAHEAD(2) preferringClause=PreferringClause() { plainSelect.setPreferringClause(preferringClause); }
[LOOKAHEAD(2) <K_PARTITION> <K_BY>
(
LOOKAHEAD(2) expressionList=ComplexExpressionList()
|
"(" {partitionByBrackets = true;} expressionList=ComplexExpressionList() ")"
)
expressionList=ComplexExpressionList()
{
preferringClause.setPartitionExpressionList(expressionList, partitionByBrackets);
preferringClause.setPartitionExpressionList(expressionList, false);
}
]
]
Expand Down Expand Up @@ -14463,7 +14458,6 @@ JsonAggregateFunction JsonAggregateFunction() : {
ExpressionList expressionList = null;
List<OrderByElement> olist = null;
WindowElement windowElement = null;
boolean partitionByBrackets = false;
}
{
(
Expand Down Expand Up @@ -14550,13 +14544,12 @@ JsonAggregateFunction JsonAggregateFunction() : {
<K_OVER> {result.setAnalyticType(AnalyticType.OVER);}
"("
[<K_PARTITION> <K_BY>
(LOOKAHEAD(3) expressionList=ComplexExpressionList()
| "(" {partitionByBrackets = true;} expressionList=ComplexExpressionList() ")" )
expressionList=ComplexExpressionList()
]
[olist=OrderByElements() ]
[windowElement = WindowElement() ]
{
result.setPartitionExpressionList(expressionList, partitionByBrackets);
result.setPartitionExpressionList(expressionList, false);
result.setOrderByElements(olist);
result.setWindowElement(windowElement);
}
Expand Down Expand Up @@ -14698,7 +14691,6 @@ KeepExpression KeepExpression() : {

void windowFun(AnalyticExpression retval):{
ExpressionList expressionList = null;
boolean partitionByBrackets = false;
String windowName = null;
WindowDefinition winDef;
} {
Expand All @@ -14722,10 +14714,9 @@ void windowFun(AnalyticExpression retval):{
[
LOOKAHEAD(2) <K_OVER> "("
[ <K_PARTITION> <K_BY>
(LOOKAHEAD(3) expressionList=ComplexExpressionList()
| "(" {partitionByBrackets = true;} expressionList=ComplexExpressionList() ")" )
expressionList=ComplexExpressionList()
]
")" { winDef.setPartitionExpressionList(expressionList, partitionByBrackets); retval.setType(AnalyticType.WITHIN_GROUP_OVER); }
")" { winDef.setPartitionExpressionList(expressionList, false); retval.setType(AnalyticType.WITHIN_GROUP_OVER); }
]
)
}
Expand All @@ -14734,7 +14725,6 @@ WindowDefinition windowDefinition() : {
ExpressionList expressionList = null;
List<OrderByElement> olist = null;
WindowElement windowElement = null;
boolean partitionByBrackets = false;
WindowDefinition winDef = new WindowDefinition();
String baseWindowName;
} {
Expand All @@ -14748,13 +14738,12 @@ WindowDefinition windowDefinition() : {
{}
)
[<K_PARTITION> <K_BY>
(LOOKAHEAD(3) expressionList=ComplexExpressionList()
| "(" {partitionByBrackets = true;} expressionList=ComplexExpressionList() ")" )
expressionList=ComplexExpressionList()
]
[olist=OrderByElements() ]
[windowElement = WindowElement() ]
{
winDef.setPartitionExpressionList(expressionList, partitionByBrackets);
winDef.setPartitionExpressionList(expressionList, false);
winDef.setOrderByElements(olist);
winDef.setWindowElement(windowElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,23 @@ void testDatabricks() throws JSQLParserException {

TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
void testPartitionByBracketedOperand() throws JSQLParserException {
TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT SUM(x) OVER (PARTITION BY (1 + a) / 2 ORDER BY b) FROM t", true);

TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT SUM(x) OVER w FROM t WINDOW w AS (PARTITION BY (1 + a) / 2)", true);

TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT LISTAGG(x, ',') WITHIN GROUP (ORDER BY y) OVER (PARTITION BY (1 + a) / 2) FROM t",
true);

TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT * FROM t PREFERRING HIGH x PARTITION BY (1 + a) / 2", true);

TestUtils.assertSqlCanBeParsedAndDeparsed(
"SELECT SUM(x) OVER (PARTITION BY (a, b), c) FROM t", true);
}
}
Loading