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 73476e00a9a Fix back-quote remove of Select-Into query when query is 
not for raw data
73476e00a9a is described below

commit 73476e00a9a94e4b4f6b80b93b57c0ea944a7054
Author: Weihao Li <[email protected]>
AuthorDate: Mon Dec 2 14:43:30 2024 +0800

    Fix back-quote remove of Select-Into query when query is not for raw data
---
 .../iotdb/db/it/selectinto/IoTDBSelectIntoIT.java  | 49 ++++++++++++++++++++++
 .../queryengine/plan/analyze/AnalyzeVisitor.java   |  6 ++-
 .../queryengine/plan/analyze/SelectIntoUtils.java  | 12 ++++++
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
index f6dde78db7f..b92176d182d 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
@@ -806,4 +806,53 @@ public class IoTDBSelectIntoIT {
     String expectedQueryHeader = 
"Time,root.db.d2.s7,root.db.d2.s8,root.db.d2.s9,root.db.d2.s10,";
     resultSetEqualTest("select s7,s8,s9,s10 from root.db.d2;", 
expectedQueryHeader, resultSet);
   }
+
+  // -------------------------------------- OTHER TEST 
-------------------------------------
+  @Test
+  public void testRemoveBackQuote() {
+    String[] intoRetArray =
+        new String[] {
+          "count(root.sg.d1.s1),root.sg_agg1.d1.count_s1,1,",
+          "last_value(root.sg.d1.s2),root.sg_agg1.d1.last_value_s2,1,",
+          "count(root.sg.d2.s1),root.sg_agg1.d2.count_s1,1,",
+          "last_value(root.sg.d2.s2),root.sg_agg1.d2.last_value_s2,1,"
+        };
+    resultSetEqualTest(
+        "select count(d1.s1), last_value(d1.s2), count(d2.s1), 
last_value(d2.s2) "
+            + "into root.sg_agg1.`d1`(`count_s1`, last_value_s2), aligned 
root.sg_agg1.d2(count_s1, last_value_s2) "
+            + "from root.sg;",
+        selectIntoHeader,
+        intoRetArray);
+
+    String expectedQueryHeader =
+        
"Time,root.sg_agg1.d1.count_s1,root.sg_agg1.d2.count_s1,root.sg_agg1.d1.last_value_s2,root.sg_agg1.d2.last_value_s2,";
+    String[] queryRetArray = new String[] {"0,10,7,12.0,11.0,"};
+    resultSetEqualTest(
+        "select count_s1, last_value_s2 from root.sg_agg1.d1, 
root.sg_agg1.d2;",
+        expectedQueryHeader,
+        queryRetArray);
+  }
+
+  @Test
+  public void testRemoveBackQuoteAlignByDevice() {
+    String[] intoRetArray =
+        new String[] {
+          "root.sg.d1,count(s1),root.sg_abd_agg1.d1.count_s1,1,",
+          "root.sg.d1,last_value(s2),root.sg_abd_agg1.d1.last_value_s2,1,"
+        };
+    resultSetEqualTest(
+        "select count(s1), last_value(s2) "
+            + "into root.sg_abd_agg1.`d1`(`count_s1`, last_value_s2) "
+            + "from root.sg.d1 align by device;",
+        selectIntoAlignByDeviceHeader,
+        intoRetArray);
+
+    String expectedQueryHeader =
+        "Time,root.sg_abd_agg1.d1.count_s1," + 
"root.sg_abd_agg1.d1.last_value_s2,";
+    String[] queryRetArray = new String[] {"0,10,12.0,"};
+    resultSetEqualTest(
+        "select count_s1, last_value_s2 from root.sg_abd_agg1.d1, 
root.sg_abd_agg1.d2;",
+        expectedQueryHeader,
+        queryRetArray);
+  }
 }
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 b855603bd9c..dd5f7ed93b2 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
@@ -221,8 +221,10 @@ import static 
org.apache.iotdb.db.queryengine.plan.analyze.ExpressionTypeAnalyze
 import static 
org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetDevice;
 import static 
org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetMeasurement;
 import static 
org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetPath;
+import static 
org.apache.iotdb.db.queryengine.plan.analyze.SelectIntoUtils.constructTargetPathWithoutPlaceHolder;
 import static 
org.apache.iotdb.db.queryengine.plan.optimization.LimitOffsetPushDown.canPushDownLimitOffsetInGroupByTimeForDevice;
 import static 
org.apache.iotdb.db.queryengine.plan.optimization.LimitOffsetPushDown.pushDownLimitOffsetInGroupByTimeForDevice;
+import static 
org.apache.iotdb.db.queryengine.plan.parser.ASTVisitor.parseNodeString;
 import static 
org.apache.iotdb.db.schemaengine.schemaregion.view.visitor.GetSourcePathsVisitor.getSourcePaths;
 import static 
org.apache.iotdb.db.storageengine.load.metrics.LoadTsFileCostMetricsSet.ANALYSIS;
 import static org.apache.iotdb.db.utils.constant.SqlConstant.COUNT_TIME_HEADER;
@@ -2371,7 +2373,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
                       pair.right == null ? sourceColumn.getExpressionString() 
: pair.right),
                   measurementTemplate);
         } else {
-          targetMeasurement = measurementTemplate;
+          targetMeasurement = parseNodeString(measurementTemplate);
         }
         deviceViewIntoPathDescriptor.specifyTargetDeviceMeasurement(
             sourceDevice, targetDevice, sourceColumn.getExpressionString(), 
targetMeasurement);
@@ -2450,7 +2452,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
         }
         targetPath = constructTargetPath(sourcePath, deviceTemplate, 
measurementTemplate);
       } else {
-        targetPath = 
deviceTemplate.concatAsMeasurementPath(measurementTemplate);
+        targetPath = constructTargetPathWithoutPlaceHolder(deviceTemplate, 
measurementTemplate);
       }
       intoPathDescriptor.specifyTargetPath(sourceColumn, viewPath, targetPath);
       intoPathDescriptor.specifyDeviceAlignment(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/SelectIntoUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/SelectIntoUtils.java
index 97994ad0806..9245d2eb634 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/SelectIntoUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/SelectIntoUtils.java
@@ -48,6 +48,18 @@ public class SelectIntoUtils {
     // forbidding instantiation
   }
 
+  public static PartialPath constructTargetPathWithoutPlaceHolder(
+      PartialPath devicePath, String measurement) {
+    String[] originalDeviceNodes = devicePath.getNodes();
+    String[] resNodes = new String[originalDeviceNodes.length + 1];
+
+    for (int i = 0; i < originalDeviceNodes.length; i++) {
+      resNodes[i] = parseNodeString(originalDeviceNodes[i]);
+    }
+    resNodes[resNodes.length - 1] = parseNodeString(measurement);
+    return new MeasurementPath(resNodes);
+  }
+
   public static PartialPath constructTargetPath(
       PartialPath sourcePath, PartialPath deviceTemplate, String 
measurementTemplate) {
     PartialPath targetDevice = 
constructTargetDevice(sourcePath.getDevicePath(), deviceTemplate);

Reply via email to