This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch FixUDTF in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit cfdd0e9166c7c6922bcd78aef5be5bdfcebd7838 Author: JackieTien97 <[email protected]> AuthorDate: Mon Aug 25 12:16:17 2025 +0800 Fix error of non-mappable udtf query in align by device while existing any devices' data cross region --- .../iotdb/db/queryengine/plan/analyze/Analysis.java | 2 +- .../plan/planner/distribution/SourceRewriter.java | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java index 38eed6dab7d..bfef6ad64a0 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analysis.java @@ -193,7 +193,7 @@ public class Analysis implements IAnalysis { // indicates whether DeviceView need special process when rewriteSource in DistributionPlan, // you can see SourceRewriter#visitDeviceView to get more information - // deviceViewSpecialProcess equals true when all Aggregation Functions and DIFF + // deviceViewSpecialProcess equals true when all Aggregation Functions and UDTF and DIFF private boolean deviceViewSpecialProcess; ///////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java index 21d4c5a14c6..743db35c092 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/distribution/SourceRewriter.java @@ -35,6 +35,7 @@ import org.apache.iotdb.db.queryengine.plan.analyze.Analysis; import org.apache.iotdb.db.queryengine.plan.expression.Expression; import org.apache.iotdb.db.queryengine.plan.expression.leaf.TimeSeriesOperand; import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionExpression; +import org.apache.iotdb.db.queryengine.plan.expression.multi.FunctionType; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.BaseSourceRewriter; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNode; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId; @@ -217,7 +218,7 @@ public class SourceRewriter extends BaseSourceRewriter<DistributionPlanContext> analysis.getPartitionInfo(outputDevice, context.getPartitionTimeFilter())); if (regionReplicaSets.size() > 1 && !existDeviceCrossRegion) { existDeviceCrossRegion = true; - if (analysis.isDeviceViewSpecialProcess() && aggregationCannotUseMergeSort()) { + if (analysis.isDeviceViewSpecialProcess() && cannotUseAggMergeSort()) { return processSpecialDeviceView(node, context); } } @@ -387,10 +388,12 @@ public class SourceRewriter extends BaseSourceRewriter<DistributionPlanContext> } /** - * aggregation align by device, and aggregation is `count_if` or `diff`, or aggregation used with - * group by parameter (session, variation, count), use the old aggregation logic + * 1. aggregation align by device, and aggregation is `count_if` or `diff`, or aggregation used + * with 2. group by parameter (session, variation, count), use the old aggregation logic 3. + * non-mappable UDTF, we just need to check UDTF in this method, because caller has already + * checked analysis.isDeviceViewSpecialProcess() */ - private boolean aggregationCannotUseMergeSort() { + private boolean cannotUseAggMergeSort() { if (analysis.hasGroupByParameter()) { return true; } @@ -398,7 +401,9 @@ public class SourceRewriter extends BaseSourceRewriter<DistributionPlanContext> for (Expression expression : analysis.getDeviceViewOutputExpressions()) { if (expression instanceof FunctionExpression) { String functionName = ((FunctionExpression) expression).getFunctionName(); - if (COUNT_IF.equalsIgnoreCase(functionName) || DIFF.equalsIgnoreCase(functionName)) { + if (((FunctionExpression) expression).getFunctionType() == FunctionType.UDTF + || COUNT_IF.equalsIgnoreCase(functionName) + || DIFF.equalsIgnoreCase(functionName)) { return true; } }
