alpass163 commented on code in PR #19227:
URL: https://github.com/apache/iotdb/pull/19227#discussion_r4548368473


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java:
##########
@@ -185,6 +187,27 @@ public class TableDistributedPlanGenerator
     implements PlanVisitor<List<PlanNode>, 
TableDistributedPlanGenerator.PlanContext> {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(TableDistributedPlanGenerator.class);
 
+  // Functions that keep per-partition state and therefore require every 
partition to be handled
+  // by a single processor. A partition is not guaranteed to be confined to 
one child of the
+  // distributed plan: PARTITION BY may use non-device columns, and a device 
itself may span
+  // regions. These functions are collected before being evaluated instead of 
being cloned for
+  // every child.
+  private static final Set<String> NON_SPLITTABLE_TABLE_FUNCTIONS =

Review Comment:
   These table functions are non-splittable because they maintain state across 
the rows of an entire partition. In a distributed plan, a partition is not 
guaranteed to be contained within a single child: PARTITION BY may use 
non-device columns, and a device’s data may span multiple regions. If the 
function is cloned and run independently on each child, each instance sees only 
part of the partition and may produce incomplete or incorrect results. The 
inputs must therefore be gathered and ordered by the partition keys and the 
required in-partition ordering before a single processor evaluates the function



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/TableDistributedPlanGenerator.java:
##########
@@ -2270,17 +2293,28 @@ static boolean isInputOrderedByTimeAscending(
       List<Symbol> groupingKeys,
       OrderingScheme childOrdering) {
     String functionName = 
aggregation.getResolvedFunction().getSignature().getName();
-    if (step != SINGLE
-        || childOrdering == null
-        || aggregation.getArguments().size() < 2
-        || !(RATE.equalsIgnoreCase(functionName)
-            || INCREASE.equalsIgnoreCase(functionName)
-            || IRATE.equalsIgnoreCase(functionName)
-            || DELTA.equalsIgnoreCase(functionName))) {
+    if (step != SINGLE || childOrdering == null) {
+      return false;
+    }
+
+    // integral(value, time_unit, time) takes the time column as the third 
argument, while the
+    // rate family takes it as the second one
+    final int timeArgumentIndex;
+    if (INTEGRAL.equalsIgnoreCase(functionName)) {

Review Comment:
   the Sort operator is eliminated during planning before the distributed 
aggregation checks its input ordering. As a result, childOrdering no longer 
carries evidence that the input is ordered, so isInputOrderedByTimeAscending() 
cannot recognize the ordering. currently it could consume much effort to 
optimize it



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