[ 
https://issues.apache.org/jira/browse/CALCITE-7474?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sergey Nuyanzin resolved CALCITE-7474.
--------------------------------------
    Fix Version/s: 1.42.0
       Resolution: Fixed

> 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
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.42.0
>
>
> 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
> I tested it with 
> 1. Oracle. 
> 2. Snowflake
> for both the query fails with message that variable doesn't occur in 
> {{PATTERN}}, at the same time it also fails if use just a star.
> 3. BigQuery. 
> it was able to process the query and return the result



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

Reply via email to