This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new a184469ada3 When querying the lastest point of alias view and normal 
series at the same time, points may be lost due to overwriting
a184469ada3 is described below

commit a184469ada3e74aa82f3975480a9ba97397fef25
Author: shuwenwei <[email protected]>
AuthorDate: Sat Jul 5 08:03:14 2025 +0800

    When querying the lastest point of alias view and normal series at the same 
time, points may be lost due to overwriting
---
 .../queryengine/plan/analyze/AnalyzeVisitor.java   | 24 ++++++++++++++++------
 .../plan/planner/LogicalPlanBuilder.java           |  4 +++-
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index 44c0e13107d..434419bf596 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -612,6 +612,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
 
     Ordering timeseriesOrdering = analysis.getTimeseriesOrderingForLastQuery();
 
+    boolean hasAliasView = false;
     for (Expression selectExpression : selectExpressions) {
       for (Expression lastQuerySourceExpression :
           bindSchemaForExpression(selectExpression, schemaTree, context)) {
@@ -622,20 +623,31 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
                   (timeSeriesOperand.isViewExpression()
                       ? timeSeriesOperand.getViewPath()
                       : timeSeriesOperand.getPath());
-          IDeviceID outputDevice =
+          IDeviceID actualDeviceID =
               
ExpressionAnalyzer.getDeviceNameInSourceExpression(timeSeriesOperand);
+          IDeviceID outputDeviceID =
+              timeSeriesOperand.isViewExpression() ? outputPath.getIDeviceID() 
: actualDeviceID;
+          if (timeSeriesOperand.isViewExpression()) {
+            deviceExistViewSet.add(outputDeviceID);
+            if (!hasAliasView) {
+              allDeviceSet.addAll(outputPathToSourceExpressionMap.keySet());
+              hasAliasView = true;
+            }
+            allDeviceSet.add(actualDeviceID);
+          } else if (hasAliasView) {
+            allDeviceSet.add(actualDeviceID);
+          }
+          // If we use actual deviceId, it may overwrite other expression of 
same measurement in
+          // Map<String, Expression>.
           outputPathToSourceExpressionMap
               .computeIfAbsent(
-                  outputDevice,
+                  outputDeviceID,
                   k ->
                       timeseriesOrdering != null
                           ? new 
TreeMap<>(timeseriesOrdering.getStringComparator())
                           : new LinkedHashMap<>())
               .put(outputPath.getMeasurement(), timeSeriesOperand);
 
-          if (timeSeriesOperand.isViewExpression()) {
-            deviceExistViewSet.add(outputDevice);
-          }
         } else {
           lastQueryNonWritableViewSourceExpressionMap =
               lastQueryNonWritableViewSourceExpressionMap == null
@@ -653,7 +665,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
     }
     if (allDeviceSet.isEmpty()) {
       allDeviceSet = outputPathToSourceExpressionMap.keySet();
-    } else {
+    } else if (!hasAliasView) {
       allDeviceSet.addAll(outputPathToSourceExpressionMap.keySet());
     }
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java
index ce0ab0fe882..84d0d84224d 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanBuilder.java
@@ -259,7 +259,9 @@ public class LogicalPlanBuilder {
                   : null;
 
           PartialPath devicePath = selectedPath.getDevicePath();
-          devicePath.setIDeviceID(deviceId);
+          // For expression with view path, we do not use the deviceId in 
Map.Entry because it is a
+          // view device.
+          devicePath.setIDeviceID(selectedPath.getIDeviceID());
           long memCost =
               lastQueryNode.addDeviceLastQueryScanNode(
                   context.getQueryId().genPlanNodeId(),

Reply via email to