[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
yuqi updated CALCITE-2053: -------------------------- Description: We define a udf function class have two function as follows {code:java} public double toDouble(Double var) { return var; } public double toDouble(BigDecimal var) { return var.doubleValue(); } {code} when use it in sql like: {code:sql} select sum(price) from tb; {code} where price is a double value in table tb, exception occurs: {code:java} java.lang.AssertionError: DECIMAL(19, 0) at org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154) at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592) at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371) at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358) at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592) at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577) 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:5081) at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) 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:5081) at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:901) at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:611) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:551) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:263) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:229) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:786) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221) at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603) at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149) at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218) at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:564) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1337) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1320) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1284) at org.apache.calcite.test.UdfTest.testDoubleAndDecimal(UdfTest.java:896) 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:497) {code} was: We define a udf function class have two function as follows {code:java} public double toDouble(Double var) { return var; } public double toDouble(BigDecimal var) { return var.doubleValue(); } {code} when use it in sql like: {code:sql} select sum(price) from tb; {code} where price is a double value in table tb, exception occurs: {code:java} java.lang.AssertionError: DECIMAL(19, 0) at org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154) at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592) at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371) at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358) at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592) at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577) 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:5081) at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) 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:5081) at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:901) at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:611) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:551) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:263) at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:229) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:786) at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640) at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610) at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221) at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603) at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149) at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218) at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:564) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1337) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1320) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1284) at org.apache.calcite.test.UdfTest.testDoubleAndDecimal(UdfTest.java:896) 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:497) 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.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.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) 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:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) {code} > Overloaded user-defined functions that have Double and BigDecimal arguments > will goes wrong > ------------------------------------------------------------------------------------------- > > Key: CALCITE-2053 > URL: https://issues.apache.org/jira/browse/CALCITE-2053 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.13.0 > Reporter: yuqi > Assignee: Julian Hyde > Fix For: 1.14.0 > > > We define a udf function class have two function as follows > {code:java} > public double toDouble(Double var) { > return var; > } > > public double toDouble(BigDecimal var) { > return var.doubleValue(); > } > {code} > when use it in sql like: > {code:sql} > select sum(price) from tb; > {code} > where price is a double value in table tb, exception occurs: > {code:java} > java.lang.AssertionError: DECIMAL(19, 0) > at > org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154) > at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) > at > org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592) > at > org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) > at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) > at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) > at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577) > 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:5081) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) > 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:5081) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:901) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:611) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:551) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:263) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:229) > at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:786) > at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640) > at > org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610) > at > org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221) > at > org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603) > at > org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638) > at > org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149) > at > org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218) > at > org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:564) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1337) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1320) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1284) > at > org.apache.calcite.test.UdfTest.testDoubleAndDecimal(UdfTest.java:896) > 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:497) > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)