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

yuqi updated CALCITE-2053:
--------------------------
    Description: 
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
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
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:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1573)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:225)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:224)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:895)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:605)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:550)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:228)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:784)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:639)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:609)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
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)
{code}

  was:
We add the following udf method in Smalls.AllTypesFunction
{code:java}
    public double toDouble(Double var) {
      return var;
    }
    
 public double toDouble(BigDecimal var) {
      return var.doubleValue();
    }
{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
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
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:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1573)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:225)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:224)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:895)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:605)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:550)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:228)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:784)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:639)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:609)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
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)
{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
>            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
> at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
> at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
> at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
> at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
> 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:5053)
> at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
> at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
> at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
> at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1573)
> at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:225)
> at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
> at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
> at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
> at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:224)
> at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
> at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
> at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
> at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:895)
> at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:605)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:550)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:228)
> at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:784)
> at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:639)
> at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:609)
> at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
> 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)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to