You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2022/07/26 14:33:11 UTC

[iotdb] branch lmh/FixGroupByLevelHeader updated (d69208519d -> 3e6cdaf48a)

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

hui pushed a change to branch lmh/FixGroupByLevelHeader
in repository https://gitbox.apache.org/repos/asf/iotdb.git


    from d69208519d fix incorrect column name in some scenarios for group by level query
     new 48c6f0a787 add IT & bug fix
     new 3e6cdaf48a add IT & bug fix

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/iotdb/db/it/query/IoTDBAliasIT.java | 27 ++++++++++++++++++++++
 .../iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java  | 10 +++++++-
 .../mpp/plan/analyze/GroupByLevelController.java   | 16 ++++++++++---
 3 files changed, 49 insertions(+), 4 deletions(-)


[iotdb] 01/02: add IT & bug fix

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hui pushed a commit to branch lmh/FixGroupByLevelHeader
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 48c6f0a7879dba882083a72f54d3e072f5ff989e
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Tue Jul 26 20:58:25 2022 +0800

    add IT & bug fix
---
 .../org/apache/iotdb/db/it/query/IoTDBAliasIT.java | 27 ++++++++++++++++++++++
 .../iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java  | 10 +++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java
index 8ef5fc7181..68b988c11c 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java
@@ -381,4 +381,31 @@ public class IoTDBAliasIT {
       resultSetEqualTest(sqls.get(i), expectHeaders.get(i), retArrays.get(i));
     }
   }
+
+  // ------------------------------------ Function name --------------------------------------
+
+  @Test
+  public void aggregationFuncNameTest() {
+    String expectedHeader =
+        "count(root.sg.d1.temperature),count(root.sg.d2.temperature),"
+            + "COUNT(root.sg.d1.temperature),COUNT(root.sg.d2.temperature),"
+            + "CoUnT(root.sg.d1.temperature),CoUnT(root.sg.d2.temperature),";
+    String[] retArray = new String[] {"4,4,4,4,4,4,"};
+
+    resultSetEqualTest(
+        "select count(temperature),COUNT(temperature),CoUnT(temperature) from root.sg.*",
+        expectedHeader,
+        retArray);
+  }
+
+  @Test
+  public void groupByLevelFuncNameTest() {
+    String expectedHeader = "count(root.sg.*.s2),COUNT(root.sg.*.s2),CoUnT(root.sg.*.s2),";
+    String[] retArray = new String[] {"8,8,8,"};
+
+    resultSetEqualTest(
+        "select count(s2),COUNT(s2),CoUnT(s2) from root.sg.* group by level = 1",
+        expectedHeader,
+        retArray);
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
index c36085b9f5..412c920162 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java
@@ -684,10 +684,18 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
                 groupedExpression,
                 groupByLevelController.getAlias(groupedExpression.getExpressionString()));
         Expression groupedExpressionWithoutAlias = outputExpression.left;
+
+        Set<Expression> rawExpressions = rawGroupByLevelExpressions.get(groupedExpression);
+        rawExpressions.forEach(
+            expression -> ExpressionAnalyzer.updateTypeProvider(expression, typeProvider));
+        rawExpressions.forEach(expression -> expression.inferTypes(typeProvider));
+
         Set<Expression> rawExpressionsWithoutAlias =
-            rawGroupByLevelExpressions.get(groupedExpression).stream()
+            rawExpressions.stream()
                 .map(ExpressionAnalyzer::removeAliasFromExpression)
                 .collect(Collectors.toSet());
+        rawExpressionsWithoutAlias.forEach(
+            expression -> ExpressionAnalyzer.updateTypeProvider(expression, typeProvider));
         rawExpressionsWithoutAlias.forEach(expression -> expression.inferTypes(typeProvider));
 
         groupByLevelExpressions.put(groupedExpressionWithoutAlias, rawExpressionsWithoutAlias);


[iotdb] 02/02: add IT & bug fix

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hui pushed a commit to branch lmh/FixGroupByLevelHeader
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 3e6cdaf48a0bd1191dedc1bf33e3185915bfe33b
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Tue Jul 26 22:32:48 2022 +0800

    add IT & bug fix
---
 .../java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java  |  8 ++++----
 .../db/mpp/plan/analyze/GroupByLevelController.java      | 16 +++++++++++++---
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java
index 68b988c11c..21bc7371bd 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBAliasIT.java
@@ -388,23 +388,23 @@ public class IoTDBAliasIT {
   public void aggregationFuncNameTest() {
     String expectedHeader =
         "count(root.sg.d1.temperature),count(root.sg.d2.temperature),"
-            + "COUNT(root.sg.d1.temperature),COUNT(root.sg.d2.temperature),"
+            + "COUNT(root.sg.d1.s2),COUNT(root.sg.d2.s2),"
             + "CoUnT(root.sg.d1.temperature),CoUnT(root.sg.d2.temperature),";
     String[] retArray = new String[] {"4,4,4,4,4,4,"};
 
     resultSetEqualTest(
-        "select count(temperature),COUNT(temperature),CoUnT(temperature) from root.sg.*",
+        "select count(temperature),COUNT(s2),CoUnT(temperature) from root.sg.*",
         expectedHeader,
         retArray);
   }
 
   @Test
   public void groupByLevelFuncNameTest() {
-    String expectedHeader = "count(root.sg.*.s2),COUNT(root.sg.*.s2),CoUnT(root.sg.*.s2),";
+    String expectedHeader = "count(root.sg.*.s2),COUNT(root.sg.*.temperature),CoUnT(root.sg.*.s2),";
     String[] retArray = new String[] {"8,8,8,"};
 
     resultSetEqualTest(
-        "select count(s2),COUNT(s2),CoUnT(s2) from root.sg.* group by level = 1",
+        "select count(s2),COUNT(temperature),CoUnT(s2) from root.sg.* group by level = 1",
         expectedHeader,
         retArray);
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/GroupByLevelController.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/GroupByLevelController.java
index a583805e33..4f8da81f15 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/GroupByLevelController.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/GroupByLevelController.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.commons.conf.IoTDBConstant;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
+import org.apache.iotdb.db.metadata.path.MeasurementPath;
 import org.apache.iotdb.db.mpp.plan.expression.Expression;
 import org.apache.iotdb.db.mpp.plan.expression.leaf.TimeSeriesOperand;
 import org.apache.iotdb.db.mpp.plan.expression.multi.FunctionExpression;
@@ -81,7 +82,7 @@ public class GroupByLevelController {
     }
 
     PartialPath rawPath = ((TimeSeriesOperand) expression.getExpressions().get(0)).getPath();
-    PartialPath groupedPath = generatePartialPathByLevel(isCountStar, rawPath.getNodes(), levels);
+    PartialPath groupedPath = generatePartialPathByLevel(isCountStar, rawPath, levels);
 
     checkDatatypeConsistency(
         groupedPath.getFullPath(), ((FunctionExpression) expression).getFunctionName(), rawPath);
@@ -179,7 +180,8 @@ public class GroupByLevelController {
    * @return result partial path
    */
   public PartialPath generatePartialPathByLevel(
-      boolean isCountStar, String[] nodes, int[] pathLevels) {
+      boolean isCountStar, PartialPath rawPath, int[] pathLevels) {
+    String[] nodes = rawPath.getNodes();
     Set<Integer> levelSet = new HashSet<>();
     for (int level : pathLevels) {
       levelSet.add(level);
@@ -200,7 +202,15 @@ public class GroupByLevelController {
     } else {
       transformedNodes.add(nodes[nodes.length - 1]);
     }
-    return new PartialPath(transformedNodes.toArray(new String[0]));
+
+    MeasurementPath groupedPath =
+        new MeasurementPath(
+            new PartialPath(transformedNodes.toArray(new String[0])),
+            ((MeasurementPath) rawPath).getMeasurementSchema());
+    if (rawPath.isMeasurementAliasExists()) {
+      groupedPath.setMeasurementAlias(rawPath.getMeasurementAlias());
+    }
+    return groupedPath;
   }
 
   public Map<Expression, Set<Expression>> getGroupedPathMap() {