[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16429601#comment-16429601 ] yuqi commented on CALCITE-2053: --- [~julianhyde], Could you take time to this issue and look the change is reasonable ? > 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.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > 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.
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16394854#comment-16394854 ] yuqi commented on CALCITE-2053: --- [~julianhyde] Is this change look OK? > 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.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > 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
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16356590#comment-16356590 ] yuqi commented on CALCITE-2053: --- Thanks for your time. > 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.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > 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.m
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16353189#comment-16353189 ] Julian Hyde commented on CALCITE-2053: -- Your change looks fairly close. I think if your test worked for java.lang.Float as well as java.lang.Double we would be good. > 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.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16352842#comment-16352842 ] Julian Hyde commented on CALCITE-2053: -- Did you know that in SQL, FLOAT is a 64-bit floating point type? (Actually it is variable in the standard, but Calcite fixes it at 64 bits.) REAL is a 32-bit floating point. > 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.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16351794#comment-16351794 ] yuqi commented on CALCITE-2053: --- En, FLOAT should take into consideration if we want to solve problem like this completely, Changes have been make. Still, I can't understand why calcite treat float in java as SqlTypeName.REAL in file JavaToSqlTypeConversionRules, see below {code:java} ... .put(Float.class, SqlTypeName.REAL) .put(float.class, SqlTypeName.REAL) {code} and what's the type in java thats equals SqlTypeName.FLOAT in calcite? [~julianhyde] > 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.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16351558#comment-16351558 ] Julian Hyde commented on CALCITE-2053: -- If that change works and doesn't break anything I could accept it. If you are calling a method with a DECIMAL argument and there are overloads with DOUBLE, DECIMAL and FLOAT parameters, which overload would it choose? And so forth. > 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.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAcc
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16350178#comment-16350178 ] yuqi commented on CALCITE-2053: --- Ok, I change {code:java} .put(SqlTypeName.DOUBLE, numeric(SqlTypeName.DOUBLE)){code} to {code:java} .put(SqlTypeName.DOUBLE, list(SqlTypeName.DOUBLE, SqlTypeName.DECIMAL)){code} but, i do think it's a little hard-code. what's your opinion ? [~julianhyde] > 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, 1.15.0 >Reporter: yuqi >Assignee: Julian Hyde >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.refle
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16349632#comment-16349632 ] Julian Hyde commented on CALCITE-2053: -- I reviewed [ded37ab|https://github.com/apache/calcite/pull/619/commits/ded37ab18187a9493361251caf8fccb603174c27]; it seems wrong that you weakened {code}assert containsType(type1) : type1; assert containsType(type2) : type2;{code}to{code}assert containsType(type1) || containsType(type2) : type1.toString() + ", " + type2.toString();{code} The precedence list ought to contain both DECIMAL and DOUBLE, so that's what you need to fix. > 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 >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQ
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16348015#comment-16348015 ] yuqi commented on CALCITE-2053: --- [~julianhyde] , I confirm this, here is my MR [https://github.com/apache/calcite/pull/619] , please help to review this PR if you have time, thanks > 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 >Priority: Major > > We add the following udf method in Smalls.AllTypesFunction > {code:java} >public double toDouble(BigDecimal var) { > return var.doubleValue(); >} >public double toDouble(Double var) { > return var; > } > > {code} > when test it : > {code:java} > @Test > public void testBigDecimalAndLong() { > final CalciteAssert.AssertThat with = withUdf(); > with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))") > .returns("EXPR$0=1.0\n"); > }{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:5432) > at > org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419) > at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591) > 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:5136) > 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:5136) > at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at > org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903) > at > org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613) > at > org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553) > at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at > org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at > org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781) > 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:568) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329) > at > org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293) > at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorI
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16258753#comment-16258753 ] yuqi commented on CALCITE-2053: --- yes, similar to CALCITE-1881, but it does exist and has not been fixed > 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 > > 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(DelegatingMethod
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16254150#comment-16254150 ] Julian Hyde commented on CALCITE-2053: -- Looks similar to CALCITE-1881. Fix may or may not be similar. > 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 > > 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(DelegatingM
[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong
[ https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16253170#comment-16253170 ] yuqi commented on CALCITE-2053: --- The problem is that in function {code:java} filterRoutinesByParameterType {code} , calcite do think decimal(bigdecimal in java) can transfer to double and vice versa(see {code:java} SqlTypeAssignmentRules.java {code} ) however in function {code:java} filterRoutinesByTypePrecedence {code} , according to number type precedence list in {code:java} SqlTypeExplicitPrecedentList.java {code} , decimal value can to cast to decimal and double and double value can only be cast to double, this is why this problem exist. My points to solve the problem are as follows: 1. we can change function {code:java} containsType {code} in class {code:java} SqlTypeExplicitPrecedentList {code} , When containsType return false, containsType directly return a positive values which means the second parameter does't precedent to the first one, thus best match parameter is still the former. 2. we can also change the precedent list in {code:java} SqlTypeExplicitPrecedentList {code} , what puzzle me is that how to choose the sequence of Decimal and Double ? now decimal is in front of double, double value can't cast to decimal, if put decimal after double then decimal, decimal value can't cast to double. What's your opinion about this problem, suggestions are welcome [~julianhyde], thanks > 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.CalcitePrepareI