You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Dmitry Sysolyatin (Jira)" <ji...@apache.org> on 2022/11/24 20:49:00 UTC

[jira] [Created] (CALCITE-5400) EnumerableCalc should not generate Enumerable.current with a non-idempotent function inside

Dmitry Sysolyatin created CALCITE-5400:
------------------------------------------

             Summary: EnumerableCalc should not generate Enumerable.current with a non-idempotent function inside
                 Key: CALCITE-5400
                 URL: https://issues.apache.org/jira/browse/CALCITE-5400
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.32.0
            Reporter: Dmitry Sysolyatin


The problem has been found inside CALCITE-5388. The following query can return wrong result:
{code:java}
with
    CTE1(rand1, val1) as ( select RAND_INTEGER(2), id from (values (1), (2)) as Vals1(id) ),
    CTE2(rand2, val2) as ( select RAND_INTEGER(2), id from (values (1), (2)) as Vals2(id) )
select
    CTE1.rand1,    CTE1.val1,
    CTE2.rand2,
    CTE2.val2 
from
    CTE1,
    CTE2 
where
    CTE1.rand1 = CTE2.rand2 
{code}
For instance it can return:
|RAND1|VAL1|RAND2|VAL2|
|1|1|1|1|
|*{color:#ff0000}0{color}*|1|*{color:#ff0000}1{color}*|2|

The problem is that EnumerableCalc generates Enumerable class that uses non-idempotent function `randInteger` inside 'current()' method: 
{code:java}
new org.apache.calcite.linq4j.AbstractEnumerable() {
          public org.apache.calcite.linq4j.Enumerator enumerator() {
            return new org.apache.calcite.linq4j.Enumerator() {
              <.........>
              public Object current() {
                return new Object[]{
                    $L4J$C$new_org_apache_calcite_runtime_RandomFunction_.randInteger(2),
                    org.apache.calcite.runtime.SqlFunctions.toInt(inputEnumerator.current())};
              }

              static final org.apache.calcite.runtime.RandomFunction $L4J$C$new_org_apache_calcite_runtime_RandomFunction_ = new org.apache.calcite.runtime.RandomFunction();
            };

          }
        };
{code}

if current() is called twice it can produce different results. What exactly happens inside EnumerableDefault.hashEquiJoin_ function (outers.current() is called inside moveNext() and current())



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