diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctions.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctions.java index 996a591d1233f..f0cdc69cca4d6 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctions.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctions.java @@ -1248,6 +1248,16 @@ public static ConstantOperator substring(ConstantOperator value, ConstantOperato return ConstantOperator.createVarchar(string.substring(beginIndex, endIndex)); } + @ConstantFunction(name = "lower", argTypes = {VARCHAR}, returnType = VARCHAR) + public static ConstantOperator lower(ConstantOperator str) { + return ConstantOperator.createVarchar(StringUtils.lowerCase(str.getVarchar())); + } + + @ConstantFunction(name = "upper", argTypes = {VARCHAR}, returnType = VARCHAR) + public static ConstantOperator upper(ConstantOperator str) { + return ConstantOperator.createVarchar(StringUtils.upperCase(str.getVarchar())); + } + @ConstantFunction(name = "replace", argTypes = {VARCHAR, VARCHAR, VARCHAR}, returnType = VARCHAR) public static ConstantOperator replace(ConstantOperator value, ConstantOperator target, ConstantOperator replacement) { diff --git a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoQueryTest.java b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoQueryTest.java index bb097c8bccfb3..78b42e27b9dfc 100644 --- a/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoQueryTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/connector/parser/trino/TrinoQueryTest.java @@ -1031,7 +1031,7 @@ public void testTrim() throws Exception { assertPlanContains(sql, " : trim(' abcd')"); sql = "select trim(trailing 'ER' from upper('worker'));"; - assertPlanContains(sql, " : rtrim(upper('worker'), 'ER')"); + assertPlanContains(sql, " : rtrim('WORKER', 'ER')"); sql = "select trim(trailing from ' abcd');"; assertPlanContains(sql, " : rtrim(' abcd')"); diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctionsTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctionsTest.java index d6736f120946a..d707769e79409 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctionsTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctionsTest.java @@ -1462,6 +1462,16 @@ public void testReplace() { ).getVarchar()); } + @Test + public void testLowerUpper() { + assertEquals("aaa", ScalarOperatorFunctions.lower( + new ConstantOperator("AAA", Type.VARCHAR) + ).getVarchar()); + assertEquals("AAA", ScalarOperatorFunctions.upper( + new ConstantOperator("aaa", Type.VARCHAR) + ).getVarchar()); + } + /* test cases are generated by the following SQL by capturing: 1. leap year diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/plan/ConstantExpressionTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/plan/ConstantExpressionTest.java index 16943b224f765..d158360b100f6 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/plan/ConstantExpressionTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/plan/ConstantExpressionTest.java @@ -491,7 +491,7 @@ public void testGetQueryDump() throws Exception { // Non-constant arguments. { - String sql = "SELECT get_query_dump(lower('select count(v1) from t0')) from t0"; + String sql = "SELECT get_query_dump(rtrim('select count(v1) from t0')) from t0"; Assert.assertThrows("Meta function get_query_dump does not support non-constant arguments", SemanticException.class, () -> getFragmentPlan(sql)); } diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/plan/ExpressionTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/plan/ExpressionTest.java index 5b12897ea851c..df3ef469759f3 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/plan/ExpressionTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/plan/ExpressionTest.java @@ -1583,7 +1583,7 @@ public void testConstantFoldInLikeFunction() throws Exception { String sql2 = "select ilike('AA', concat('a', 'A'))"; String plan2 = getFragmentPlan(sql2); - assertContains(plan2, " : like(lower('AA'), lower('aA'))"); + assertContains(plan2, " : like('aa', 'aa')"); } @Test diff --git a/test/sql/test_function/R/test_get_query_dump b/test/sql/test_function/R/test_get_query_dump index 14d36695516a4..9fcaf9dfa59e7 100644 --- a/test/sql/test_function/R/test_get_query_dump +++ b/test/sql/test_function/R/test_get_query_dump @@ -57,7 +57,7 @@ select get_query_dump('invalid-query'); -- result: E: (6013, "SemanticException: Getting analyzing error. Detail message: Invalid parameter get_query_dump: execute query failed. Getting syntax error at line 1, column 0. Detail message: Unexpected input 'invalid', the most similar input is {'INSTALL', 'UNINSTALL', 'KILL', 'LOAD', 'ADMIN', '(', ';'}..") -- !result -select get_query_dump(lower('select * from t1')); +select get_query_dump(rtrim('select * from t1')); -- result: E: (1064, 'Getting analyzing error. Detail message: Meta function get_query_dump does not support non-constant arguments.') -- !result @@ -103,4 +103,4 @@ select get_json_string(x, '$.statement') from query_dump; -- result: SELECT * FROM db_mock_000.tbl_mock_001 --- !result \ No newline at end of file +-- !result diff --git a/test/sql/test_function/T/test_get_query_dump b/test/sql/test_function/T/test_get_query_dump index 21978e6f7c18a..ab246bd317958 100644 --- a/test/sql/test_function/T/test_get_query_dump +++ b/test/sql/test_function/T/test_get_query_dump @@ -45,7 +45,7 @@ from __row_util; -- Invalid cases. select get_query_dump(''); select get_query_dump('invalid-query'); -select get_query_dump(lower('select * from t1')); +select get_query_dump(trim('select * from t1')); -- Valid cases. with