Skip to content

[CALCITE-5507] HAVING alias failed when aggregate function in condition#3055

Closed
JiajunBernoulli wants to merge 2 commits intoapache:mainfrom
JiajunBernoulli:CALCITE-5507
Closed

[CALCITE-5507] HAVING alias failed when aggregate function in condition#3055
JiajunBernoulli wants to merge 2 commits intoapache:mainfrom
JiajunBernoulli:CALCITE-5507

Conversation

@JiajunBernoulli
Copy link
Contributor

No description provided.

@JiajunBernoulli JiajunBernoulli force-pushed the CALCITE-5507 branch 2 times, most recently from 22b5546 to d1fe017 Compare January 31, 2023 03:52
Copy link
Contributor

@NobiGo NobiGo left a comment

Choose a reason for hiding this comment

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

I think we should validate the SQL result in .iq file.

@JiajunBernoulli
Copy link
Contributor Author

I think we should validate the SQL result in .iq file.

Make sense, but I don't know how to change SqlConformanceEnum in agg.iq.

Would anyone tell me, thanks~

@NobiGo
Copy link
Contributor

NobiGo commented Feb 2, 2023

Hi @JiajunBernoulli
I know the SET command works on the Prepare class.
For example:
!set expand false
works on the THREAD_EXPAND.
Maybe you can read the code to add this SqlConformanceEnum.
Or maybe we can validate the RelNode in the SqlToRelConverter?

@JiajunBernoulli
Copy link
Contributor Author

@NobiGo , I added two unit tests in SqlToRelConverter, would you please review it again?

* @param parent a SqlNode
* @param children a SqlIdentifier
*/
private boolean containIdentifier(SqlNode parent, SqlIdentifier children) {
Copy link
Contributor

Choose a reason for hiding this comment

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

containIdentifier -> containsIdentifier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks for your review.

Copy link
Contributor

@NobiGo NobiGo left a comment

Choose a reason for hiding this comment

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

LGTM

@zoudan
Copy link
Contributor

zoudan commented Feb 7, 2023

LGTM

Copy link
Member

@libenchao libenchao left a comment

Choose a reason for hiding this comment

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

@JiajunBernoulli Thanks for your PR, it looks good generally, I only left some minor comments.

* @param parent a SqlNode
* @param children a SqlIdentifier
*/
private boolean containsIdentifier(SqlNode parent, SqlIdentifier children) {
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to use plural for second parameter. Further more, we even do not need to name them 'parent, child', it's not helpful for readability in my opinion.
How about name it containsIdentifier(SqlNode sqlNode, SqlIdentifier target)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I renamed them.

@Test void testAggregateFunAndAliasInHaving2() {
sql("select count(empno) as e\n"
+ "from emp\n"
+ "having e > 10 or count(empno) < 5")
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we need to have a different test which has only a minor difference with testAggregateFunAndAliasInHaving1 (from AND to OR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to show it because one is reduced and another is not reduced.

  • testAggregateFunAndAliasInHaving1
    LogicalFilter(condition=[>($0, 10)]) has no and.
  • testAggregateFunAndAliasInHaving2
    LogicalFilter(condition=[SEARCH($0, Sarg[(-∞..5), (10..+∞)])]) has or.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.5% 95.5% Coverage
0.0% 0.0% Duplication

Copy link
Member

@libenchao libenchao left a comment

Choose a reason for hiding this comment

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

+1, merging.

@libenchao libenchao closed this in bc263a3 Feb 19, 2023
julianhyde pushed a commit that referenced this pull request Feb 19, 2023
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.

4 participants