[jira] [Commented] (CALCITE-2885) SqlValidatorImpl fails when processing an InferTypes.FIRST_KNOWN function containing a function with a dynamic parameter as first operand
[ https://issues.apache.org/jira/browse/CALCITE-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17026547#comment-17026547 ] Ruben Q L commented on CALCITE-2885: Thanks for your comment [~jinxing6...@126.com], it's been a while since I logged this issue, I need to remind the specifics. I'll take a look at your suggestion. > SqlValidatorImpl fails when processing an InferTypes.FIRST_KNOWN function > containing a function with a dynamic parameter as first operand > - > > Key: CALCITE-2885 > URL: https://issues.apache.org/jira/browse/CALCITE-2885 > Project: Calcite > Issue Type: Bug >Affects Versions: 1.18.0 >Reporter: Ruben Q L >Priority: Major > > Problem can be reproduced by adding following tests (e.g. to > SqlValidatorDynamicTest.java): > {code:java} > @Test public void testDynamicParameter1() throws Exception { > final String sql = "select 4 = 2*?"; > sql(sql).ok(); > } > @Test public void testDynamicParameter2() throws Exception { > final String sql = "select 2*? = 4"; > sql(sql).ok(); > } > {code} > The first test will run successfully, but the second one (which is the same > query reversing the equality operands) will fail with the exception: > {code} > org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply '*' to > arguments of type ' * '. Supported form(s): ' * > ' ' * ' ' * > ' > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (CALCITE-2885) SqlValidatorImpl fails when processing an InferTypes.FIRST_KNOWN function containing a function with a dynamic parameter as first operand
[ https://issues.apache.org/jira/browse/CALCITE-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17023793#comment-17023793 ] Jin Xing commented on CALCITE-2885: --- Hi, Ruben ~ I also came across this issue. *FIRST_KNOWN* infers operand types by calling *deriveType* on operands. In your case (+_select 2 * ? = 4_+), when deriving operand types for *EQUALS* function, type of the dynamic param in *MULTIPLY* is not inferred yet, thus the deriving failed for validation[1][2]. To my best knowledge, type validation might be not needed when infer operand types – – we will do operand type validation anyway after operand type inference. I'm thinking that shall we have a switch to control whether to bypass type validation in *SqlValidatorImpl#deriveType* ? We can disable the type validation during operand type inference and enable afterwards. But note that this change is not trivial – – public methods will be changed to add param for switching. [1][https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/SqlOperator.java#L534] [2][https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/SqlOperator.java#L448] > SqlValidatorImpl fails when processing an InferTypes.FIRST_KNOWN function > containing a function with a dynamic parameter as first operand > - > > Key: CALCITE-2885 > URL: https://issues.apache.org/jira/browse/CALCITE-2885 > Project: Calcite > Issue Type: Bug >Affects Versions: 1.18.0 >Reporter: Ruben Q L >Priority: Major > > Problem can be reproduced by adding following tests (e.g. to > SqlValidatorDynamicTest.java): > {code:java} > @Test public void testDynamicParameter1() throws Exception { > final String sql = "select 4 = 2*?"; > sql(sql).ok(); > } > @Test public void testDynamicParameter2() throws Exception { > final String sql = "select 2*? = 4"; > sql(sql).ok(); > } > {code} > The first test will run successfully, but the second one (which is the same > query reversing the equality operands) will fail with the exception: > {code} > org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply '*' to > arguments of type ' * '. Supported form(s): ' * > ' ' * ' ' * > ' > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (CALCITE-2885) SqlValidatorImpl fails when processing an InferTypes.FIRST_KNOWN function containing a function with a dynamic parameter as first operand
[ https://issues.apache.org/jira/browse/CALCITE-2885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16781526#comment-16781526 ] Ruben Quesada Lopez commented on CALCITE-2885: -- I think what is happening here is that the SqlOperandTypeInference FIRST_KNOWN of the equals function would try to infer its parameters' type evaluating its operands and taking the first "non-unknown" type. In our second test (the one which fails), it would try to get the type from the MULTIPLY function using callBinding.getValidator().deriveType(callBinding.getScope(), operand). This deriveType will eventually call the MULTIPLY validateOperands method, and since there is an unknown parameter (the dynamic one), it will fail. If we reversed the equality, as in the first test, the problem did not happen because the SqlOperandTypeInference FIRST_KNOWN will never call the MULTIPLY derive type, since it will break before as soon as it derived the type from the numeric literal. Right after, the SqlValidatorImpl will call inferUnknownTypes for the equals' operands (which was not called in the previous case), and that was the key, because that method will infer and store inside the nodeToTypeMap that the dynamic parameter's type; and later, the MULTIPLY operands validation will not fail. > SqlValidatorImpl fails when processing an InferTypes.FIRST_KNOWN function > containing a function with a dynamic parameter as first operand > - > > Key: CALCITE-2885 > URL: https://issues.apache.org/jira/browse/CALCITE-2885 > Project: Calcite > Issue Type: Bug >Affects Versions: 1.18.0 >Reporter: Ruben Quesada Lopez >Priority: Major > > Problem can be reproduced by adding following tests (e.g. to > SqlValidatorDynamicTest.java): > {code:java} > @Test public void testDynamicParameter1() throws Exception { > final String sql = "select 4 = 2*?"; > sql(sql).ok(); > } > @Test public void testDynamicParameter2() throws Exception { > final String sql = "select 2*? = 4"; > sql(sql).ok(); > } > {code} > The first test will run successfully, but the second one (which is the same > query reversing the equals operands) will fail with the exception: > {code} > org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply '*' to > arguments of type ' * '. Supported form(s): ' * > ' > ' * ' > ' * ' > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)