[jira] [Closed] (CALCITE-6246) Unable to find the correct function signature when using named parameters with omitting arguments

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin closed CALCITE-6246.
-
Resolution: Not A Bug

> Unable to find the correct function signature when using named parameters 
> with omitting arguments
> -
>
> Key: CALCITE-6246
> URL: https://issues.apache.org/jira/browse/CALCITE-6246
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Feng Jin
>Assignee: Feng Jin
>Priority: Major
>
> When we use named parameters, if a non-mandatory parameter is omitted, it 
> will be automatically filled with a DEFAULT node. However, the default return 
> type of the DEFAULT node is ANY. This will cause some issues when inferring 
> the function signature.
> Take the unit test below as an example.
> org.apache.calcite.test.UdfTest#testScalarFunctionWithParameterWithOptional
> {code:java}
> // Some comments here
>   @Test void testScalarFunctionWithParameterWithOptional() {
> final String sql = "select \"adhoc\".my_det_plus() as p\n"
> + "from \"adhoc\".EMPLOYEES";
> final AtomicInteger c = 
> Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
> final int before = c.get();
> withUdf()
> .with("caseSensitive", false)
> .query(sql).returnsUnordered("P=110",
> "P=120",
> "P=110",
> "P=110");
> final int after = c.get();
> assertThat(after, is(before + 1));
>   }
> {code}
> We will get the following error:
> {code:shell}
> java.sql.SQLException: Error while executing SQL "select 
> "adhoc".my_det_plus() as p
> from "adhoc".EMPLOYEES": From line 1, column 16 to line 1, column 28: No 
> match found for function signature MY_DET_PLUS()
>   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.testScalarFunctionWithParameterWithOptional(UdfTest.java:242)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at 
> org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
>   at 
> org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
>   at 
> org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
>   at 
> 

[jira] [Commented] (CALCITE-6246) Unable to find the correct function signature when using named parameters with omitting arguments

2024-02-06 Thread Feng Jin (Jira)


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

Feng Jin commented on CALCITE-6246:
---

[~eveywu] Thank you for your reply. I have confirmed that the example I 
provided above cannot be reproduced. 

The reason for the above exception is that I did not set the second parameter 
of MY_DET_PLUS as optional. In fact, we encountered this problem in Flink, 
which may be related to Flink's implementation. 

I will close this issue first until I find a more appropriate way to reproduce 
it.

> Unable to find the correct function signature when using named parameters 
> with omitting arguments
> -
>
> Key: CALCITE-6246
> URL: https://issues.apache.org/jira/browse/CALCITE-6246
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Feng Jin
>Assignee: Feng Jin
>Priority: Major
>
> When we use named parameters, if a non-mandatory parameter is omitted, it 
> will be automatically filled with a DEFAULT node. However, the default return 
> type of the DEFAULT node is ANY. This will cause some issues when inferring 
> the function signature.
> Take the unit test below as an example.
> org.apache.calcite.test.UdfTest#testScalarFunctionWithParameterWithOptional
> {code:java}
> // Some comments here
>   @Test void testScalarFunctionWithParameterWithOptional() {
> final String sql = "select \"adhoc\".my_det_plus() as p\n"
> + "from \"adhoc\".EMPLOYEES";
> final AtomicInteger c = 
> Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
> final int before = c.get();
> withUdf()
> .with("caseSensitive", false)
> .query(sql).returnsUnordered("P=110",
> "P=120",
> "P=110",
> "P=110");
> final int after = c.get();
> assertThat(after, is(before + 1));
>   }
> {code}
> We will get the following error:
> {code:shell}
> java.sql.SQLException: Error while executing SQL "select 
> "adhoc".my_det_plus() as p
> from "adhoc".EMPLOYEES": From line 1, column 16 to line 1, column 28: No 
> match found for function signature MY_DET_PLUS()
>   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.testScalarFunctionWithParameterWithOptional(UdfTest.java:242)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at 
> org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
>   at 
> org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
>   at 
> org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
> 

[jira] [Comment Edited] (CALCITE-6246) Unable to find the correct function signature when using named parameters with omitting arguments

2024-02-06 Thread Feng Jin (Jira)


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

Feng Jin edited comment on CALCITE-6246 at 2/7/24 7:43 AM:
---

[~eveywu] Thank you for your reply. I have confirmed that the example I 
provided above cannot reproduce the problem. 

The reason for the above exception is that I did not set the second parameter 
of MY_DET_PLUS as optional. In fact, we encountered this problem in Flink, 
which may be related to Flink's implementation. 

I will close this issue first until I find a more appropriate way to reproduce 
it.


was (Author: hackergin):
[~eveywu] Thank you for your reply. I have confirmed that the example I 
provided above cannot be reproduced. 

The reason for the above exception is that I did not set the second parameter 
of MY_DET_PLUS as optional. In fact, we encountered this problem in Flink, 
which may be related to Flink's implementation. 

I will close this issue first until I find a more appropriate way to reproduce 
it.

> Unable to find the correct function signature when using named parameters 
> with omitting arguments
> -
>
> Key: CALCITE-6246
> URL: https://issues.apache.org/jira/browse/CALCITE-6246
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Feng Jin
>Assignee: Feng Jin
>Priority: Major
>
> When we use named parameters, if a non-mandatory parameter is omitted, it 
> will be automatically filled with a DEFAULT node. However, the default return 
> type of the DEFAULT node is ANY. This will cause some issues when inferring 
> the function signature.
> Take the unit test below as an example.
> org.apache.calcite.test.UdfTest#testScalarFunctionWithParameterWithOptional
> {code:java}
> // Some comments here
>   @Test void testScalarFunctionWithParameterWithOptional() {
> final String sql = "select \"adhoc\".my_det_plus() as p\n"
> + "from \"adhoc\".EMPLOYEES";
> final AtomicInteger c = 
> Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
> final int before = c.get();
> withUdf()
> .with("caseSensitive", false)
> .query(sql).returnsUnordered("P=110",
> "P=120",
> "P=110",
> "P=110");
> final int after = c.get();
> assertThat(after, is(before + 1));
>   }
> {code}
> We will get the following error:
> {code:shell}
> java.sql.SQLException: Error while executing SQL "select 
> "adhoc".my_det_plus() as p
> from "adhoc".EMPLOYEES": From line 1, column 16 to line 1, column 28: No 
> match found for function signature MY_DET_PLUS()
>   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.testScalarFunctionWithParameterWithOptional(UdfTest.java:242)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at 
> org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
>   at 
> org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
>   at 
> org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
>   at 
> 

[jira] [Updated] (CALCITE-6246) Unable to find the correct function signature when using named parameters with omitting arguments

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin updated CALCITE-6246:
--
Description: 
When we use named parameters, if a non-mandatory parameter is omitted, it will 
be automatically filled with a DEFAULT node. However, the default return type 
of the DEFAULT node is ANY. This will cause some issues when inferring the 
function signature.

Take the unit test below as an example.

org.apache.calcite.test.UdfTest#testScalarFunctionWithParameterWithOptional

{code:java}
// Some comments here
  @Test void testScalarFunctionWithParameterWithOptional() {
final String sql = "select \"adhoc\".my_det_plus() as p\n"
+ "from \"adhoc\".EMPLOYEES";
final AtomicInteger c = 
Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
final int before = c.get();
withUdf()
.with("caseSensitive", false)
.query(sql).returnsUnordered("P=110",
"P=120",
"P=110",
"P=110");
final int after = c.get();
assertThat(after, is(before + 1));
  }
{code}


We will get the following error:


{code:shell}
java.sql.SQLException: Error while executing SQL "select "adhoc".my_det_plus() 
as p
from "adhoc".EMPLOYEES": From line 1, column 16 to line 1, column 28: No match 
found for function signature MY_DET_PLUS()
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.testScalarFunctionWithParameterWithOptional(UdfTest.java:242)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at 
org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at 
org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
at 
org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at 
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at 
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at 
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at 
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at 
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at 

[jira] [Updated] (CALCITE-6245) A ValidationError occurs when a named parameter is used on a ScalarFunction or AggregateFunction.

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6245?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin updated CALCITE-6245:
--
Description: 
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()
.with("caseSensitive", false)
.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 

[jira] [Updated] (CALCITE-6245) A ValidationError occurs when a named parameter is used on a ScalarFunction or AggregateFunction.

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6245?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin updated CALCITE-6245:
--
Component/s: core

> A ValidationError occurs when a named parameter is used on a ScalarFunction 
> or AggregateFunction.
> -
>
> Key: CALCITE-6245
> URL: https://issues.apache.org/jira/browse/CALCITE-6245
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>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 
> 

[jira] [Updated] (CALCITE-6246) Unable to find the correct function signature when using named parameters with omitting arguments

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin updated CALCITE-6246:
--
Summary: Unable to find the correct function signature when using named 
parameters with omitting arguments  (was: DEFAULT node returns argument type 
instead of ANY When using named parameter)

> Unable to find the correct function signature when using named parameters 
> with omitting arguments
> -
>
> Key: CALCITE-6246
> URL: https://issues.apache.org/jira/browse/CALCITE-6246
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Feng Jin
>Assignee: Feng Jin
>Priority: Major
>
> When we use named parameters, if a non-mandatory parameter is omitted, it 
> will be automatically filled with a DEFAULT node. However, the default return 
> type of the DEFAULT node is ANY. This will cause some issues when inferring 
> the function's type.
> Take the unit test below as an example.
> org.apache.calcite.test.UdfTest#testScalarFunctionWithParameterWithOptional
> {code:java}
> // Some comments here
>   @Test void testScalarFunctionWithParameterWithOptional() {
> final String sql = "select \"adhoc\".my_det_plus() as p\n"
> + "from \"adhoc\".EMPLOYEES";
> final AtomicInteger c = 
> Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
> final int before = c.get();
> withUdf()
> .with("caseSensitive", false)
> .query(sql).returnsUnordered("P=110",
> "P=120",
> "P=110",
> "P=110");
> final int after = c.get();
> assertThat(after, is(before + 1));
>   }
> {code}
> We will get the following error:
> {code:shell}
> java.sql.SQLException: Error while executing SQL "select 
> "adhoc".my_det_plus() as p
> from "adhoc".EMPLOYEES": From line 1, column 16 to line 1, column 28: No 
> match found for function signature MY_DET_PLUS()
>   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.testScalarFunctionWithParameterWithOptional(UdfTest.java:242)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at 
> org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
>   at 
> org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
>   at 
> org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
> 

[jira] [Commented] (CALCITE-6245) A ValidationError occurs when a named parameter is used on a ScalarFunction or AggregateFunction.

2024-02-06 Thread Feng Jin (Jira)


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

Feng Jin commented on CALCITE-6245:
---

[~libenchao]  Thank you for the suggestion. I updated the jira title. 

> A ValidationError occurs when a named parameter is used on a ScalarFunction 
> or AggregateFunction.
> -
>
> 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 
> 

[jira] [Updated] (CALCITE-6245) A ValidationError occurs when a named parameter is used on a ScalarFunction or AggregateFunction.

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6245?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin updated CALCITE-6245:
--
Summary: A ValidationError occurs when a named parameter is used on a 
ScalarFunction or AggregateFunction.  (was: Permute operands of SqlCall when 
validating and Converting to Rel)

> A ValidationError occurs when a named parameter is used on a ScalarFunction 
> or AggregateFunction.
> -
>
> 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 
> 

[jira] [Commented] (CALCITE-6245) Permute operands of SqlCall when validating and Converting to Rel

2024-02-06 Thread Feng Jin (Jira)


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

Feng Jin commented on CALCITE-6245:
---

Thanks [~libenchao],  the permission has taken effect

> 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 
> 

[jira] [Assigned] (CALCITE-6246) DEFAULT node returns argument type instead of ANY When using named parameter

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin reassigned CALCITE-6246:
-

Assignee: Feng Jin

> DEFAULT node returns argument type instead of ANY When using named parameter
> 
>
> Key: CALCITE-6246
> URL: https://issues.apache.org/jira/browse/CALCITE-6246
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Feng Jin
>Assignee: Feng Jin
>Priority: Major
>
> When we use named parameters, if a non-mandatory parameter is omitted, it 
> will be automatically filled with a DEFAULT node. However, the default return 
> type of the DEFAULT node is ANY. This will cause some issues when inferring 
> the function's type.
> Take the unit test below as an example.
> org.apache.calcite.test.UdfTest#testScalarFunctionWithParameterWithOptional
> {code:java}
> // Some comments here
>   @Test void testScalarFunctionWithParameterWithOptional() {
> final String sql = "select \"adhoc\".my_det_plus() as p\n"
> + "from \"adhoc\".EMPLOYEES";
> final AtomicInteger c = 
> Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
> final int before = c.get();
> withUdf()
> .with("caseSensitive", false)
> .query(sql).returnsUnordered("P=110",
> "P=120",
> "P=110",
> "P=110");
> final int after = c.get();
> assertThat(after, is(before + 1));
>   }
> {code}
> We will get the following error:
> {code:shell}
> java.sql.SQLException: Error while executing SQL "select 
> "adhoc".my_det_plus() as p
> from "adhoc".EMPLOYEES": From line 1, column 16 to line 1, column 28: No 
> match found for function signature MY_DET_PLUS()
>   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.testScalarFunctionWithParameterWithOptional(UdfTest.java:242)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at 
> org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
>   at 
> org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
>   at 
> org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
>   at 
> org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
>   at 
> org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
>   at 
> org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
>   at 
> 

[jira] [Commented] (CALCITE-6245) Permute operands of SqlCall when validating and Converting to Rel

2024-02-06 Thread Feng Jin (Jira)


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

Feng Jin commented on CALCITE-6245:
---

[~libenchao] I want to fix this. Please assign me this task.

> 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
>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 

[jira] [Created] (CALCITE-6246) DEFAULT node returns argument type instead of ANY When using named parameter

2024-02-06 Thread Feng Jin (Jira)
Feng Jin created CALCITE-6246:
-

 Summary: DEFAULT node returns argument type instead of ANY When 
using named parameter
 Key: CALCITE-6246
 URL: https://issues.apache.org/jira/browse/CALCITE-6246
 Project: Calcite
  Issue Type: Bug
  Components: core
Reporter: Feng Jin


When we use named parameters, if a non-mandatory parameter is omitted, it will 
be automatically filled with a DEFAULT node. However, the default return type 
of the DEFAULT node is ANY. This will cause some issues when inferring the 
function's type.

Take the unit test below as an example.

org.apache.calcite.test.UdfTest#testScalarFunctionWithParameterWithOptional

{code:java}
// Some comments here
  @Test void testScalarFunctionWithParameterWithOptional() {
final String sql = "select \"adhoc\".my_det_plus() as p\n"
+ "from \"adhoc\".EMPLOYEES";
final AtomicInteger c = 
Smalls.MyDeterministicPlusFunction.INSTANCE_COUNT.get();
final int before = c.get();
withUdf()
.with("caseSensitive", false)
.query(sql).returnsUnordered("P=110",
"P=120",
"P=110",
"P=110");
final int after = c.get();
assertThat(after, is(before + 1));
  }
{code}


We will get the following error:


{code:shell}
java.sql.SQLException: Error while executing SQL "select "adhoc".my_det_plus() 
as p
from "adhoc".EMPLOYEES": From line 1, column 16 to line 1, column 28: No match 
found for function signature MY_DET_PLUS()
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.testScalarFunctionWithParameterWithOptional(UdfTest.java:242)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at 
org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at 
org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
at 
org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at 
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at 
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at 
org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at 
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at 
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at 

[jira] [Updated] (CALCITE-6245) Permute operands of SqlCall when validating and Converting to Rel

2024-02-06 Thread Feng Jin (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6245?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Feng Jin updated CALCITE-6245:
--
Summary: Permute operands of SqlCall when validating and Converting to Rel  
(was: Permute operands of SqlCall everywhere when validating and Converting to 
Rel)

> 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
>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:shell}
> 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:shell}
> // 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 
> 

[jira] [Created] (CALCITE-6245) Permute operands of SqlCall everywhere when validating and Converting to Rel

2024-02-05 Thread Feng Jin (Jira)
Feng Jin created CALCITE-6245:
-

 Summary: Permute operands of SqlCall everywhere 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


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:shell}
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:shell}
// 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