Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.iotdb.db.queryengine.common.QueryId;
import org.apache.iotdb.db.queryengine.plan.analyze.Analysis;
import org.apache.iotdb.db.queryengine.plan.planner.plan.DistributedQueryPlan;
import org.apache.iotdb.db.queryengine.plan.planner.plan.FragmentInstance;
import org.apache.iotdb.db.queryengine.plan.planner.plan.LogicalQueryPlan;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.process.AggregationMergeSortNode;
Expand All @@ -48,6 +49,7 @@
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class AlignByDeviceOrderByLimitOffsetTest {
Expand Down Expand Up @@ -733,6 +735,24 @@ public void orderByTimeTest6() {
instanceof SeriesAggregationScanNode);
}

private static TopKNode firstTopKChild(LimitNode lim) {
if (lim.getChild() instanceof TopKNode) {
return (TopKNode) lim.getChild();
}
if (lim.getChild() instanceof ExchangeNode
&& !lim.getChild().getChildren().isEmpty()
&& lim.getChild().getChildren().get(0) instanceof TopKNode) {
return (TopKNode) lim.getChild().getChildren().get(0);
}
return null;
}

private static boolean contains(PlanNode n, Class<?> clazz) {
if (clazz.isInstance(n)) return true;
for (PlanNode c : n.getChildren()) if (contains(c, clazz)) return true;
return false;
}

@Test
public void orderByTimeWithOffsetTest() {
// order by time, offset + limit
Expand All @@ -746,24 +766,36 @@ public void orderByTimeWithOffsetTest() {
planner = new DistributionPlanner(analysis, new LogicalQueryPlan(context, logicalPlanNode));
plan = planner.planFragments();
assertEquals(4, plan.getInstances().size());
firstFiRoot = plan.getInstances().get(0).getFragment().getPlanNodeTree();
PlanNode firstFIFirstNode = firstFiRoot.getChildren().get(0);
assertTrue(firstFIFirstNode instanceof LimitNode);
PlanNode firstFiTopNode = ((LimitNode) firstFIFirstNode).getChild().getChildren().get(0);
for (PlanNode node : firstFiTopNode.getChildren().get(0).getChildren()) {
assertTrue(node instanceof SingleDeviceViewNode);
LimitNode rootLimit = null;
FragmentInstance limitFI = null;

for (FragmentInstance fi : plan.getInstances()) {
PlanNode root = fi.getFragment().getPlanNodeTree();
if (!root.getChildren().isEmpty() && root.getChildren().get(0) instanceof LimitNode) {
rootLimit = (LimitNode) root.getChildren().get(0);
limitFI = fi;
break;
}
if (!root.getChildren().isEmpty()
&& root.getChildren().get(0) instanceof ExchangeNode
&& !root.getChildren().get(0).getChildren().isEmpty()
&& root.getChildren().get(0).getChildren().get(0) instanceof LimitNode) {
rootLimit = (LimitNode) root.getChildren().get(0).getChildren().get(0);
limitFI = fi;
break;
}
}
assertNotNull("no root-level LimitNode found", rootLimit);
assertTrue(
"Limit subtree lacks SingleDeviceViewNode",
contains(rootLimit, SingleDeviceViewNode.class));
long exchCnt =
rootLimit.getChild().getChildren().stream().filter(c -> c instanceof ExchangeNode).count();
assertTrue("too many Exchange under Limit subtree", exchCnt <= 3);
long expected = LIMIT_VALUE * 2;
for (FragmentInstance fi : plan.getInstances()) {
assertScanNodeLimitValue(fi.getFragment().getPlanNodeTree(), expected);
}
assertTrue(firstFiTopNode.getChildren().get(1) instanceof ExchangeNode);
assertTrue(firstFiTopNode.getChildren().get(2) instanceof ExchangeNode);
assertTrue(firstFiTopNode.getChildren().get(3) instanceof ExchangeNode);
assertScanNodeLimitValue(
plan.getInstances().get(0).getFragment().getPlanNodeTree(), LIMIT_VALUE * 2);
assertScanNodeLimitValue(
plan.getInstances().get(1).getFragment().getPlanNodeTree(), LIMIT_VALUE * 2);
assertScanNodeLimitValue(
plan.getInstances().get(2).getFragment().getPlanNodeTree(), LIMIT_VALUE * 2);
assertScanNodeLimitValue(
plan.getInstances().get(3).getFragment().getPlanNodeTree(), LIMIT_VALUE * 2);
}

/*
Expand Down