This is an automated email from the ASF dual-hosted git repository. hui pushed a commit to branch lmh/orderBySensor in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 9024ee03380cd15704a033e8990d21bac05275ab Author: Minghui Liu <[email protected]> AuthorDate: Tue Jul 19 18:18:16 2022 +0800 add semantic check --- .../plan/statement/component/OrderByComponent.java | 24 ++++++++++++++++ .../db/mpp/plan/statement/crud/QueryStatement.java | 33 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/OrderByComponent.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/OrderByComponent.java index 1aa09bbcae..8fe478d918 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/OrderByComponent.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/component/OrderByComponent.java @@ -27,15 +27,39 @@ public class OrderByComponent { private final List<SortItem> sortItemList; + private boolean orderByTime = false; + private boolean orderByTimeseries = false; + private boolean orderByDevice = false; + public OrderByComponent() { this.sortItemList = new ArrayList<>(); } public void addSortItem(SortItem sortItem) { this.sortItemList.add(sortItem); + + if (sortItem.getSortKey() == SortItem.SortKey.TIME) { + orderByTime = true; + } else if (sortItem.getSortKey() == SortItem.SortKey.TIMESERIES) { + orderByTimeseries = true; + } else { + orderByDevice = true; + } } public List<SortItem> getSortItemList() { return sortItemList; } + + public boolean isOrderByTime() { + return orderByTime; + } + + public boolean isOrderByTimeseries() { + return orderByTimeseries; + } + + public boolean isOrderByDevice() { + return orderByDevice; + } } diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java index 2da55d6f42..ea99bd3fae 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/statement/crud/QueryStatement.java @@ -215,6 +215,18 @@ public class QueryStatement extends Statement { return resultSetFormat == ResultSetFormat.DISABLE_ALIGN; } + public boolean isOrderByTime() { + return orderByComponent != null && orderByComponent.isOrderByTime(); + } + + public boolean isOrderByTimeseries() { + return orderByComponent != null && orderByComponent.isOrderByTimeseries(); + } + + public boolean isOrderByDevice() { + return orderByComponent != null && orderByComponent.isOrderByDevice(); + } + public void semanticCheck() { if (isAggregationQuery()) { if (disableAlign()) { @@ -243,6 +255,13 @@ public class QueryStatement extends Statement { if (getWhereCondition() != null) { ExpressionAnalyzer.checkIsAllMeasurement(getWhereCondition().getPredicate()); } + if (isOrderByTimeseries()) { + throw new SemanticException("Sorting by timeseries is only supported in last queries."); + } + if (isOrderByDevice()) { + // TODO support sort by device + throw new SemanticException("Sorting by device is not yet supported."); + } } if (isLastQuery()) { @@ -258,6 +277,20 @@ public class QueryStatement extends Statement { throw new SemanticException("Last queries can only be applied on raw time series."); } } + if (isOrderByDevice()) { + throw new SemanticException( + "Sorting by device is only supported in ALIGN BY DEVICE queries."); + } + } + + if (!isAlignByDevice() && !isLastQuery()) { + if (isOrderByTimeseries()) { + throw new SemanticException("Sorting by timeseries is only supported in last queries."); + } + if (isOrderByDevice()) { + throw new SemanticException( + "Sorting by device is only supported in ALIGN BY DEVICE queries."); + } } }
