This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 612c84a9653 [Enhancement](planner) Support string input for 
sql_select_limit (#34177)
612c84a9653 is described below

commit 612c84a96531021ecaf7aa90bc69be0d84de9106
Author: zy-kkk <[email protected]>
AuthorDate: Sat Apr 27 01:34:35 2024 +0800

    [Enhancement](planner) Support string input for sql_select_limit (#34177)
---
 .../org/apache/doris/qe/VariableVarConverters.java | 23 ++++++++++++++++++++++
 .../session_variable/test_default_limit.groovy     | 14 +++++++++++++
 2 files changed, 37 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableVarConverters.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableVarConverters.java
index bea61557442..789e9933daa 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableVarConverters.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableVarConverters.java
@@ -48,6 +48,8 @@ public class VariableVarConverters {
         converters.put(SessionVariable.RUNTIME_FILTER_TYPE, 
runtimeFilterTypeConverter);
         ValidatePasswordPolicyConverter validatePasswordPolicyConverter = new 
ValidatePasswordPolicyConverter();
         converters.put(GlobalVariable.VALIDATE_PASSWORD_POLICY, 
validatePasswordPolicyConverter);
+        SqlSelectLimitConverter sqlSelectLimitConverter = new 
SqlSelectLimitConverter();
+        converters.put(SessionVariable.SQL_SELECT_LIMIT, 
sqlSelectLimitConverter);
     }
 
     public static Boolean hasConverter(String varName) {
@@ -96,6 +98,27 @@ public class VariableVarConverters {
         }
     }
 
+    // Converter to convert sql select limit variable
+    public static class SqlSelectLimitConverter implements 
VariableVarConverterI {
+        @Override
+        public Long encode(String value) throws DdlException {
+            if (value.equalsIgnoreCase("DEFAULT")) {
+                return Long.MAX_VALUE;
+            } else {
+                try {
+                    return Long.parseLong(value);
+                } catch (NumberFormatException e) {
+                    throw new DdlException("Invalid sql_select_limit value: " 
+ value);
+                }
+            }
+        }
+
+        @Override
+        public String decode(Long value) throws DdlException {
+            return String.valueOf(value);
+        }
+    }
+
     public static class ValidatePasswordPolicyConverter implements 
VariableVarConverterI {
         @Override
         public Long encode(String value) throws DdlException {
diff --git 
a/regression-test/suites/query_p0/session_variable/test_default_limit.groovy 
b/regression-test/suites/query_p0/session_variable/test_default_limit.groovy
index 4133ccc3397..2ce3b647142 100644
--- a/regression-test/suites/query_p0/session_variable/test_default_limit.groovy
+++ b/regression-test/suites/query_p0/session_variable/test_default_limit.groovy
@@ -277,5 +277,19 @@ suite('test_default_limit', "arrow_flight_sql") {
             order by c.k1, baseall.k2 limit 8
         '''
         assertEquals(res.size(), 8)
+
+        // Test setting sql_select_limit with the string "DEFAULT"
+        sql 'set sql_select_limit = "DEFAULT"'
+        res = sql 'select * from baseall'
+        assertEquals(res.size(), 16)  // Expecting the default limit to show 
all rows
+
+        // Test setting sql_select_limit with an explicit numeric string
+        sql 'set sql_select_limit = "10"'
+        res = sql 'select * from baseall'
+        assertEquals(res.size(), 10)  // Expecting the limit to restrict the 
results to 10 rows
+
+        // Reset the sql_select_limit to no limit for further tests
+        sql 'set sql_select_limit = -1'
+
     }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to