Mihai Budiu created CALCITE-7834:
------------------------------------

             Summary: Type inferred for LAG/LEAD is not always nullable
                 Key: CALCITE-7834
                 URL: https://issues.apache.org/jira/browse/CALCITE-7834
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.42.0
            Reporter: Mihai Budiu
            Assignee: Mihai Budiu


The column produced by LAG/LEAD should always be nullable, but Calcite copies 
the input column type. As a result, the following quidem test crashes:
{code:java}
SELECT y, x, LAG(x, 1, 0) OVER (ORDER BY y) AS l
FROM (VALUES (1, 10), (2, CAST(NULL AS INTEGER)), (3, 30)) AS t(y, x); {code}
stack trace:
{code:java}
Caused by: org.apache.calcite.runtime.CalciteException: Cannot convert null to 
int
        at 
java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
        at 
java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at 
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)
        at 
org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:511)
        at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:605)
        at 
org.apache.calcite.runtime.SqlFunctions.cannotConvert(SqlFunctions.java:5283)
        at org.apache.calcite.runtime.SqlFunctions.toInt(SqlFunctions.java:5464)
 {code}



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

Reply via email to