Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5400

EnumerableCalc should not generate Enumerable.current with a non-idempotent function inside

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.32.0
    • None
    • core
    • None

    Description

      The problem has been found inside CALCITE-5388. The following query can return wrong result:

      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 
      

      For instance it can return:

      RAND1 VAL1 RAND2 VAL2
      1 1 1 1
      0 1 1 2

      The problem is that EnumerableCalc generates Enumerable class that uses non-idempotent function `randInteger` inside 'current()' method: 

      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();
                  };
      
                }
              };
      

      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())

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dmsysolyatin Dmitry Sysolyatin
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: