diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 6ba01c6dd05..be994d260bb 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -3810,8 +3810,12 @@ List Expression2(ExprContext exprContext) : AddExpression2b(list, ExprContext.ACCEPT_SUB_QUERY) | - itemOp = getItemOp() - e = Expression(ExprContext.ACCEPT_SUB_QUERY) + ( { itemOp = SqlLibraryOperators.OFFSET; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlLibraryOperators.ORDINAL; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlLibraryOperators.SAFE_OFFSET; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlLibraryOperators.SAFE_ORDINAL; } { e = Expression(ExprContext.ACCEPT_SUB_QUERY); } + | { itemOp = SqlStdOperatorTable.ITEM; } e = Expression(ExprContext.ACCEPT_SUB_QUERY) + ) { list.add( new SqlParserUtil.ToTreeListItem( @@ -3846,22 +3850,6 @@ List Expression2(ExprContext exprContext) : ) } -/** Returns the appropriate ITEM operator for indexing arrays. */ -SqlOperator getItemOp() : -{ -} -{ - { return SqlLibraryOperators.OFFSET; } -| - { return SqlLibraryOperators.ORDINAL; } -| - { return SqlLibraryOperators.SAFE_OFFSET; } -| - { return SqlLibraryOperators.SAFE_ORDINAL; } -| - { return SqlStdOperatorTable.ITEM; } -} - /** Parses a comparison operator inside a SOME / ALL predicate. */ SqlKind comp() : { @@ -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), diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java index 3e7164765a3..927274d21c6 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -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\\(\\)'\\. Supported form\\(s\\).*"; @@ -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 " @@ -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\\(\\)'\\. Supported form\\(s\\): " @@ -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")