This is an automated email from the ASF dual-hosted git repository.

xingtanzjr pushed a commit to branch xingtanzjr/agg_query_level
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit dfe5a62771c8b843ae21283a9725c252da4c3dd2
Author: Jinrui.Zhang <[email protected]>
AuthorDate: Thu Jul 21 19:12:01 2022 +0800

    fix the issue that GroupByLevel cannot use value filter
---
 .../mpp/plan/planner/distribution/SourceRewriter.java | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/SourceRewriter.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/SourceRewriter.java
index 51618cbe64..ce20f83396 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/SourceRewriter.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/SourceRewriter.java
@@ -531,6 +531,9 @@ public class SourceRewriter extends 
SimplePlanNodeRewriter<DistributionPlanConte
 
   @Override
   public PlanNode visitGroupByLevel(GroupByLevelNode root, 
DistributionPlanContext context) {
+    if (shouldUseNaiveAggregation(root)) {
+      return defaultRewrite(root, context);
+    }
     // Firstly, we build the tree structure for GroupByLevelNode
     List<SeriesAggregationSourceNode> sources = 
splitAggregationSourceByPartition(root, context);
     Map<TRegionReplicaSet, List<SeriesAggregationSourceNode>> sourceGroup =
@@ -554,6 +557,22 @@ public class SourceRewriter extends 
SimplePlanNodeRewriter<DistributionPlanConte
     return newRoot;
   }
 
+  // If the Aggregation Query contains value filter, we need to use the naive 
query plan
+  // for it. That is, do the raw data query and then do the aggregation 
operation.
+  // Currently, the method to judge whether the query should use naive query 
plan is whether
+  // AggregationNode is contained in the PlanNode tree of logical plan.
+  private boolean shouldUseNaiveAggregation(PlanNode root) {
+    if (root instanceof AggregationNode) {
+      return true;
+    }
+    for (PlanNode child : root.getChildren()) {
+      if (shouldUseNaiveAggregation(child)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   private GroupByLevelNode groupSourcesForGroupByLevelWithSlidingWindow(
       GroupByLevelNode root,
       SlidingWindowAggregationNode slidingWindowNode,

Reply via email to