Skip to content

Commit 2bccb24

Browse files
committed
add aggregation test
1 parent 55f9384 commit 2bccb24

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/planner/ReplicaHintPlannerTest.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
2323
import org.apache.iotdb.db.queryengine.plan.planner.plan.FragmentInstance;
24+
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
25+
import org.apache.iotdb.db.queryengine.plan.relational.planner.node.AggregationNode;
2426
import org.apache.iotdb.db.queryengine.plan.relational.planner.node.TableScanNode;
2527
import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.ParsingException;
2628

@@ -32,6 +34,7 @@
3234

3335
import static org.junit.Assert.assertEquals;
3436
import static org.junit.Assert.assertTrue;
37+
import static org.junit.Assert.fail;
3538

3639
public class ReplicaHintPlannerTest extends PlanTester {
3740

@@ -91,6 +94,15 @@ public void testReplicaHintWithConflict() {
9194
}
9295
}
9396

97+
@Test
98+
public void testReplicaHintWithAgg() {
99+
String sql = "SELECT /*+ REPLICA(0) */ tag1, avg(s1) FROM table1 GROUP BY tag1";
100+
createPlan(sql);
101+
for (int fragment = 1; fragment <= 3; fragment++) {
102+
verifyReplica(fragment, ImmutableMap.of("table1", 0));
103+
}
104+
}
105+
94106
@Test
95107
public void testRegionRouteHintWithNegativeRegion() {
96108
String sql = "SELECT /*+ REGION_ROUTE((-1, 1)) */ * FROM table1";
@@ -178,18 +190,29 @@ public void testParallelHint() {
178190

179191
private void verifyReplica(int fragment, Map<String, Integer> tableToReplica) {
180192
FragmentInstance fragmentInstance = getFragmentInstance(fragment);
181-
TableScanNode fragmentPlan = (TableScanNode) getFragmentPlan(fragment);
193+
PlanNode fragmentPlan = getFragmentPlan(fragment);
194+
195+
TableScanNode tableScanNode = null;
196+
if (fragmentPlan instanceof AggregationNode) {
197+
tableScanNode = (TableScanNode) fragmentPlan.getChildren().get(0);
198+
} else if (fragmentPlan instanceof TableScanNode) {
199+
tableScanNode = (TableScanNode) fragmentPlan;
200+
}
201+
if (tableScanNode == null) {
202+
fail("tableScanNode must not be null");
203+
}
204+
182205
assertEquals(
183-
fragmentPlan.getRegionReplicaSet().getRegionId().getId(),
206+
tableScanNode.getRegionReplicaSet().getRegionId().getId(),
184207
fragmentInstance.getRegionReplicaSet().getRegionId().getId());
185208

186209
String tableName =
187-
fragmentPlan.getAlias() != null
188-
? fragmentPlan.getAlias().getValue()
189-
: fragmentPlan.getQualifiedObjectName().getObjectName();
210+
tableScanNode.getAlias() != null
211+
? tableScanNode.getAlias().getValue()
212+
: tableScanNode.getQualifiedObjectName().getObjectName();
190213

191214
List<TDataNodeLocation> replicaNodes =
192-
fragmentPlan.getRegionReplicaSet().getDataNodeLocations();
215+
tableScanNode.getRegionReplicaSet().getDataNodeLocations();
193216
TDataNodeLocation queryNode = fragmentInstance.getHostDataNode();
194217

195218
assertEquals(2, replicaNodes.size());

0 commit comments

Comments
 (0)