[ 
https://issues.apache.org/jira/browse/CALCITE-6245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17815075#comment-17815075
 ] 

Benchao Li commented on CALCITE-6245:
-------------------------------------

In calcite, in jira title we usually describe the symptom of the problem 
instead of the way how to fix it, and it's suggested to keep it the same with 
the commit message, you can see more here: 
https://calcite.apache.org/develop/#contributing

> Permute operands of SqlCall when validating and Converting to Rel
> -----------------------------------------------------------------
>
>                 Key: CALCITE-6245
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6245
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Feng Jin
>            Assignee: Feng Jin
>            Priority: Major
>
> Currently, when using named parameters, there may be some issues due to the 
> incorrect expansion of named parameters during validation. Specifically, 
> several unit tests can be added to reproduce this.
> add a test case 
> org.apache.calcite.test.UdfTest#testScalarFunctionWithParameter
> {code:java}
>   @Test void testScalarFunctionWithParameter() {
>     final String sql = "select \"adhoc\".my_det_plus(X => \"deptno\", Y => 
> 100) as p\n"
>         + "from \"adhoc\".EMPLOYEES";
>     final AtomicInteger c = 
> Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
>     final int before = c.get();
>     withUdf().query(sql).returnsUnordered("P=110",
>         "P=120",
>         "P=110",
>         "P=110");
>     final int after = c.get();
>     assertThat(after, is(before + 1));
>   }
> {code}
> And we will get the following error:
> {code:java}
> java.sql.SQLException: Error while executing SQL "select 
> "adhoc".my_det_plus(x => "deptno", y => 100) as p
> from "adhoc".EMPLOYEES": At line 1, column 28: Column 'X' not found in any 
> table
>       at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
>       at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
>       at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:164)
>       at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:228)
>       at 
> org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:543)
>       at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.lambda$returns$1(CalciteAssert.java:1455)
>       at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.withConnection(CalciteAssert.java:1394)
>       at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1453)
>       at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1443)
>       at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returnsUnordered(CalciteAssert.java:1465)
>       at 
> org.apache.calcite.test.UdfTest.testScalarFunctionWithParameter(UdfTest.java:227)
> {code}
> another test case:
> org.apache.calcite.test.UdfTest#testAggFunctionWithParameter
> {code:java}
>   @Test void testAggFunctionWithParameter() {
>     final String empDept = JdbcTest.EmpDeptTableFactory.class.getName();
>     final String sum = Smalls.MyStaticSumFunction.class.getName();
>     final String sum2 = Smalls.MySumFunction.class.getName();
>     final CalciteAssert.AssertThat with = CalciteAssert.model("{\n"
>             + "  version: '1.0',\n"
>             + "   schemas: [\n"
>             + "     {\n"
>             + "       name: 'adhoc',\n"
>             + "       tables: [\n"
>             + "         {\n"
>             + "           name: 'EMPLOYEES',\n"
>             + "           type: 'custom',\n"
>             + "           factory: '" + empDept + "',\n"
>             + "           operand: {'foo': true, 'bar': 345}\n"
>             + "         }\n"
>             + "       ],\n"
>             + "       functions: [\n"
>             + "         {\n"
>             + "           name: 'MY_SUM',\n"
>             + "           className: '" + sum + "'\n"
>             + "         },\n"
>             + "         {\n"
>             + "           name: 'MY_SUM2',\n"
>             + "           className: '" + sum2 + "'\n"
>             + "         }\n"
>             + "       ]\n"
>             + "     }\n"
>             + "   ]\n"
>             + "}")
>         .withDefaultSchema("adhoc")
>         .with("caseSensitive", false);
>     with.withDefaultSchema(null)
>         .query(
>             "select \"adhoc\".my_sum(arg1  => \"deptno\") as p from 
> \"adhoc\".EMPLOYEES\n")
>         .returns("P=50\n");
>   }
> {code}
> And we will get the following error:
> {code:java}
> // Some comments here
> Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, 
> column 23 to line 1, column 26: Column 'ARG1' not found in any table
>       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>       at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
>       at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:505)
>       at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:945)
>       at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:930)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5470)
>       at 
> org.apache.calcite.sql.validate.DelegatingScope.fullyQualify(DelegatingScope.java:289)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.findTableColumnPair(SqlValidatorImpl.java:3929)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumn(SqlValidatorImpl.java:3972)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(SqlValidatorImpl.java:3885)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(SqlValidatorImpl.java:3880)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(SqlValidatorImpl.java:3880)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(SqlValidatorImpl.java:3899)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInSelectList(SqlValidatorImpl.java:3801)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3789)
>       at 
> org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:61)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to