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 921652a8c88 Fix error message when there is no argument in first, 
last, first_by and last_by
921652a8c88 is described below

commit 921652a8c88abf0a6d6a13f51fd8316ed0fb90d9
Author: Weihao Li <[email protected]>
AuthorDate: Tue Nov 19 12:18:46 2024 +0800

    Fix error message when there is no argument in first, last, first_by and 
last_by
---
 .../it/query/recent/IoTDBTableAggregationIT.java         | 16 ++++++++++++++++
 .../plan/relational/sql/parser/AstBuilder.java           |  6 ++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
index 82d22dfbb09..700d738939e 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
@@ -3676,5 +3676,21 @@ public class IoTDBTableAggregationIT {
         "select extreme() from table1",
         "701: Aggregate functions [extreme] should only have one argument",
         DATABASE_NAME);
+    tableAssertTestFail(
+        "select first() from table1",
+        "701: Aggregate functions [first] should only have two arguments",
+        DATABASE_NAME);
+    tableAssertTestFail(
+        "select first_by() from table1",
+        "701: Aggregate functions [first_by] should only have three arguments",
+        DATABASE_NAME);
+    tableAssertTestFail(
+        "select last() from table1",
+        "701: Aggregate functions [last] should only have two arguments",
+        DATABASE_NAME);
+    tableAssertTestFail(
+        "select last_by() from table1",
+        "701: Aggregate functions [last_by] should only have three arguments",
+        DATABASE_NAME);
   }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
index d7f5abb27c9..b49a60718e1 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
@@ -1934,6 +1934,8 @@ public class AstBuilder extends 
RelationalSqlBaseVisitor<Node> {
               new DereferenceExpression(getLocation(ctx.label), (Identifier) 
visit(ctx.label)));
     }
 
+    // Syntactic sugar: first(s1) => first(s1,time), first_by(s1,s2) => 
first_by(s1,s2,time)
+    // So do last and last_by.
     if (name.toString().equalsIgnoreCase(FIRST_AGGREGATION)
         || name.toString().equalsIgnoreCase(LAST_AGGREGATION)) {
       if (arguments.size() == 1) {
@@ -1948,8 +1950,6 @@ public class AstBuilder extends 
RelationalSqlBaseVisitor<Node> {
                 
.equalsIgnoreCase(TimestampOperand.TIMESTAMP_EXPRESSION_STRING),
             "The second argument of 'first' or 'last' function must be 'time'",
             ctx);
-      } else {
-        throw parseError("Invalid number of arguments for 'first' or 'last' 
function", ctx);
       }
     } else if (name.toString().equalsIgnoreCase(FIRST_BY_AGGREGATION)
         || name.toString().equalsIgnoreCase(LAST_BY_AGGREGATION)) {
@@ -1965,8 +1965,6 @@ public class AstBuilder extends 
RelationalSqlBaseVisitor<Node> {
                 
.equalsIgnoreCase(TimestampOperand.TIMESTAMP_EXPRESSION_STRING),
             "The third argument of 'first_by' or 'last_by' function must be 
'time'",
             ctx);
-      } else {
-        throw parseError("Invalid number of arguments for 'first_by' or 
'last_by' function", ctx);
       }
     }
 

Reply via email to