Mihai Budiu created CALCITE-6238:
------------------------------------

             Summary: Exception while evaluating ROUND function
                 Key: CALCITE-6238
                 URL: https://issues.apache.org/jira/browse/CALCITE-6238
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.36.0
            Reporter: Mihai Budiu


The following test in CalciteSqlOperatorTest:

{code:java}
 @Test void testRoundFunc() {
    final SqlOperatorFixture f = fixture();
    f.checkScalar("round(42, CAST(2 as BIGINT))", 42, "INTEGER NOT NULL");
  }
{code}

causes an exception; here is the relevant part of the stack trace:

{code}
java.sql.SQLException: Error while executing SQL "values (round(42, CAST(2 as 
BIGINT)))": Unable to implement EnumerableCalc(expr#0=[{inputs}], expr#1=[42], 
expr#2=[2:BIGINT], expr#3=[ROUND($t1, $t2)], EXPR$0=[$t3]): rowcount = 1.0, 
cumulative cost = {2.0 rows, 6.0 cpu, 0.0 io}, id = 20
  EnumerableValues(tuples=[[{ 0 }]]): rowcount = 1.0, cumulative cost = {1.0 
rows, 1.0 cpu, 0.0 io}, id = 13
...
        Suppressed: java.lang.RuntimeException: while resolving method 
'sround[int, long]' in class class org.apache.calcite.runtime.SqlFunctions
                at 
org.apache.calcite.adapter.enumerable.EnumUtils.call(EnumUtils.java:679)
                at 
org.apache.calcite.adapter.enumerable.RexImpTable$MethodImplementor.call(RexImpTable.java:2818)
                at 
org.apache.calcite.adapter.enumerable.RexImpTable$MethodImplementor.implementSafe(RexImpTable.java:2799)
                at 
org.apache.calcite.adapter.enumerable.RexImpTable$AbstractRexCallImplementor.genValueStatement(RexImpTable.java:3857)
                at 
org.apache.calcite.adapter.enumerable.RexImpTable$AbstractRexCallImplementor.implement(RexImpTable.java:3819)
{code}

And indeed, SqlFunctions does not have a function sround with this signature.

There are several possible fixes:
- reject calls to ROUND that have a BIGINT second argument
- have the validator insert an implicit cast for the second argument to INTEGER
- implement more Java versions of the SROUND function in SqlFunctions. Probably 
many more.

Which one of these is the right one? I suspect this problem applies to other 
SQL functions as well.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to