Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1871

Nesting LAST within PREV is not parsed correctly for MATCH_RECOGNIZE

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.14.0
    • Component/s: None
    • Labels:

      Description

      For table Ticker:

      symbol: string
      tstamp: long
      price: int
      

      , the UP in the following sql

      SELECT *
      FROM Ticker
      MATCH_RECOGNIZE (
        MEASURES
          STRT.tstamp AS start_tstamp,
          LAST(DOWN.tstamp) AS bottom_tstamp,
          LAST(UP.tstamp) AS end_tstamp
        ONE ROW PER MATCH
        PATTERN (STRT DOWN+ UP+)
        DEFINE
          DOWN AS DOWN.price < PREV(DOWN.price),
          UP AS UP.price > PREV(LAST(DOWN.price, 1), 1)
      ) AS T
      

      is parsed as follows:

      ">(PREV(UP.$2, 0), LAST(DOWN.$2, 1))"
      

      I think this is not as expected. According to the documentation about MATCH_RECOGNIZE, it supports nesting LAST/FIRST within PREV/NEXT and we should not just ignore the PREV.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ransom Zhiqiang He
                Reporter:
                dian.fu Dian Fu
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: