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

Sergey Nuyanzin updated CALCITE-7465:
-------------------------------------
    Description: 
It adds extra {{FINAL}} or {{RUNNING}} for every field forward at 
{{SqlValidatorImpl#navigationInMeasure}} depending on all or not all rows

for instance this query
{code:sql}
SELECT *
FROM emp
MATCH_RECOGNIZE (
  MEASURES
     FINAL COUNT(A.deptno) AS deptno,
     A.ename AS ename
  PATTERN (A B)
  DEFINE
    A AS A.empno = 123
) AS T
{code}

is being rewritten to (added {{FINAL}})
{code:sql}
SELECT *
FROM `EMP` MATCH_RECOGNIZE(
MEASURES FINAL COUNT(`A`.`DEPTNO`) AS `DEPTNO`, FINAL `A`.`ENAME` AS `ENAME`
PATTERN (`A` `B`)
DEFINE `A` AS (PREV(`A`.`EMPNO`, 0) = 123)) AS `T`
{code}

At the same time an attempt to parse unparsed version will fail because of 
added {{FINAL}}

UPD: after deeper look it might be not only {{FINAL}} being added however it 
might be rewritten {{RUNNING}} with {{FINAL}} or vice versa, depending on 
{{MATCH ALL ROWS}} or {{ONE ROW}}.
So probably better to move the logic from validation to {{SqlToRelConverter}} 
then unparsing will stop being impacted 

  was:
It adds extra {{FINAL}} or {{RUNNING}} for every field forward at 
{{SqlValidatorImpl#navigationInMeasure}} depending on all or not all rows

for instance this query
{code:sql}
SELECT *
FROM emp
MATCH_RECOGNIZE (
  MEASURES
     FINAL COUNT(A.deptno) AS deptno,
     A.ename AS ename
  PATTERN (A B)
  DEFINE
    A AS A.empno = 123
) AS T
{code}

is being rewritten to (added {{FINAL}})
{code:sql}
SELECT *
FROM `EMP` MATCH_RECOGNIZE(
MEASURES FINAL COUNT(`A`.`DEPTNO`) AS `DEPTNO`, FINAL `A`.`ENAME` AS `ENAME`
PATTERN (`A` `B`)
DEFINE `A` AS (PREV(`A`.`EMPNO`, 0) = 123)) AS `T`
{code}

At the same time an attempt to parse unparsed version will fail because of 
added {{FINAL}}


> Unparse of MATCH_RECOGNIZE with field forwards produce unparsable sql
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-7465
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7465
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Sergey Nuyanzin
>            Assignee: Sergey Nuyanzin
>            Priority: Major
>
> It adds extra {{FINAL}} or {{RUNNING}} for every field forward at 
> {{SqlValidatorImpl#navigationInMeasure}} depending on all or not all rows
> for instance this query
> {code:sql}
> SELECT *
> FROM emp
> MATCH_RECOGNIZE (
>   MEASURES
>      FINAL COUNT(A.deptno) AS deptno,
>      A.ename AS ename
>   PATTERN (A B)
>   DEFINE
>     A AS A.empno = 123
> ) AS T
> {code}
> is being rewritten to (added {{FINAL}})
> {code:sql}
> SELECT *
> FROM `EMP` MATCH_RECOGNIZE(
> MEASURES FINAL COUNT(`A`.`DEPTNO`) AS `DEPTNO`, FINAL `A`.`ENAME` AS `ENAME`
> PATTERN (`A` `B`)
> DEFINE `A` AS (PREV(`A`.`EMPNO`, 0) = 123)) AS `T`
> {code}
> At the same time an attempt to parse unparsed version will fail because of 
> added {{FINAL}}
> UPD: after deeper look it might be not only {{FINAL}} being added however it 
> might be rewritten {{RUNNING}} with {{FINAL}} or vice versa, depending on 
> {{MATCH ALL ROWS}} or {{ONE ROW}}.
> So probably better to move the logic from validation to {{SqlToRelConverter}} 
> then unparsing will stop being impacted 



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

Reply via email to