Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -96,6 +98,27 @@ public String decode(Long value) throws DdlException {
}
}

// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

}
}