Mihai Budiu created CALCITE-5998:
------------------------------------

             Summary: The SAFE_OFFSET operator can cause an index out of bounds 
exception
                 Key: CALCITE-5998
                 URL: https://issues.apache.org/jira/browse/CALCITE-5998
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.35.0
            Reporter: Mihai Budiu


The following query, when added as a SqlOperatorTest:

{code:sql}
select ARRAY[p3,p2,p1][SAFE_OFFSET(p0)] from (values (-1, 6, 4, 2)) as t(p0, 
p1, p2, p3)
{code}

causes an exception. Here is the top of the stack trace:

{code:java}
Array index -1 is out of bounds
org.apache.calcite.runtime.CalciteException: Array index -1 is out of bounds
        at 
java.base@11.0.18/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
 Method)
        at 
java.base@11.0.18/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at 
java.base@11.0.18/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at 
java.base@11.0.18/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at 
app//org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:507)
        at 
app//org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:601)
        at 
app//org.apache.calcite.runtime.SqlFunctions.arrayItem(SqlFunctions.java:4742)
        at 
app//org.apache.calcite.runtime.SqlFunctions.arrayItemOptional(SqlFunctions.java:4780)
        at Baz$1$1.current(Unknown Source)
        at 
app//org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.next(Linq4j.java:687)
        at 
app//org.apache.calcite.avatica.util.IteratorCursor.next(IteratorCursor.java:46)
        at 
app//org.apache.calcite.avatica.AvaticaResultSet.next(AvaticaResultSet.java:219)
        at 
app//org.apache.calcite.sql.test.ResultCheckers.compareResultSet(ResultCheckers.java:128)
        at 
app//org.apache.calcite.sql.test.ResultCheckers$RefSetResultChecker.checkResult(ResultCheckers.java:336)
        at 
app//org.apache.calcite.test.SqlOperatorTest$TesterImpl.check(SqlOperatorTest.java:12987)
{code}



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

Reply via email to