You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Magnus Mogren (Jira)" <ji...@apache.org> on 2023/02/13 15:09:00 UTC

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

    [ https://issues.apache.org/jira/browse/CALCITE-5400?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17687976#comment-17687976 ] 

Magnus Mogren edited comment on CALCITE-5400 at 2/13/23 3:08 PM:
-----------------------------------------------------------------

[~dmsysolyatin] do you think that there will be time to fix this to 1.34.0 ?


was (Author: mamo):
[~dmsysolyatin] do you thing that there will be time to fix this to 1.34.0 ?

> 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
>            Priority: Major
>
> 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)