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 84b56d27b6b Improve argument validation for approx_most_frequent 
function
84b56d27b6b is described below

commit 84b56d27b6b1900d482de3aeabe2044c80a7ee5a
Author: FearfulTomcat27 <[email protected]>
AuthorDate: Thu Jun 19 15:01:56 2025 +0800

    Improve argument validation for approx_most_frequent function
---
 .../relational/it/query/recent/IoTDBTableAggregationIT.java    | 10 +++++++++-
 .../db/queryengine/plan/relational/sql/parser/AstBuilder.java  | 10 ++++------
 2 files changed, 13 insertions(+), 7 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 fc3546f9f86..ec13fa95bbb 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
@@ -4343,7 +4343,15 @@ public class IoTDBTableAggregationIT {
         DATABASE_NAME);
     tableAssertTestFail(
         "select approx_most_frequent(province, 'test', 100) from table1",
-        "701: The second and third argument of 'approx_most_frequent' function 
must be numeric literal",
+        "701: The second and third argument of 'approx_most_frequent' function 
must be positive integer literal",
+        DATABASE_NAME);
+    tableAssertTestFail(
+        "select approx_most_frequent(province, 1.5, 100) from table1",
+        "701: The second and third argument of 'approx_most_frequent' function 
must be positive integer literal",
+        DATABASE_NAME);
+    tableAssertTestFail(
+        "select approx_most_frequent() from table1",
+        "701: Aggregation functions [approx_most_frequent] 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 9e116020dba..268379e6b12 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
@@ -3269,19 +3269,17 @@ public class AstBuilder extends 
RelationalSqlBaseVisitor<Node> {
             "The second argument of 'approx_count_distinct' function must be a 
literal");
       }
     } else if (name.toString().equalsIgnoreCase(APPROX_MOST_FREQUENT)) {
-      if (!isNumericLiteral(arguments.get(1)) || 
!isNumericLiteral(arguments.get(2))) {
+      if (arguments.size() == 3
+          && (!(arguments.get(1) instanceof LongLiteral)
+              || !(arguments.get(2) instanceof LongLiteral))) {
         throw new SemanticException(
-            "The second and third argument of 'approx_most_frequent' function 
must be numeric literal");
+            "The second and third argument of 'approx_most_frequent' function 
must be positive integer literal");
       }
     }
 
     return new FunctionCall(getLocation(ctx), name, window, nulls, distinct, 
mode, arguments);
   }
 
-  public boolean isNumericLiteral(Expression expression) {
-    return expression instanceof LongLiteral || expression instanceof 
DoubleLiteral;
-  }
-
   @Override
   public Node visitDateBinGapFill(RelationalSqlParser.DateBinGapFillContext 
ctx) {
     TimeDuration timeDuration = 
DateTimeUtils.constructTimeDuration(ctx.timeDuration().getText());

Reply via email to