vlsi commented on a change in pull request #2458:
URL: https://github.com/apache/calcite/pull/2458#discussion_r690570603
##########
File path:
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
##########
@@ -329,7 +330,17 @@ public Result visit(Filter e) {
ImmutableSet.of(Clause.HAVING));
parseCorrelTable(e, x);
final Builder builder = x.builder(e);
- builder.setHaving(builder.context.toSql(null, e.getCondition()));
+ SqlNode condition = builder.context.toSql(null, e.getCondition());
+ SqlNode existHaving = x.asSelect().getHaving();
+ if (existHaving != null) {
+ // if input Aggregate RelNode contains existHaving, need
+ // to create AND expression with connect condition and existHaving
+ // then update input Aggregate's Having condition.
+ condition = SqlUtil.andExpressions(condition, existHaving);
+ x.asSelect().setHaving(condition);
+ } else {
+ builder.setHaving(condition);
+ }
Review comment:
A minor style note: it often works better if a shorter `if` branch is
located the first. It makes it easier to relate `else` and the corresponding
`if` condition.
```suggestion
if (existHaving == null) {
builder.setHaving(condition);
} else {
// if input Aggregate RelNode contains existHaving, need
// to create AND expression with connect condition and existHaving
// then update input Aggregate's Having condition.
condition = SqlUtil.andExpressions(condition, existHaving);
x.asSelect().setHaving(condition);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]