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/07 01:41:17 UTC

[iotdb] branch master updated: [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 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 de700e5eaab [IOTDB-5970] Fix the info of order by when sortkey doesn't exist
de700e5eaab is described below

commit de700e5eaabbc452757f0d4d5912be330fcb2319
Author: YangCaiyin <yc...@gmail.com>
AuthorDate: Wed Jun 7 09:41:09 2023 +0800

    [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/V1.2.x/en.ts       |  2 +-
 site/src/main/.vuepress/sidebar/V1.2.x/zh.ts       |  2 +-
 site/src/main/.vuepress/sidebar/en.ts              |  2 +-
 site/src/main/.vuepress/sidebar/zh.ts              |  2 +-
 9 files changed, 38 insertions(+), 15 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 a96bd165a59..c43a5e133d3 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
@@ -209,6 +209,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;
 
@@ -1278,6 +1281,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(
@@ -1289,14 +1301,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);
     }
@@ -1399,17 +1419,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/V1.2.x/en.ts b/site/src/main/.vuepress/sidebar/V1.2.x/en.ts
index 45f196c1fe9..724ade04144 100644
--- a/site/src/main/.vuepress/sidebar/V1.2.x/en.ts
+++ b/site/src/main/.vuepress/sidebar/V1.2.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.2.x/zh.ts b/site/src/main/.vuepress/sidebar/V1.2.x/zh.ts
index e5d522bca18..15970dbfd52 100644
--- a/site/src/main/.vuepress/sidebar/V1.2.x/zh.ts
+++ b/site/src/main/.vuepress/sidebar/V1.2.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 7e58323069b..369aaa4968f 100644
--- a/site/src/main/.vuepress/sidebar/en.ts
+++ b/site/src/main/.vuepress/sidebar/en.ts
@@ -154,7 +154,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 e0c1b4212a5..0243b85b77c 100644
--- a/site/src/main/.vuepress/sidebar/zh.ts
+++ b/site/src/main/.vuepress/sidebar/zh.ts
@@ -154,7 +154,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' },