Skip to content

[CALCITE-4207] Validation fails for positional aggregate with current_date in 'case' expression #2130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2020

Conversation

ihuzenko
Copy link
Member

@ihuzenko ihuzenko commented Sep 2, 2020

No description provided.

}
};
sql("SELECT HIREDATE >= CURRENT_DATE, COUNT(*) "
+ "FROM EMP GROUP BY 1")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by why the current_date caused the problem, does other non-param function triggers the bug too ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Please take a look at the stack trace from CALCITE-4207 description and this comment.

Copy link
Contributor

@danny0405 danny0405 Sep 4, 2020

Choose a reason for hiding this comment

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

In one place CURRENT_DATE was represented as SqlBasicCall while in other it was instance of SqlIdentifier

Still does not get your point, in you fix, you just use the expanded group expr for validation, but the CURRENT_DATE is not a group expr ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Positional aggregate points to the first expression in select. Validation tries to match 2 expression trees :

  1. The first item from select which is already expanded at the moment and contains current_date as an instance of SqlBasicCall
  2. An item from the group by where prior to my fix current_date was presented as an instance of the SqlIdentifier.

Due to this instance mismatch validation goes further and tells that Expression 'EMP.HIREDATE' is not being grouped, although grouping was performed by the whole expression HIREDATE >= CURRENT_DATE.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello @danny0405 , could you proceed with reviewing the PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried the fix locally and think the fix is reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for review:)

@ihuzenko
Copy link
Member Author

ihuzenko commented Sep 7, 2020

Hello @zabetak ,

Could you please take a look at the PR?

Thank you in advance,
Igor

Copy link
Contributor

@danny0405 danny0405 left a comment

Choose a reason for hiding this comment

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

+1

@danny0405 danny0405 added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Sep 9, 2020
@amaliujia
Copy link
Contributor

+1

@amaliujia amaliujia merged commit a8be094 into apache:master Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM-will-merge-soon Overall PR looks OK. Only minor things left.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants