Skip to content

[CALCITE-7734] MATCH_RECOGNIZE with an unqualified column in MEASURES/DEFINE produces an unusable plan - #5210

Open
snuyanzin wants to merge 2 commits into
apache:mainfrom
snuyanzin:calcite7734
Open

[CALCITE-7734] MATCH_RECOGNIZE with an unqualified column in MEASURES/DEFINE produces an unusable plan#5210
snuyanzin wants to merge 2 commits into
apache:mainfrom
snuyanzin:calcite7734

Conversation

@snuyanzin

@snuyanzin snuyanzin commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7734

Changes Proposed

The PR fixes plan for MATCH_RECOGNIZE with an unqualified column in MEASURES/DEFINE broken while CALCITE-7480

pv = identifier.names.get(0);
// A qualifier that is not a declared pattern variable denotes the universal variable "*".
if (bb.scope instanceof MatchRecognizeScope
&& !((MatchRecognizeScope) bb.scope).getPatternVars().contains(pv)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be handled correctly if the input table alias has the same name as a pattern variable? For example:

FROM a_source AS A
MATCH_RECOGNIZE (
  MEASURES commission AS c
  PATTERN (A B)
  DEFINE
    A AS A.empid >= 0,
    B AS B.empid < 0
)

Here, A is both the input table alias and a pattern variable. I am not sure whether Calcite considers this case valid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, you are right, good catch
updated PR and added a couple of more tests around this

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants