diff --git a/be/src/vec/functions/like.cpp b/be/src/vec/functions/like.cpp index 0f5b7c6699..c70cbec18b 100644 --- a/be/src/vec/functions/like.cpp +++ b/be/src/vec/functions/like.cpp @@ -838,6 +838,7 @@ void register_function_like(SimpleFunctionFactory& factory) { void register_function_regexp(SimpleFunctionFactory& factory) { factory.register_function(); + factory.register_alias(FunctionRegexp::name, FunctionRegexp::alias); } } // namespace doris::vectorized diff --git a/be/src/vec/functions/like.h b/be/src/vec/functions/like.h index b248a4750c..7480d52989 100644 --- a/be/src/vec/functions/like.h +++ b/be/src/vec/functions/like.h @@ -264,6 +264,7 @@ private: class FunctionRegexp : public FunctionLikeBase { public: static constexpr auto name = "regexp"; + static constexpr auto alias = "rlike"; static FunctionPtr create() { return std::make_shared(); } diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup index 3ba5197f65..b84128a3d2 100644 --- a/fe/fe-core/src/main/cup/sql_parser.cup +++ b/fe/fe-core/src/main/cup/sql_parser.cup @@ -6197,6 +6197,10 @@ function_call_expr ::= RESULT = new FunctionCallExpr(fn_name, params); } :} + | KW_LIKE LPAREN function_params:params RPAREN + {: RESULT = new FunctionCallExpr("like", params); :} + | KW_REGEXP LPAREN function_params:params RPAREN + {: RESULT = new FunctionCallExpr("regexp", params); :} | function_name:fn_name LPAREN ident:id ARROW expr:e COMMA function_params:params RPAREN {: List exprs = params.exprs(); diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index 2cbd15db15..fdf8a2b9e5 100644 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -1823,6 +1823,9 @@ visible_functions = [ # search functions [['multi_search_all_positions'], 'ARRAY_INT', ['STRING', 'ARRAY_STRING'], 'ALWAYS_NOT_NULLABLE'], [['multi_match_any'], 'TINYINT', ['STRING', 'ARRAY_STRING'], 'ALWAYS_NOT_NULLABLE'], + [['like'], 'BOOLEAN', ['VARCHAR', 'VARCHAR'], ''], + [['rlike'], 'BOOLEAN', ['VARCHAR', 'VARCHAR'], ''], + [['regexp'], 'BOOLEAN', ['VARCHAR', 'VARCHAR'], ''], [['uuid'], 'VARCHAR', [], 'ALWAYS_NOT_NULLABLE'], diff --git a/regression-test/data/correctness_p0/test_select_with_predicate_like.out b/regression-test/data/correctness_p0/test_select_with_predicate_like.out index 887fc1ab47..d6db89b7b4 100644 --- a/regression-test/data/correctness_p0/test_select_with_predicate_like.out +++ b/regression-test/data/correctness_p0/test_select_with_predicate_like.out @@ -19,3 +19,23 @@ -- !select_default4 -- +-- !select2_default -- +1 + +-- !select2_default2 -- +1 + +-- !select2_default3 -- + +-- !select2_default4 -- + +-- !select2_default -- +1 + +-- !select2_default2 -- +1 + +-- !select2_default3 -- + +-- !select2_default4 -- + diff --git a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out index 07c1aa7844..51fbfc68af 100644 --- a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out +++ b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_like.out @@ -121,3 +121,127 @@ bab bb -- !sql -- + +-- !sql -- + + +-- !sql -- + + +-- !sql -- +a + +-- !sql -- +a +ba + +-- !sql -- +a +ab +accb + +-- !sql -- +a +ab +accb +ba +bab + +-- !sql -- +ba + +-- !sql -- +ab + +-- !sql -- +bab + +-- !sql -- +accb + +-- !sql -- + + +ab +accb +b +ba +bab +bb + +-- !sql -- + + +ab +accb +b +bab +bb + +-- !sql -- + + +b +ba +bab +bb + +-- !sql -- + + +b +bb + +-- !sql -- + + +a +ab +accb +b +bab +bb + +-- !sql -- + + +a +accb +b +ba +bab +bb + +-- !sql -- + + +a +ab +accb +b +ba +bb + +-- !sql -- + + +a +ab +b +ba +bab +bb + +-- !sql -- + + +a +ab +accb +b +ba +bab +bb + +-- !sql -- + diff --git a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out index 5480d6e270..3c7d8473ae 100644 --- a/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out +++ b/regression-test/data/query_p0/sql_functions/string_functions/test_string_function_regexp.out @@ -21,6 +21,28 @@ Emmy eillish It's true billie eillish +-- !sql -- +billie eillish + +-- !sql -- +It's ok + +-- !sql -- +Emmy eillish +It's ok +It's true +billie eillish + +-- !sql -- +Emmy eillish +It's ok +It's true + +-- !sql -- +Emmy eillish +It's true +billie eillish + -- !sql -- b @@ -118,6 +140,54 @@ false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk -- !sql -- 2 +-- !sql -- +false 1 1989 1001 11011902 123.123 true 1989-03-21 1989-03-21T13:00 wangjuoo4 0.1 6.333 string12345 170141183460469231731687303715884105727 + +-- !sql -- + +-- !sql -- +false 1 1989 1001 11011902 123.123 true 1989-03-21 1989-03-21T13:00 wangjuoo4 0.1 6.333 string12345 170141183460469231731687303715884105727 +false 2 1986 1001 11011903 1243.500 false 1901-12-31 1989-03-21T13:00 wangynnsf 20.268 789.25 string12345 -170141183460469231731687303715884105727 + +-- !sql -- + +-- !sql -- +false 1 1989 1001 11011902 123.123 true 1989-03-21 1989-03-21T13:00 wangjuoo4 0.1 6.333 string12345 170141183460469231731687303715884105727 + +-- !sql -- + +-- !sql -- +1 + +-- !sql -- +false 2 1986 1001 11011903 1243.500 false 1901-12-31 1989-03-21T13:00 wangynnsf 20.268 789.25 string12345 -170141183460469231731687303715884105727 +false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk 78945.0 3654.0 string12345 0 + +-- !sql -- +false 1 1989 1001 11011902 123.123 true 1989-03-21 1989-03-21T13:00 wangjuoo4 0.1 6.333 string12345 170141183460469231731687303715884105727 +false 2 1986 1001 11011903 1243.500 false 1901-12-31 1989-03-21T13:00 wangynnsf 20.268 789.25 string12345 -170141183460469231731687303715884105727 +false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk 78945.0 3654.0 string12345 0 + +-- !sql -- +false 2 1986 1001 11011903 1243.500 false 1901-12-31 1989-03-21T13:00 wangynnsf 20.268 789.25 string12345 -170141183460469231731687303715884105727 +false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk 78945.0 3654.0 string12345 0 + +-- !sql -- +false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk 78945.0 3654.0 string12345 0 + +-- !sql -- +false 1 1989 1001 11011902 123.123 true 1989-03-21 1989-03-21T13:00 wangjuoo4 0.1 6.333 string12345 170141183460469231731687303715884105727 +false 2 1986 1001 11011903 1243.500 false 1901-12-31 1989-03-21T13:00 wangynnsf 20.268 789.25 string12345 -170141183460469231731687303715884105727 +false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk 78945.0 3654.0 string12345 0 + +-- !sql -- +false 1 1989 1001 11011902 123.123 true 1989-03-21 1989-03-21T13:00 wangjuoo4 0.1 6.333 string12345 170141183460469231731687303715884105727 +false 2 1986 1001 11011903 1243.500 false 1901-12-31 1989-03-21T13:00 wangynnsf 20.268 789.25 string12345 -170141183460469231731687303715884105727 +false 3 1989 1002 11011905 24453.325 false 2012-03-14 2000-01-01T00:00 yunlj8@nk 78945.0 3654.0 string12345 0 + +-- !sql -- +1 + -- !sql_field1 -- Suzi Suzi diff --git a/regression-test/suites/correctness_p0/test_select_with_predicate_like.groovy b/regression-test/suites/correctness_p0/test_select_with_predicate_like.groovy index 9491c4271c..5f8d05299b 100644 --- a/regression-test/suites/correctness_p0/test_select_with_predicate_like.groovy +++ b/regression-test/suites/correctness_p0/test_select_with_predicate_like.groovy @@ -32,4 +32,13 @@ suite("test_select_with_predicate_like") { qt_select_default2 "select 1 from test_basic_agg where '199.8' like '1%';" qt_select_default3 "select 1 from test_basic_agg where 299.8 like '1%';" qt_select_default4 "select 1 from test_basic_agg where '299.8' like '1%';" + + qt_select2_default "select 1 from test_basic_agg where like( 1998 , '1%');" + qt_select2_default2 "select 1 from test_basic_agg where like( '1998', '1%');" + qt_select2_default3 "select 1 from test_basic_agg where like( 2998 , '1%');" + qt_select2_default4 "select 1 from test_basic_agg where like( '2998', '1%');" + qt_select2_default "select 1 from test_basic_agg where like( 199.8 , '1%');" + qt_select2_default2 "select 1 from test_basic_agg where like('199.8', '1%');" + qt_select2_default3 "select 1 from test_basic_agg where like( 299.8 , '1%');" + qt_select2_default4 "select 1 from test_basic_agg where like('299.8', '1%');" } \ No newline at end of file diff --git a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy index 48941ed485..9c5deed865 100644 --- a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy +++ b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_like.groovy @@ -38,6 +38,8 @@ suite("test_string_function_like") { ("ab"), ("accb"); """ + + // LIKE as predicate qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"\" ORDER BY k;" qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \" \" ORDER BY k;" qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"a\" ORDER BY k;" @@ -63,5 +65,29 @@ suite("test_string_function_like") { qt_sql "SELECT k FROM ${tbName} WHERE k LIKE \"%\" ORDER BY k;" qt_sql "SELECT k FROM ${tbName} WHERE k NOT LIKE \"%\" ORDER BY k;" + + // LIKE as function + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \" \") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"a\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"%a\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"a%\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"%a%\") ORDER BY k;" + + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"_a\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"a_\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"_a_\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"a__b\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"a\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"%a\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"a%\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"%a%\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"_a\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"a_\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"_a_\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"a__b\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE LIKE(k, \"%\") ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE NOT LIKE(k, \"%\") ORDER BY k;" + // sql "DROP TABLE ${tbName};" } diff --git a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy index fba213ef98..ba4f941a4b 100644 --- a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy +++ b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function_regexp.groovy @@ -33,6 +33,7 @@ suite("test_string_function_regexp") { ("Emmy eillish"), ("It's true") """ + // regexp as keyword qt_sql "SELECT k FROM ${tbName} WHERE k regexp '^billie' ORDER BY k;" qt_sql "SELECT k FROM ${tbName} WHERE k regexp 'ok\$' ORDER BY k;" qt_sql "SELECT k FROM ${tbName} WHERE k regexp concat('^', k) order by k;" @@ -40,6 +41,13 @@ suite("test_string_function_regexp") { qt_sql "SELECT k FROM ${tbName} WHERE k not regexp '^billie' ORDER BY k;" qt_sql "SELECT k FROM ${tbName} WHERE k not regexp 'ok\$' ORDER BY k;" + // regexp as function + qt_sql "SELECT k FROM ${tbName} WHERE regexp(k, '^billie') ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE regexp(k, 'ok\$') ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE regexp(k, concat('^', k)) order by k;" + qt_sql "SELECT k FROM ${tbName} WHERE not regexp(k, '^billie') ORDER BY k;" + qt_sql "SELECT k FROM ${tbName} WHERE not regexp(k, 'ok\$') ORDER BY k;" + qt_sql "SELECT regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 1);" qt_sql "SELECT regexp_extract('AbCdE', '([[:lower:]]+)C([[:lower:]]+)', 2);" @@ -79,23 +87,42 @@ suite("test_string_function_regexp") { def tableName= "test" sql "use test_query_db" - //regexp - qt_sql "select * from ${tableName} where lower(k7) regexp'.*o4\$' order by k1, k2, k3, k4" - qt_sql "select * from ${tableName} where lower(k7) regexp'[yun]+nk' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) regexp'^[a-z]+[0-9]?\$' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) regexp'^[a-z]+[0-9]+[a-z]+\$' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) regexp'wang(juoo|yu)[0-9]+\$' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) regexp'^[a-o]+[0-9]+[a-z]?\$' order by k1, k2, k3, k4" - qt_sql"select count(*) from ${tableName} where k1<10 and lower(k6) regexp '^t'" - //not regexp - qt_sql"select * from ${tableName} where lower(k7) not regexp'.*o4\$' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) not regexp'[yun]+nk' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) not regexp'wang(juoo|yu)[0-9]+\$' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) not regexp'^[a-z]+[0-9]?\$' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) not regexp'^[a-z]+[0-9]+[a-z]+\$' order by k1, k2, k3, k4" - qt_sql"select * from ${tableName} where lower(k7) not regexp'^[a-o]+[0-9]+[a-z]?\$' order by k1, k2, k3, k4" - qt_sql"select count(*) from ${tableName} where k1<10 and lower(k6) not regexp '^t'" + //regexp as keyword + qt_sql "select * from ${tableName} where lower(k7) regexp '.*o4\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) regexp '[yun]+nk' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) regexp '^[a-z]+[0-9]?\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) regexp '^[a-z]+[0-9]+[a-z]+\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) regexp 'wang(juoo|yu)[0-9]+\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) regexp '^[a-o]+[0-9]+[a-z]?\$' order by k1, k2, k3, k4" + qt_sql "select count(*) from ${tableName} where k1<10 and lower(k6) regexp '^t'" + + //not regexp as keyword + qt_sql "select * from ${tableName} where lower(k7) not regexp '.*o4\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) not regexp '[yun]+nk' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) not regexp 'wang(juoo|yu)[0-9]+\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) not regexp '^[a-z]+[0-9]?\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) not regexp '^[a-z]+[0-9]+[a-z]+\$' order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where lower(k7) not regexp '^[a-o]+[0-9]+[a-z]?\$' order by k1, k2, k3, k4" + qt_sql "select count(*) from ${tableName} where k1<10 and lower(k6) not regexp '^t'" + + //regexp as function + qt_sql "select * from ${tableName} where regexp(lower(k7), '.*o4\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where regexp(lower(k7), '[yun]+nk') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where regexp(lower(k7), '^[a-z]+[0-9]?\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where regexp(lower(k7), '^[a-z]+[0-9]+[a-z]+\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where regexp(lower(k7), 'wang(juoo|yu)[0-9]+\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where regexp(lower(k7), '^[a-o]+[0-9]+[a-z]?\$') order by k1, k2, k3, k4" + qt_sql "select count(*) from ${tableName} where k1<10 and regexp(lower(k6), '^t')" + + //not regexp as function + qt_sql "select * from ${tableName} where not regexp(lower(k7), '.*o4\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where not regexp(lower(k7), '[yun]+nk') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where not regexp(lower(k7), 'wang(juoo|yu)[0-9]+\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where not regexp(lower(k7), '^[a-z]+[0-9]?\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where not regexp(lower(k7), '^[a-z]+[0-9]+[a-z]+\$') order by k1, k2, k3, k4" + qt_sql "select * from ${tableName} where not regexp(lower(k7), '^[a-o]+[0-9]+[a-z]?\$') order by k1, k2, k3, k4" + qt_sql "select count(*) from ${tableName} where k1<10 and regexp(lower(k6), '^t')" def tbName2 = "test_string_function_field" sql "DROP TABLE IF EXISTS ${tbName2}"