Skip to content

Commit ef0e45e

Browse files
authored
Fix error of non-mappable udtf query in align by device while existing any devices' data cross region
1 parent 67c450b commit ef0e45e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ aggregation results last_value(temperature) and last_value(status), whereas buck
193193

194194
// indicates whether DeviceView need special process when rewriteSource in DistributionPlan,
195195
// you can see SourceRewriter#visitDeviceView to get more information
196-
// deviceViewSpecialProcess equals true when all Aggregation Functions and DIFF
196+
// deviceViewSpecialProcess equals true when all Aggregation Functions and non-mappable UDTF and
197+
// DIFF
197198
private boolean deviceViewSpecialProcess;
198199

199200
/////////////////////////////////////////////////////////////////////////////////////////////////

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.iotdb.db.queryengine.plan.expression.Expression;
3636
import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand;
3737
import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionExpression;
38+
import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionType;
3839
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.BaseSourceRewriter;
3940
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode;
4041
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
@@ -217,7 +218,7 @@ public List<PlanNode> visitDeviceView(DeviceViewNode node, DistributionPlanConte
217218
analysis.getPartitionInfo(outputDevice, context.getPartitionTimeFilter()));
218219
if (regionReplicaSets.size() > 1 && !existDeviceCrossRegion) {
219220
existDeviceCrossRegion = true;
220-
if (analysis.isDeviceViewSpecialProcess() && aggregationCannotUseMergeSort()) {
221+
if (analysis.isDeviceViewSpecialProcess() && cannotUseAggMergeSort()) {
221222
return processSpecialDeviceView(node, context);
222223
}
223224
}
@@ -387,18 +388,22 @@ private static List<Expression> getWithDeviceExpressions(
387388
}
388389

389390
/**
390-
* aggregation align by device, and aggregation is `count_if` or `diff`, or aggregation used with
391-
* group by parameter (session, variation, count), use the old aggregation logic
391+
* 1. aggregation align by device, and aggregation is `count_if` or `diff`, or aggregation used
392+
* with 2. group by parameter (session, variation, count), use the old aggregation logic 3.
393+
* non-mappable UDTF, we just need to check UDTF in this method, because caller has already
394+
* checked analysis.isDeviceViewSpecialProcess()
392395
*/
393-
private boolean aggregationCannotUseMergeSort() {
396+
private boolean cannotUseAggMergeSort() {
394397
if (analysis.hasGroupByParameter()) {
395398
return true;
396399
}
397400

398401
for (Expression expression : analysis.getDeviceViewOutputExpressions()) {
399402
if (expression instanceof FunctionExpression) {
400403
String functionName = ((FunctionExpression) expression).getFunctionName();
401-
if (COUNT_IF.equalsIgnoreCase(functionName) || DIFF.equalsIgnoreCase(functionName)) {
404+
if (((FunctionExpression) expression).getFunctionType() == FunctionType.UDTF
405+
|| COUNT_IF.equalsIgnoreCase(functionName)
406+
|| DIFF.equalsIgnoreCase(functionName)) {
402407
return true;
403408
}
404409
}

0 commit comments

Comments
 (0)