Skip to content

Commit b14cdbe

Browse files
authored
Fix error message when there is no argument in sum, avg and extreme
1 parent 7f56c1b commit b14cdbe

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,5 +3653,18 @@ public void exceptionTest() {
36533653
"select s1 from table1 where s2 in (select s2 from table1)",
36543654
"701: Only TableSubquery is supported now",
36553655
DATABASE_NAME);
3656+
3657+
tableAssertTestFail(
3658+
"select avg() from table1",
3659+
"701: Aggregate functions [avg] should only have one argument",
3660+
DATABASE_NAME);
3661+
tableAssertTestFail(
3662+
"select sum() from table1",
3663+
"701: Aggregate functions [sum] should only have one argument",
3664+
DATABASE_NAME);
3665+
tableAssertTestFail(
3666+
"select extreme() from table1",
3667+
"701: Aggregate functions [extreme] should only have one argument",
3668+
DATABASE_NAME);
36563669
}
36573670
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,13 @@ && isIntegerNumber(argumentTypes.get(2)))) {
534534
case SqlConstant.VARIANCE:
535535
case SqlConstant.VAR_POP:
536536
case SqlConstant.VAR_SAMP:
537-
if (!isOneSupportedMathNumericType(argumentTypes)) {
537+
if (argumentTypes.size() != 1) {
538+
throw new SemanticException(
539+
String.format(
540+
"Aggregate functions [%s] should only have one argument", functionName));
541+
}
542+
543+
if (!isSupportedMathNumericType(argumentTypes.get(0))) {
538544
throw new SemanticException(
539545
String.format(
540546
"Aggregate functions [%s] only support numeric data types [INT32, INT64, FLOAT, DOUBLE]",

0 commit comments

Comments
 (0)