Skip to content

Commit

Permalink
[CALCITE-6502] Parser loses position information for Expression3
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
mihaibudiu committed Jul 30, 2024
1 parent cc1d6b9 commit ad66246
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
26 changes: 7 additions & 19 deletions core/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -3810,8 +3810,12 @@ List<Object> Expression2(ExprContext exprContext) :
AddExpression2b(list, ExprContext.ACCEPT_SUB_QUERY)
|
<LBRACKET>
itemOp = getItemOp()
e = Expression(ExprContext.ACCEPT_SUB_QUERY)
( <OFFSET> { itemOp = SqlLibraryOperators.OFFSET; } <LPAREN> { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } <RPAREN>
| <ORDINAL> { itemOp = SqlLibraryOperators.ORDINAL; } <LPAREN> { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } <RPAREN>
| <SAFE_OFFSET> { itemOp = SqlLibraryOperators.SAFE_OFFSET; } <LPAREN> { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } <RPAREN>
| <SAFE_ORDINAL> { itemOp = SqlLibraryOperators.SAFE_ORDINAL; } <LPAREN> { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } <RPAREN>
| { itemOp = SqlStdOperatorTable.ITEM; } e = Expression(ExprContext.ACCEPT_SUB_QUERY)
)
<RBRACKET> {
list.add(
new SqlParserUtil.ToTreeListItem(
Expand Down Expand Up @@ -3846,22 +3850,6 @@ List<Object> Expression2(ExprContext exprContext) :
)
}

/** Returns the appropriate ITEM operator for indexing arrays. */
SqlOperator getItemOp() :
{
}
{
<OFFSET> { return SqlLibraryOperators.OFFSET; }
|
<ORDINAL> { return SqlLibraryOperators.ORDINAL; }
|
<SAFE_OFFSET> { return SqlLibraryOperators.SAFE_OFFSET; }
|
<SAFE_ORDINAL> { return SqlLibraryOperators.SAFE_ORDINAL; }
|
{ return SqlStdOperatorTable.ITEM; }
}

/** Parses a comparison operator inside a SOME / ALL predicate. */
SqlKind comp() :
{
Expand Down Expand Up @@ -3980,7 +3968,7 @@ SqlNode Expression3(ExprContext exprContext) :
{
if (list1.size() == 1) {
// interpret as single value or query
return list1.get(0);
return list1.get(0).clone(list1.getParserPosition());
} else {
// interpret as row constructor
return SqlStdOperatorTable.ROW.createCall(span().end(list1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5364,7 +5364,7 @@ void testReturnsCorrectRowTypeOnCombinedJoin() {

@Test void testJoinOnScalarFails() {
final String sql = "select * from emp as e join dept d\n"
+ "on d.deptno = (^select 1, 2 from emp where deptno < e.deptno^)";
+ "on d.deptno = ^(select 1, 2 from emp where deptno < e.deptno)^";
final String expected = "(?s)Cannot apply '\\$SCALAR_QUERY' to arguments "
+ "of type '\\$SCALAR_QUERY\\(<RECORDTYPE\\(INTEGER EXPR\\$0, INTEGER "
+ "EXPR\\$1\\)>\\)'\\. Supported form\\(s\\).*";
Expand Down Expand Up @@ -6154,7 +6154,7 @@ public boolean isBangEqualAllowed() {
.withConformance(strict).fails("Column 'DNO' not found in any table")
.withConformance(lenient).ok();
sql("select deptno as dno, ename name, sum(sal) from emp\n"
+ "group by grouping sets ((^dno^), (name, deptno))")
+ "group by grouping sets (^(dno)^, (name, deptno))")
.withConformance(strict).fails("Column 'DNO' not found in any table")
.withConformance(lenient).ok();
sql("select ename as deptno from emp as e join dept as d on "
Expand Down Expand Up @@ -8283,7 +8283,7 @@ void testGroupExpressionEquivalenceParams() {

@Test void testScalarSubQuery() {
sql("SELECT ename,(select name from dept where deptno=1) FROM emp").ok();
sql("SELECT ename,(^select losal, hisal from salgrade where grade=1^) FROM emp")
sql("SELECT ename,^(select losal, hisal from salgrade where grade=1)^ FROM emp")
.fails("Cannot apply '\\$SCALAR_QUERY' to arguments of type "
+ "'\\$SCALAR_QUERY\\(<RECORDTYPE\\(INTEGER LOSAL, "
+ "INTEGER HISAL\\)>\\)'\\. Supported form\\(s\\): "
Expand Down Expand Up @@ -11515,7 +11515,7 @@ private void checkCustomColumnResolving(String table) {
sql("select (select ^slackingmin^ from emp_r), a from (select empno as a from emp_r)")
.fails(error);

sql("select (((^slackingmin^))) from emp_r")
sql("select ^(((slackingmin)))^ from emp_r")
.fails(error);

sql("select ^slackingmin^ from nest.emp_r")
Expand Down

0 comments on commit ad66246

Please sign in to comment.