xuzifu666 commented on code in PR #4896:
URL: https://github.com/apache/calcite/pull/4896#discussion_r3114621671


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -263,8 +265,42 @@ protected ElasticsearchAggregateRule(Config config) {
       super(config);
     }
 
+    /**
+     * Checks if the relational expression or any of its inputs
+     * is an Aggregate (LogicalAggregate or ElasticsearchAggregate).
+     * This prevents nested aggregations from being pushed down to 
Elasticsearch.

Review Comment:
   Had added comment on called function.



##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchRules.java:
##########
@@ -263,8 +265,42 @@ protected ElasticsearchAggregateRule(Config config) {
       super(config);
     }
 
+    /**
+     * Checks if the relational expression or any of its inputs
+     * is an Aggregate (LogicalAggregate or ElasticsearchAggregate).
+     * This prevents nested aggregations from being pushed down to 
Elasticsearch.
+     */
+    private static boolean containsAggregate(RelNode node) {
+      // Handle RelSubset by checking its best or original node
+      if (node instanceof RelSubset) {

Review Comment:
   Let me explain, When the optimizer processes a subquery:
   1. The subquery ```SELECT deptno FROM dept``` is optimized to 
```RelSubset```.
   2. The main query's filter input is this ```RelSubset```.
   3. If ```RelSubset``` is not processed, ```containsAggregate()``` will 
incorrectly return false.
   4. This causes nested aggregations to be incorrectly pushed down to 
Elasticsearch.
   



-- 
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]

Reply via email to