You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2023/06/10 13:18:35 UTC

[iotdb] branch rel/1.2 updated: [To rel/1.2][IOTDB-5970] Fix the info of order by when sortkey doesn't exist

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

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


The following commit(s) were added to refs/heads/rel/1.2 by this push:
     new 4764aebfff6 [To rel/1.2][IOTDB-5970] Fix the info of order by when sortkey doesn't exist
4764aebfff6 is described below

commit 4764aebfff678547d73b15874c57b98e73830148
Author: YangCaiyin <yc...@gmail.com>
AuthorDate: Sat Jun 10 21:18:30 2023 +0800

    [To rel/1.2][IOTDB-5970] Fix the info of order by when sortkey doesn't exist
---
 .../iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java  | 39 ++++++++++++++++++----
 site/src/main/.vuepress/sidebar/V1.0.x/en.ts       |  1 -
 site/src/main/.vuepress/sidebar/V1.0.x/zh.ts       |  1 -
 site/src/main/.vuepress/sidebar/V1.1.x/en.ts       |  2 +-
 site/src/main/.vuepress/sidebar/V1.1.x/zh.ts       |  2 +-
 site/src/main/.vuepress/sidebar/en.ts              |  2 +-
 site/src/main/.vuepress/sidebar/zh.ts              |  2 +-
 7 files changed, 36 insertions(+), 13 deletions(-)

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 b20d445e3ba..717f7cf8408 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
@@ -210,6 +210,9 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
   private static final Expression endTimeExpression =
       TimeSeriesOperand.constructColumnHeaderExpression(ENDTIME, TSDataType.INT64);
 
+  private final List<String> lastQueryColumnNames =
+      new ArrayList<>(Arrays.asList("TIME", "TIMESERIES", "VALUE", "DATATYPE"));
+
   private final IPartitionFetcher partitionFetcher;
   private final ISchemaFetcher schemaFetcher;
 
@@ -1279,6 +1282,15 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
       analysis.setTimeseriesOrderingForLastQuery(
           queryStatement.getOrderByComponent().getTimeseriesOrder());
     }
+
+    for (SortItem sortItem : queryStatement.getSortItemList()) {
+      String sortKey = sortItem.getSortKey();
+      if (!lastQueryColumnNames.contains(sortKey.toUpperCase())) {
+        throw new SemanticException(
+            String.format(
+                "%s in order by clause doesn't exist in the result of last query.", sortKey));
+      }
+    }
   }
 
   private void analyzeOrderBy(
@@ -1290,14 +1302,22 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
       // Expression in a sortItem only indicates one column
       List<Expression> expressions =
           ExpressionAnalyzer.bindSchemaForExpression(expressionForItem, schemaTree);
-      if (expressions.size() != 1) {
-        throw new SemanticException("One sort item in order by should only indicate one value");
+      if (expressions.size() == 0) {
+        throw new SemanticException(
+            String.format(
+                "%s in order by clause doesn't exist.", expressionForItem.getExpressionString()));
+      }
+      if (expressions.size() > 1) {
+        throw new SemanticException(
+            String.format(
+                "%s in order by clause shouldn't refer to more than one timeseries.",
+                expressionForItem.getExpressionString()));
       }
       expressionForItem = ExpressionAnalyzer.removeAliasFromExpression(expressions.get(0));
       TSDataType dataType = analyzeExpression(analysis, expressionForItem);
       if (!dataType.isComparable()) {
         throw new SemanticException(
-            String.format("The data type of sort item %s is not comparable", dataType));
+            String.format("The data type of %s is not comparable", dataType));
       }
       orderByExpressions.add(expressionForItem);
     }
@@ -1400,17 +1420,22 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext>
         List<Expression> expressions =
             ExpressionAnalyzer.concatDeviceAndBindSchemaForExpression(
                 expressionForItem, device, schemaTree);
-        if (expressions.size() != 1) {
+        if (expressions.size() == 0) {
+          throw new SemanticException(
+              String.format(
+                  "%s in order by clause doesn't exist.", expressionForItem.getExpressionString()));
+        }
+        if (expressions.size() > 1) {
           throw new SemanticException(
               String.format(
-                  "One sort item in order by should only indicate one value, got %s value(s)",
-                  expressions.size()));
+                  "%s in order by clause shouldn't refer to more than one timeseries.",
+                  expressionForItem.getExpressionString()));
         }
         expressionForItem = expressions.get(0);
         TSDataType dataType = analyzeExpression(analysis, expressionForItem);
         if (!dataType.isComparable()) {
           throw new SemanticException(
-              String.format("The data type of sort item %s is not comparable", dataType));
+              String.format("The data type of %s is not comparable", dataType));
         }
 
         Expression devicerViewExpression =
diff --git a/site/src/main/.vuepress/sidebar/V1.0.x/en.ts b/site/src/main/.vuepress/sidebar/V1.0.x/en.ts
index 5b4d868b9bc..a9bf81f4d59 100644
--- a/site/src/main/.vuepress/sidebar/V1.0.x/en.ts
+++ b/site/src/main/.vuepress/sidebar/V1.0.x/en.ts
@@ -138,7 +138,6 @@ export const enSidebar = {
         { text: 'Where Condition', link: 'Where-Condition' },
         { text: 'Group By', link: 'Group-By' },
         { text: 'Having Condition', link: 'Having-Condition' },
-        // { text:  'Order By', link: 'Order-By' },
         { text: 'Fill Null Value', link: 'Fill' },
         { text: 'Pagination', link: 'Pagination' },
         { text: 'Select Into', link: 'Select-Into' },
diff --git a/site/src/main/.vuepress/sidebar/V1.0.x/zh.ts b/site/src/main/.vuepress/sidebar/V1.0.x/zh.ts
index 2f8a90d0b67..a5ecf9d16c7 100644
--- a/site/src/main/.vuepress/sidebar/V1.0.x/zh.ts
+++ b/site/src/main/.vuepress/sidebar/V1.0.x/zh.ts
@@ -138,7 +138,6 @@ export const zhSidebar = {
         { text: '查询过滤条件', link: 'Where-Condition' },
         { text: '分段分组聚合', link: 'Group-By' },
         { text: '聚合结果过滤', link: 'Having-Condition' },
-        // { text:'结果集排序', link: 'Order-By' },
         { text: '结果集补空值', link: 'Fill' },
         { text: '结果集分页', link: 'Pagination' },
         { text: '查询写回', link: 'Select-Into' },
diff --git a/site/src/main/.vuepress/sidebar/V1.1.x/en.ts b/site/src/main/.vuepress/sidebar/V1.1.x/en.ts
index f9619f0316a..6bcf03cf519 100644
--- a/site/src/main/.vuepress/sidebar/V1.1.x/en.ts
+++ b/site/src/main/.vuepress/sidebar/V1.1.x/en.ts
@@ -148,7 +148,7 @@ export const enSidebar = {
         { text: 'Where Condition', link: 'Where-Condition' },
         { text: 'Group By', link: 'Group-By' },
         { text: 'Having Condition', link: 'Having-Condition' },
-        // { text:  'Order By', link: 'Order-By' },
+        { text: 'Order By', link: 'Order-By' },
         { text: 'Fill Null Value', link: 'Fill' },
         { text: 'Pagination', link: 'Pagination' },
         { text: 'Select Into', link: 'Select-Into' },
diff --git a/site/src/main/.vuepress/sidebar/V1.1.x/zh.ts b/site/src/main/.vuepress/sidebar/V1.1.x/zh.ts
index d623ccadbab..1e8441f8422 100644
--- a/site/src/main/.vuepress/sidebar/V1.1.x/zh.ts
+++ b/site/src/main/.vuepress/sidebar/V1.1.x/zh.ts
@@ -148,7 +148,7 @@ export const zhSidebar = {
         { text: '查询过滤条件', link: 'Where-Condition' },
         { text: '分段分组聚合', link: 'Group-By' },
         { text: '聚合结果过滤', link: 'Having-Condition' },
-        // { text:'结果集排序', link: 'Order-By' },
+        { text: '结果集排序', link: 'Order-By' },
         { text: '结果集补空值', link: 'Fill' },
         { text: '结果集分页', link: 'Pagination' },
         { text: '查询写回', link: 'Select-Into' },
diff --git a/site/src/main/.vuepress/sidebar/en.ts b/site/src/main/.vuepress/sidebar/en.ts
index 97206aa7882..cdb26b81e0c 100644
--- a/site/src/main/.vuepress/sidebar/en.ts
+++ b/site/src/main/.vuepress/sidebar/en.ts
@@ -153,7 +153,7 @@ export const enSidebar = sidebar({
         { text: 'Where Condition', link: 'Where-Condition' },
         { text: 'Group By', link: 'Group-By' },
         { text: 'Having Condition', link: 'Having-Condition' },
-        // { text:  'Order By', link: 'Order-By' },
+        { text: 'Order By', link: 'Order-By' },
         { text: 'Fill Null Value', link: 'Fill' },
         { text: 'Pagination', link: 'Pagination' },
         { text: 'Select Into', link: 'Select-Into' },
diff --git a/site/src/main/.vuepress/sidebar/zh.ts b/site/src/main/.vuepress/sidebar/zh.ts
index 2115cbfc9b8..7dda3df39b4 100644
--- a/site/src/main/.vuepress/sidebar/zh.ts
+++ b/site/src/main/.vuepress/sidebar/zh.ts
@@ -153,7 +153,7 @@ export const zhSidebar = sidebar({
         { text: '查询过滤条件', link: 'Where-Condition' },
         { text: '分段分组聚合', link: 'Group-By' },
         { text: '聚合结果过滤', link: 'Having-Condition' },
-        // { text:'结果集排序', link: 'Order-By' },
+        { text: '结果集排序', link: 'Order-By' },
         { text: '结果集补空值', link: 'Fill' },
         { text: '结果集分页', link: 'Pagination' },
         { text: '查询写回', link: 'Select-Into' },