Skip to content
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

[CALCITE-4779] GroupByList contains constant literal, materialized view recognition failed #2529

Merged
merged 1 commit into from Sep 28, 2021

Conversation

xy2953396112
Copy link
Contributor

@xy2953396112 xy2953396112 commented Sep 19, 2021

@xy2953396112
Copy link
Contributor Author

@julianhyde
Please help review this pr,thank you.

Copy link
Member

@asolimando asolimando left a comment

Choose a reason for hiding this comment

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

The PR LGTM, I was thinking that tests could cover also constants between column names, and after them, instead of only preceding them.

For instance something like: group by $col1, 1, $col2, group by 1, $col1, $col2 and group by 1, $col1, $col2

@xy2953396112 xy2953396112 force-pushed the CALCITE_4779 branch 2 times, most recently from 1debc97 to 068acd4 Compare September 20, 2021 00:01
@xy2953396112 xy2953396112 changed the title [CALCITE_4779] GroupSet contains constant, materialized view recognit… [CALCITE_4779] GroupSet contains literal, materialized view recognit… Sep 20, 2021
@wojustme
Copy link
Contributor

LGTM~

@yanlin-Lynn
Copy link
Contributor

Can you use a varchar constant, not integer constant in the group by list.

@asolimando
Copy link
Member

@xy2953396112 please avoid squashing while the review process is on-going, old and new changes cannot be distinguished anymore, and reviewers can't just look at the "newer" part.

@xy2953396112
Copy link
Contributor Author

Can you use a varchar constant, not integer constant in the group by list.

ok.Please review again,thanks.

@wojustme
Copy link
Contributor

wojustme commented Sep 20, 2021

Can you use a varchar constant, not integer constant in the group by list.
Hi @yanlin-Lynn
Should we need case of group by varchar literal?
In query's relnode, group by varchar literal is the same to group by integer literal.
They are all belong to the pattern of AggregateOnCalc.

@xy2953396112
Copy link
Contributor Author

@xy2953396112 please avoid squashing while the review process is on-going, old and new changes cannot be distinguished anymore, and reviewers can't just look at the "newer" part.

ok.Please help review, thanks a lot.

@asolimando
Copy link
Member

Can you use a varchar constant, not integer constant in the group by list.
Hi @yanlin-Lynn
Should we need case of group by varchar literal?
In query's relnode, group by varchar literal is the same to group by integer literal.
They are all belong to the pattern of AggregateOnCalc.

As a general comment, test cases should be crafted with the expected behaviour in mind, not the concrete implementation.

It might seem trivial in the current state of the implementation, but tomorrow a change could break this assumption (maybe simply by mistake), and the test case would capture it.

Of course there must be a reasonable chance for this to happen, I am not saying that this is necessarily the case here.

@julianhyde
Copy link
Contributor

julianhyde commented Sep 21, 2021

I second @asolimando's point about merging. When a PR is under review, don't rebase (unless asked to), don't squash commits, don't amend commits, just add new commits. It makes things easier for reviewers. We know how to do git diff HEAD~5 if we need to.

I think it would be useful if you describe in brief a javadoc sentence the particular feature that each each test is testing. It's difficult to capture this in the test name - for example, the test case "testGroupSetMultipleLiteralsOrder" contains neither GROUPING SET nor ORDER BY. I understand from reading the test that you are interested in a query that contains literals and the literals are in a different order in the SELECT clause to the GROUP BY clause.

I'm not sure that this bug requires 70 lines of new tests, because the fix simply removes literals. Since all tests use the same MV, I would compress them all into one method.

The one case you have not tested is a query that groups by a literal and no columns, e.g. GROUP BY 'a'. The semantics are non-obvious when the table is empty. It warrants its own test.

@wojustme
Copy link
Contributor

Can you use a varchar constant, not integer constant in the group by list.
Hi @yanlin-Lynn
Should we need case of group by varchar literal?
In query's relnode, group by varchar literal is the same to group by integer literal.
They are all belong to the pattern of AggregateOnCalc.

As a general comment, test cases should be crafted with the expected behaviour in mind, not the concrete implementation.

It might seem trivial in the current state of the implementation, but tomorrow a change could break this assumption (maybe simply by mistake), and the test case would capture it.

Of course there must be a reasonable chance for this to happen, I am not saying that this is necessarily the case here.

Can you use a varchar constant, not integer constant in the group by list.
Hi @yanlin-Lynn
Should we need case of group by varchar literal?
In query's relnode, group by varchar literal is the same to group by integer literal.
They are all belong to the pattern of AggregateOnCalc.

As a general comment, test cases should be crafted with the expected behaviour in mind, not the concrete implementation.

It might seem trivial in the current state of the implementation, but tomorrow a change could break this assumption (maybe simply by mistake), and the test case would capture it.

Of course there must be a reasonable chance for this to happen, I am not saying that this is necessarily the case here.

Ok, got it. Thanks for for your advice. @asolimando

@xy2953396112
Copy link
Contributor Author

xy2953396112 commented Sep 22, 2021

@yanlin-Lynn @julianhyde @asolimando
I have updated the code.Any comments?

Copy link
Member

@asolimando asolimando left a comment

Choose a reason for hiding this comment

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

I re-confirm my approval after checking the latest changes, thanks for addressing the comments!

@xy2953396112 xy2953396112 force-pushed the CALCITE_4779 branch 2 times, most recently from 1e82bbd to ba3bcab Compare September 22, 2021 12:45
@xy2953396112
Copy link
Contributor Author

I re-confirm my approval after checking the latest changes, thanks for addressing the comments!

Thanks for review.

@xy2953396112 xy2953396112 changed the title [CALCITE_4779] GroupSet contains literal, materialized view recognit… [CALCITE-4779] GroupSet contains literal, materialized view recognit… Sep 23, 2021
@xy2953396112 xy2953396112 force-pushed the CALCITE_4779 branch 2 times, most recently from 048fd15 to 7814935 Compare September 25, 2021 02:08
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-4779">[CALCITE-4779]
* GroupingSet contains {@link RexLiteral}, materialized view recognition failed</a>. */
@Test void testGroupingSetLiteral() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not grouping set, it's "constant literal" in group by list. right?

@@ -1691,6 +1691,44 @@ private void checkSatisfiable(RexNode e, String s) {
+ "EnumerableTableScan(table=[[hr, MV0]])")).ok();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-4779">[CALCITE-4779]
* GroupSet contains {@link RexLiteral}, materialized view recognition failed</a>. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Not GroupSet, it's group by list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

final String mv1 = ""
+ "select \"deptno\", \"empid\"\n"
+ "from \"emps\"\n"
+ "group by \"deptno\", \"empid\"";
Copy link
Contributor

Choose a reason for hiding this comment

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

mv0 and mv1 is the same.

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,update the code.

@xy2953396112 xy2953396112 changed the title [CALCITE-4779] GroupSet contains literal, materialized view recognit… [CALCITE-4779] GroupByList contains constant literal, materialized view recognition failed Sep 26, 2021
@yanlin-Lynn
Copy link
Contributor

LGTM

@yanlin-Lynn yanlin-Lynn added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Sep 27, 2021
@yanlin-Lynn yanlin-Lynn merged commit 219e41e into apache:master Sep 28, 2021
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
5 participants