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

Matt Wang commented on CALCITE-3243:
------------------------------------

[~zabetak]

I think the error was thrown in validate phase. I run this test

```java
 tester.checkString("json_value(true, 'strict $.foo' default 'empty' on 
error)", "empty", "VARCHAR(2000)");
```
 which throws exception like this:

```sh
 org.apache.calcite.runtime.CalciteContextException: From line 1, column 20 to 
line 1, column 23: Cannot apply 'JSON_VALUE_EXPRESSION' to arguments of type 
'JSON_VALUE_EXPRESSION(<BOOLEAN>)'. Supported form(s): 
'JSON_VALUE_EXPRESSION(<STRING>)'

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:463)
 at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:787)
 at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:772)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:4816)
 at 
org.apache.calcite.sql.SqlCallBinding.newValidationSignatureError(SqlCallBinding.java:280)
 at 
org.apache.calcite.sql.type.FamilyOperandTypeChecker.checkSingleOperandType(FamilyOperandTypeChecker.java:92)
 at 
org.apache.calcite.sql.type.FamilyOperandTypeChecker.checkOperandTypes(FamilyOperandTypeChecker.java:109)
 at org.apache.calcite.sql.SqlOperator.checkOperandTypes(SqlOperator.java:665)
 at org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:432)
 at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:515)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5575)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5562)
 at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1661)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1646)
 at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236)
 at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5279)
 at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:116)
 at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235)
 at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
 at org.apache.calcite.sql.SqlFunction.validateCall(SqlFunction.java:196)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5279)
 at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:116)
 at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235)
 at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5279)
 at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:116)
 at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235)
 at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5279)
 at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:116)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:943)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:637)
 at 
org.apache.calcite.sql.test.AbstractSqlTester.parseAndValidate(AbstractSqlTester.java:172)
 at 
org.apache.calcite.sql.test.AbstractSqlTester.getResultType(AbstractSqlTester.java:157)
 at 
org.apache.calcite.sql.test.AbstractSqlTester.getColumnType(AbstractSqlTester.java:149)
 at 
org.apache.calcite.sql.test.AbstractSqlTester.check(AbstractSqlTester.java:466)
 at 
org.apache.calcite.sql.test.SqlOperatorBaseTest$TesterImpl.check(SqlOperatorBaseTest.java:8170)
 at 
org.apache.calcite.sql.test.AbstractSqlTester.check(AbstractSqlTester.java:451)
 at 
org.apache.calcite.sql.test.AbstractSqlTester.checkString(AbstractSqlTester.java:436)
 at 
org.apache.calcite.sql.test.SqlOperatorBaseTest.testJsonValue(SqlOperatorBaseTest.java:4365)
 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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
 at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
 at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
 at org.junit.runners.Suite.runChild(Suite.java:128)
 at org.junit.runners.Suite.runChild(Suite.java:27)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
 at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
 at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
 at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply 
'JSON_VALUE_EXPRESSION' to arguments of type 
'JSON_VALUE_EXPRESSION(<BOOLEAN>)'. Supported form(s): 
'JSON_VALUE_EXPRESSION(<STRING>)'
 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:463)
 at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
 ... 72 more
 ```

> Incomplete validation of operands in JSON functions  
> -----------------------------------------------------
>
>                 Key: CALCITE-3243
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3243
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.20.0
>            Reporter: Stamatis Zampetakis
>            Priority: Major
>
> The operands of various JSON functions are not validated correctly. 
> Consider for instance the {{JSON_VALUE}} function and the following calls:
> {code:sql}
> json_value('{\"foo\":100}', 'strict $.foo')"
> json_value(1, 'strict $.foo')"
> json_value(TRUE, 'strict $.foo')"
> {code}
> The first call is legal but the next are not; if I am not wrong the operands 
> should be always CHAR or VARCHAR literals which is not the case above.
> Queries involving such calls fail at runtime when compiling generated code. I 
> guess that such kind of problems should be captured by the validator and we 
> should not even arrive at the code generation step.
> The problems can be easily reproduced by adding such calls in the 
> {{SqlOperatorBaseTest}}.
> The problem does not only affect {{JSON_VALUE}} but other JSON functions 
> (such as {{JSON_QUERY}} etc.) as well. 



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to