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 48fff510224 [IOTDB-5890] [IOTDB-5891] Fix messages problem in order by
48fff510224 is described below
commit 48fff5102247ec6877c3066fbe518a715d934bc5
Author: YangCaiyin <[email protected]>
AuthorDate: Sun May 21 09:54:42 2023 +0800
[IOTDB-5890] [IOTDB-5891] Fix messages problem in order by
---
.../apache/iotdb/db/it/orderBy/IoTDBOrderByIT.java | 26 +++++++++++++
.../resources/conf/iotdb-common.properties | 2 +-
.../java/org/apache/iotdb/db/conf/IoTDBConfig.java | 2 +-
.../db/mpp/plan/statement/crud/QueryStatement.java | 45 +++++++++++++---------
4 files changed, 55 insertions(+), 20 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/orderBy/IoTDBOrderByIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/orderBy/IoTDBOrderByIT.java
index 70dac5729d3..bbc859b0255 100644
---
a/integration-test/src/test/java/org/apache/iotdb/db/it/orderBy/IoTDBOrderByIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/orderBy/IoTDBOrderByIT.java
@@ -1223,4 +1223,30 @@ public class IoTDBOrderByIT {
int[] ans = {12, 14, 13, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
orderByUDFTest(sql, ans);
}
+
+ @Test
+ public void errorTest1() {
+ String sql = "select num from root.sg.d order by avg(bigNum)";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ try (ResultSet resultSet = statement.executeQuery(sql)) {
+ fail();
+ }
+ } catch (Exception e) {
+ assertEquals("701: Raw data and aggregation hybrid query is not
supported.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void errorTest2() {
+ String sql = "select avg(num) from root.sg.d order by bigNum";
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ try (ResultSet resultSet = statement.executeQuery(sql)) {
+ fail();
+ }
+ } catch (Exception e) {
+ assertEquals("701: Raw data and aggregation hybrid query is not
supported.", e.getMessage());
+ }
+ }
}
diff --git a/node-commons/src/assembly/resources/conf/iotdb-common.properties
b/node-commons/src/assembly/resources/conf/iotdb-common.properties
index f492bf2e99a..405a58b161b 100644
--- a/node-commons/src/assembly/resources/conf/iotdb-common.properties
+++ b/node-commons/src/assembly/resources/conf/iotdb-common.properties
@@ -451,7 +451,7 @@ cluster_name=defaultCluster
# The memory for external sort in sort operator, when the data size is smaller
than sort_buffer_size_in_bytes, the sort operator will use in-memory sort.
# Datatype: long
-# sort_buffer_size_in_bytes=52428800
+# sort_buffer_size_in_bytes=1048576
####################
### Storage Engine Configuration
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index 7b3ec1b493c..838e8e3e232 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -421,7 +421,7 @@ public class IoTDBConfig {
private boolean enableMLNodeService = false;
/** The buffer for sort operation */
- private long sortBufferSize = 50 * 1024 * 1024L;
+ private long sortBufferSize = 1024 * 1024L;
/**
* The strategy of inner space compaction task. There are just one inner
space compaction strategy
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 c2cfae97f0d..984db33270f 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
@@ -38,6 +38,7 @@ import
org.apache.iotdb.db.mpp.plan.statement.component.GroupByTimeComponent;
import org.apache.iotdb.db.mpp.plan.statement.component.HavingCondition;
import org.apache.iotdb.db.mpp.plan.statement.component.IntoComponent;
import org.apache.iotdb.db.mpp.plan.statement.component.OrderByComponent;
+import org.apache.iotdb.db.mpp.plan.statement.component.OrderByKey;
import org.apache.iotdb.db.mpp.plan.statement.component.Ordering;
import org.apache.iotdb.db.mpp.plan.statement.component.ResultColumn;
import org.apache.iotdb.db.mpp.plan.statement.component.ResultSetFormat;
@@ -307,6 +308,24 @@ public class QueryStatement extends Statement {
return groupByComponent != null && groupByComponent.getWindowType() ==
WindowType.COUNT_WINDOW;
}
+ private boolean hasAggregationFunction(Expression expression) {
+ if (expression instanceof FunctionExpression) {
+ if (!expression.isBuiltInAggregationFunctionExpression()) {
+ return false;
+ }
+ } else {
+ if (expression instanceof TimeSeriesOperand) {
+ return false;
+ }
+ for (Expression subExpression : expression.getExpressions()) {
+ if (!subExpression.isBuiltInAggregationFunctionExpression()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
public boolean hasGroupByExpression() {
return isGroupByVariation() || isGroupByCondition() || isGroupByCount();
}
@@ -473,20 +492,8 @@ public class QueryStatement extends Statement {
: resultColumn.getExpression().getExpressionString());
}
for (Expression expression : getExpressionSortItemList()) {
- if (expression instanceof FunctionExpression) {
- if (!expression.isBuiltInAggregationFunctionExpression()) {
- throw new SemanticException("Raw data and aggregation hybrid query
is not supported.");
- }
- } else {
- if (expression instanceof TimeSeriesOperand) {
- throw new SemanticException("Raw data and aggregation hybrid query
is not supported.");
- }
- for (Expression subExpression : expression.getExpressions()) {
- if (!subExpression.isBuiltInAggregationFunctionExpression()) {
- throw new SemanticException(
- "Raw data and aggregation hybrid query is not supported.");
- }
- }
+ if (!hasAggregationFunction(expression)) {
+ throw new SemanticException("Raw data and aggregation hybrid query
is not supported.");
}
}
if (isGroupByTag()) {
@@ -517,10 +524,8 @@ public class QueryStatement extends Statement {
"Common queries and aggregated queries are not allowed to appear
at the same time");
}
for (Expression expression : getExpressionSortItemList()) {
- for (Expression subExpression : expression.getExpressions()) {
- if (subExpression.isBuiltInAggregationFunctionExpression()) {
- throw new SemanticException("Raw data and aggregation hybrid query
is not supported.");
- }
+ if (hasAggregationFunction(expression)) {
+ throw new SemanticException("Raw data and aggregation hybrid query
is not supported.");
}
}
}
@@ -570,6 +575,10 @@ public class QueryStatement extends Statement {
}
if (isLastQuery()) {
+ if (getSortItemList().size() == 1
+ &&
!getSortItemList().get(0).getSortKey().equals(OrderByKey.TIMESERIES)) {
+ throw new SemanticException("Last query only support sorting by
timeseries now.");
+ }
if (isAlignByDevice()) {
throw new SemanticException("Last query doesn't support align by
device.");
}