Wail Y. Alkowaileet created ASTERIXDB-3103:
----------------------------------------------

             Summary: Non-pure functions are not referenced correctly
                 Key: ASTERIXDB-3103
                 URL: https://issues.apache.org/jira/browse/ASTERIXDB-3103
             Project: Apache AsterixDB
          Issue Type: Bug
            Reporter: Wail Y. Alkowaileet
            Assignee: Wail Y. Alkowaileet


 

Currently, `LangExpressionToPlanTranslator` inlines every expression – 
including non-pure functions. This could lead to incorrect referencing as 
follows

Query:
{code:java}
EXPLAIN
SELECT COUNT(*)
FROM [1, 2, 3] AS A
LIMIT random() {code}
 

Plan:

 
{code:java}
distribute result [$$32]
-- DISTRIBUTE_RESULT  |LOCAL|
  exchange
  -- ONE_TO_ONE_EXCHANGE  |LOCAL|
    limit switch-case(gt(treat-as-integer(random()), 0), true, 
treat-as-integer(random()), 0)
    -- STREAM_LIMIT  |LOCAL|
      project ([$$32])
      -- STREAM_PROJECT  |LOCAL|
        assign [$$32] <- [{\"$1\": $$34}]
        -- ASSIGN  |LOCAL|
          limit switch-case(gt(treat-as-integer(random()), 0), true, 
treat-as-integer(random()), 0)
          -- STREAM_LIMIT  |LOCAL|
            aggregate [$$34] <- [agg-sql-sum($$35)]
            -- AGGREGATE  |LOCAL|
              aggregate [$$35] <- [agg-sql-count(1)]
              -- AGGREGATE  |LOCAL|
                unnest $$A <- scan-collection(array: [ 1, 2, 3 ])
                -- UNNEST  |UNPARTITIONED|
                  empty-tuple-source
                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
 {code}
 

 

In:
{code:java}
 limit switch-case(gt(treat-as-integer(random()), 0), true, 
treat-as-integer(random()), 0) {code}
the test *gt(treat-as-integer(random()), 0)* could yield a positive number; 
however, the second call  *treat-as-integer(random())* could yield a negative 
number – rendering this check ({*}switch-case{*} call) as useless

 

The expected behavior is that the value from *random()* should be in its own 
assign

 



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

Reply via email to