Sergey Nuyanzin created CALCITE-7474:
----------------------------------------

             Summary: LAST in MATCH_RECOGNIZE might return wrong result
                 Key: CALCITE-7474
                 URL: https://issues.apache.org/jira/browse/CALCITE-7474
             Project: Calcite
          Issue Type: Bug
            Reporter: Sergey Nuyanzin
            Assignee: Sergey Nuyanzin


depending on expanded or non-expanded column name the result is different 
for instance
{code:sql}
select *
from "hr"."emps" match_recognize (
    order by "empid" desc
    measures "commission" as c,
    LAST("empid") as empid
    pattern (s up)
    define up as up."commission" < prev(up."commission"));
{code}
returns 
{noformat}
C    EMPID
---- -----
1000   100
 500   200
{noformat}
now if use expanded name like {{LAST("hr"."emps"."empid") as empid}} instead of 
{{LAST("empid") as empid}}
{code:sql}
select *
from "hr"."emps" match_recognize (
    order by "empid" desc
    measures "commission" as c,
    LAST("hr"."emps"."empid") as empid
    pattern (s up)
    define up as up."commission" < prev(up."commission"));
{code}
returns
{noformat}
C   
---- 
1000
 500 
{noformat}

the reason is 
https://github.com/apache/calcite/blob/0ce0c5ae2f7055f13551ebcde8e1aaa2ff17b469/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java#L4184-L4196



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

Reply via email to