JackieTien97 commented on code in PR #19250:
URL: https://github.com/apache/iotdb/pull/19250#discussion_r4559299589


##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/distribute/RateOrderedPlannerTest.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.plan.relational.planner.distribute;
+
+import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNode;
+import 
org.apache.iotdb.commons.queryengine.plan.relational.planner.node.AggregationNode;
+import org.apache.iotdb.db.queryengine.plan.relational.analyzer.TestMetadata;
+import org.apache.iotdb.db.queryengine.plan.relational.planner.PlanTester;
+
+import org.junit.Test;
+
+import static 
org.apache.iotdb.commons.queryengine.plan.relational.planner.node.AggregationNode.Step.SINGLE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class RateOrderedPlannerTest {
+
+  private static final String SINGLE_DEVICE_WHERE =
+      " WHERE tag1='shanghai' AND tag2='A3' AND tag3='YY'";
+  // DEVICE_3 and DEVICE_4 are both in DATA_REGION_GROUP_2, so this filter 
still produces a SINGLE
+  // aggregation over a two-device scan.
+  private static final String TWO_DEVICE_WHERE = " WHERE tag1='shanghai'";
+
+  @Test
+  public void testSingleDeviceQueryEnablesOrderedInput() {
+    assertOrdered("SELECT irate(s1, time) AS ir FROM table1" + 
SINGLE_DEVICE_WHERE);
+  }
+
+  @Test
+  public void testTwoDevicesGroupedByAllTagsEnableOrderedInput() {
+    assertOrdered(
+        "SELECT irate(s1, time) AS ir FROM table1"
+            + TWO_DEVICE_WHERE
+            + " GROUP BY tag1, tag2, tag3");
+  }
+
+  @Test
+  public void testTwoDevicesGroupedBySubsetOfTagsKeepNaiveInput() {
+    assertNotOrdered(
+        "SELECT irate(s1, time) AS ir FROM table1" + TWO_DEVICE_WHERE + " 
GROUP BY tag1");
+  }
+
+  @Test
+  public void testGlobalAggregationOverTwoDevicesKeepsNaiveInput() {
+    assertNotOrdered("SELECT irate(s1, time) AS ir FROM table1" + 
TWO_DEVICE_WHERE);
+  }
+
+  @Test
+  public void testDescendingSubqueryKeepsNaiveInput() {

Review Comment:
   With two devices, this plan is `Aggregation ← TopK ← DeviceTableScan(DESC)`: 
the TopK can't be eliminated, so `findOrderedDeviceScan` returns `null` before 
the scan-order check runs. I confirmed this with a mutant that drops the 
`scan.getScanOrder() != Ordering.ASC` condition. All eight planner tests still 
pass, and only `RateOrderedInputTest.testDescendingScanIsNotOrderedPerGroup` 
fails.
   
   With `SINGLE_DEVICE_WHERE`, the TopK is eliminated (its limit moves into the 
scan) and the plan becomes `Aggregation ← DeviceTableScan(DESC)`, which 
exercises the scan-order check at the planner level. Could this case use the 
single-device filter, or keep both variants?



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