Apache DataFusion SQL Query Engine
Refactor regexp slt tests (#15709)
Lokeshab5edc975d9c
diff --git a/datafusion/sqllogictest/test_files/regexp.slt b/datafusion/sqllogictest/test_files/regexp.sltdeleted file mode 100644index 44ba61e877..0000000000--- a/datafusion/sqllogictest/test_files/regexp.slt+++ /dev/null@@ -1,898 +0,0 @@-# Licensed to the Apache Software Foundation (ASF) under one-# or more contributor license agreements. See the NOTICE file-# distributed with this work for additional information-# regarding copyright ownership. The ASF licenses this file-# to you under the Apache License, Version 2.0 (the-# "License"); you may not use this file except in compliance-# with the License. You may obtain a copy of the License at--# http://www.apache.org/licenses/LICENSE-2.0--# Unless required by applicable law or agreed to in writing,-# software distributed under the License is distributed on an-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY-# KIND, either express or implied. See the License for the-# specific language governing permissions and limitations-# under the License.--statement ok-CREATE TABLE t (str varchar, pattern varchar, start int, flags varchar) AS VALUES- ('abc', '^(a)', 1, 'i'),- ('ABC', '^(A).*', 1, 'i'),- ('aBc', '(b|d)', 1, 'i'),- ('AbC', '(B|D)', 2, null),- ('aBC', '^(b|c)', 3, null),- ('4000', '\b4([1-9]\d\d|\d[1-9]\d|\d\d[1-9])\b', 1, null),- ('4010', '\b4([1-9]\d\d|\d[1-9]\d|\d\d[1-9])\b', 2, null),- ('Düsseldorf','[\p{Letter}-]+', 3, null),- ('Москва', '[\p{L}-]+', 4, null),- ('Köln', '[a-zA-Z]ö[a-zA-Z]{2}', 1, null),- ('إسرائيل', '^\p{Arabic}+$', 2, null);--#-# regexp_like tests-#--query B-SELECT regexp_like(str, pattern, flags) FROM t;------true-true-true-false-false-false-true-true-true-true-true--query B-SELECT str ~ NULL FROM t;------NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL--query B-select str ~ right('foo', NULL) FROM t;------NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL--query B-select right('foo', NULL) !~ str FROM t;------NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL-NULL--query B-SELECT regexp_like('foobarbequebaz', '');------true--query B-SELECT regexp_like('', '');------true--query B-SELECT regexp_like('foobarbequebaz', '(bar)(beque)');------true--query B-SELECT regexp_like('fooBarb-eQuebaz', '(bar).*(que)', 'is');------true--query B-SELECT regexp_like('foobarbequebaz', '(ba3r)(bequ34e)');------false--query B-SELECT regexp_like('foobarbequebaz', '^.*(barbequ[0-9]*e).*$', 'm');------true--query B-SELECT regexp_like('aaa-0', '.*-(\d)');------true--query B-SELECT regexp_like('bb-1', '.*-(\d)');------true--query B-SELECT regexp_like('aa', '.*-(\d)');------false--query B-SELECT regexp_like(NULL, '.*-(\d)');------NULL--query B-SELECT regexp_like('aaa-0', NULL);------NULL--query B-SELECT regexp_like(null, '.*-(\d)');------NULL--query error Error during planning: regexp_like\(\) does not support the "global" option-SELECT regexp_like('bb-1', '.*-(\d)', 'g');--query error Error during planning: regexp_like\(\) does not support the "global" option-SELECT regexp_like('bb-1', '.*-(\d)', 'g');--query error Arrow error: Compute error: Regular expression did not compile: CompiledTooBig\(10485760\)-SELECT regexp_like('aaaaa', 'a{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}');--# look-around is not supported and will just return false-query B-SELECT regexp_like('(?<=[A-Z]\w )Smith', 'John Smith', 'i');------false--query B-select regexp_like('aaa-555', '.*-(\d*)');------true--#-# regexp_match tests-#--query ?-SELECT regexp_match(str, pattern, flags) FROM t;------[a]-[A]-[B]-NULL-NULL-NULL-[010]-[Düsseldorf]-[Москва]-[Köln]-[إسرائيل]--# test string view-statement ok-CREATE TABLE t_stringview AS-SELECT arrow_cast(str, 'Utf8View') as str, arrow_cast(pattern, 'Utf8View') as pattern, arrow_cast(flags, 'Utf8View') as flags FROM t;--query ?-SELECT regexp_match(str, pattern, flags) FROM t_stringview;------[a]-[A]-[B]-NULL-NULL-NULL-[010]-[Düsseldorf]-[Москва]-[Köln]-[إسرائيل]--statement ok-DROP TABLE t_stringview;--query ?-SELECT regexp_match('foobarbequebaz', '');------[]--query ?-SELECT regexp_match('', '');------[]--query ?-SELECT regexp_match('foobarbequebaz', '(bar)(beque)');------[bar, beque]--query ?-SELECT regexp_match('fooBarb-eQuebaz', '(bar).*(que)', 'is');------[Bar, Que]--query ?-SELECT regexp_match('foobarbequebaz', '(ba3r)(bequ34e)');------NULL--query ?-SELECT regexp_match('foobarbequebaz', '^.*(barbequ[0-9]*e).*$', 'm');------[barbeque]--query ?-SELECT regexp_match('aaa-0', '.*-(\d)');------[0]--query ?-SELECT regexp_match('bb-1', '.*-(\d)');------[1]--query ?-SELECT regexp_match('aa', '.*-(\d)');------NULL--query ?-SELECT regexp_match(NULL, '.*-(\d)');------NULL--query ?-SELECT regexp_match('aaa-0', NULL);------NULL--query ?-SELECT regexp_match(null, '.*-(\d)');------NULL--query error Error during planning: regexp_match\(\) does not support the "global" option-SELECT regexp_match('bb-1', '.*-(\d)', 'g');--query error Error during planning: regexp_match\(\) does not support the "global" option-SELECT regexp_match('bb-1', '.*-(\d)', 'g');--query error Arrow error: Compute error: Regular expression did not compile: CompiledTooBig\(10485760\)-SELECT regexp_match('aaaaa', 'a{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}');--# look-around is not supported and will just return null-query ?-SELECT regexp_match('(?<=[A-Z]\w )Smith', 'John Smith', 'i');------NULL--# ported test-query ?-SELECT regexp_match('aaa-555', '.*-(\d*)');------[555]--query B-select 'abc' ~ null;------NULL--query B-select null ~ null;------NULL--query B-select null ~ 'abc';------NULL--query B-select 'abc' ~* null;------NULL--query B-select null ~* null;------NULL--query B-select null ~* 'abc';------NULL--query B-select 'abc' !~ null;------NULL--query B-select null !~ null;------NULL--query B-select null !~ 'abc';------NULL--query B-select 'abc' !~* null;------NULL--query B-select null !~* null;------NULL--query B-select null !~* 'abc';------NULL--#-# regexp_replace tests-#--query T-SELECT regexp_replace(str, pattern, 'X', concat('g', flags)) FROM t;------Xbc-X-aXc-AbC-aBC-4000-X-X-X-X-X--# test string view-statement ok-CREATE TABLE t_stringview AS-SELECT arrow_cast(str, 'Utf8View') as str, arrow_cast(pattern, 'Utf8View') as pattern, arrow_cast(flags, 'Utf8View') as flags FROM t;--query T-SELECT regexp_replace(str, pattern, 'X', concat('g', flags)) FROM t_stringview;------Xbc-X-aXc-AbC-aBC-4000-X-X-X-X-X--statement ok-DROP TABLE t_stringview;--query T-SELECT regexp_replace('ABCabcABC', '(abc)', 'X', 'gi');------XXX--query T-SELECT regexp_replace('ABCabcABC', '(abc)', 'X', 'i');------XabcABC--query T-SELECT regexp_replace('foobarbaz', 'b..', 'X', 'g');------fooXX--query T-SELECT regexp_replace('foobarbaz', 'b..', 'X');------fooXbaz--query T-SELECT regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', 'g');------fooXarYXazY--query T-SELECT regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', NULL);------NULL--query T-SELECT regexp_replace('foobarbaz', 'b(..)', NULL, 'g');------NULL--query T-SELECT regexp_replace('foobarbaz', NULL, 'X\\1Y', 'g');------NULL--query T-SELECT regexp_replace('Thomas', '.[mN]a.', 'M');------ThM--query T-SELECT regexp_replace(NULL, 'b(..)', 'X\\1Y', 'g');------NULL--query T-SELECT regexp_replace('foobar', 'bar', 'xx', 'gi')------fooxx--query T-SELECT regexp_replace(arrow_cast('foobar', 'Dictionary(Int32, Utf8)'), 'bar', 'xx', 'gi')------fooxx--query TTT-select- regexp_replace(col, NULL, 'c'),- regexp_replace(col, 'a', NULL),- regexp_replace(col, 'a', 'c', NULL)-from (values ('a'), ('b')) as tbl(col);------NULL NULL NULL-NULL NULL NULL--# multiline string-query B-SELECT 'foo\nbar\nbaz' ~ 'bar';------true--statement error-Error during planning: Cannot infer common argument type for regex operation List(Field { name: "item", data_type: Int64, nullable: true, dict_is_ordered: false, metadata-: {} }) ~ List(Field { name: "item", data_type: Int64, nullable: true, dict_is_ordered: false, metadata: {} })-select [1,2] ~ [3];--query B-SELECT 'foo\nbar\nbaz' LIKE '%bar%';------true--query B-SELECT NULL LIKE NULL;------NULL--query B-SELECT NULL iLIKE NULL;------NULL--query B-SELECT NULL not LIKE NULL;------NULL--query B-SELECT NULL not iLIKE NULL;------NULL--# regexp_count tests--# regexp_count tests from postgresql-# https://github.com/postgres/postgres/blob/56d23855c864b7384970724f3ad93fb0fc319e51/src/test/regress/sql/strings.sql#L226-L235--query I-SELECT regexp_count('123123123123123', '(12)3');------5--query I-SELECT regexp_count('123123123123', '123', 1);------4--query I-SELECT regexp_count('123123123123', '123', 3);------3--query I-SELECT regexp_count('123123123123', '123', 33);------0--query I-SELECT regexp_count('ABCABCABCABC', 'Abc', 1, '');------0--query I-SELECT regexp_count('ABCABCABCABC', 'Abc', 1, 'i');------4--statement error-External error: query failed: DataFusion error: Arrow error: Compute error: regexp_count() requires start to be 1 based-SELECT regexp_count('123123123123', '123', 0);--statement error-External error: query failed: DataFusion error: Arrow error: Compute error: regexp_count() requires start to be 1 based-SELECT regexp_count('123123123123', '123', -3);--statement error-External error: statement failed: DataFusion error: Arrow error: Compute error: regexp_count() does not support global flag-SELECT regexp_count('123123123123', '123', 1, 'g');--query I-SELECT regexp_count(str, '\w') from t;------3-3-3-3-3-4-4-10-6-4-7--query I-SELECT regexp_count(str, '\w{2}', start) from t;------1-1-1-1-0-2-1-4-1-2-3--query I-SELECT regexp_count(str, 'ab', 1, 'i') from t;------1-1-1-1-1-0-0-0-0-0-0---query I-SELECT regexp_count(str, pattern) from t;------1-1-0-0-0-0-1-1-1-1-1--query I-SELECT regexp_count(str, pattern, start) from t;------1-1-0-0-0-0-0-1-1-1-1--query I-SELECT regexp_count(str, pattern, start, flags) from t;------1-1-1-0-0-0-0-1-1-1-1--# test type coercion-query I-SELECT regexp_count(arrow_cast(str, 'Utf8'), arrow_cast(pattern, 'LargeUtf8'), arrow_cast(start, 'Int32'), flags) from t;------1-1-1-0-0-0-0-1-1-1-1--# test string views--statement ok-CREATE TABLE t_stringview AS-SELECT arrow_cast(str, 'Utf8View') as str, arrow_cast(pattern, 'Utf8View') as pattern, arrow_cast(start, 'Int64') as start, arrow_cast(flags, 'Utf8View') as flags FROM t;--query I-SELECT regexp_count(str, '\w') from t_stringview;------3-3-3-3-3-4-4-10-6-4-7--query I-SELECT regexp_count(str, '\w{2}', start) from t_stringview;------1-1-1-1-0-2-1-4-1-2-3--query I-SELECT regexp_count(str, 'ab', 1, 'i') from t_stringview;------1-1-1-1-1-0-0-0-0-0-0---query I-SELECT regexp_count(str, pattern) from t_stringview;------1-1-0-0-0-0-1-1-1-1-1--query I-SELECT regexp_count(str, pattern, start) from t_stringview;------1-1-0-0-0-0-0-1-1-1-1--query I-SELECT regexp_count(str, pattern, start, flags) from t_stringview;------1-1-1-0-0-0-0-1-1-1-1--# test type coercion-query I-SELECT regexp_count(arrow_cast(str, 'Utf8'), arrow_cast(pattern, 'LargeUtf8'), arrow_cast(start, 'Int32'), flags) from t_stringview;------1-1-1-0-0-0-0-1-1-1-1--# NULL tests--query I-SELECT regexp_count(NULL, NULL);------0--query I-SELECT regexp_count(NULL, 'a');------0--query I-SELECT regexp_count('a', NULL);------0--query I-SELECT regexp_count(NULL, NULL, NULL, NULL);------0--statement ok-CREATE TABLE empty_table (str varchar, pattern varchar, start int, flags varchar);--query I-SELECT regexp_count(str, pattern, start, flags) from empty_table;-------statement ok-INSERT INTO empty_table VALUES ('a', NULL, 1, 'i'), (NULL, 'a', 1, 'i'), (NULL, NULL, 1, 'i'), (NULL, NULL, NULL, 'i');--query I-SELECT regexp_count(str, pattern, start, flags) from empty_table;------0-0-0-0--statement ok-drop table t;--statement ok-create or replace table strings as values- ('FooBar'),- ('Foo'),- ('Foo'),- ('Bar'),- ('FooBar'),- ('Bar'),- ('Baz');--statement ok-create or replace table dict_table as-select arrow_cast(column1, 'Dictionary(Int32, Utf8)') as column1-from strings;--query T-select column1 from dict_table where column1 LIKE '%oo%';------FooBar-Foo-Foo-FooBar--query T-select column1 from dict_table where column1 NOT LIKE '%oo%';------Bar-Bar-Baz--query T-select column1 from dict_table where column1 ILIKE '%oO%';------FooBar-Foo-Foo-FooBar--query T-select column1 from dict_table where column1 NOT ILIKE '%oO%';------Bar-Bar-Baz---# plan should not cast the column, instead it should use the dictionary directly-query TT-explain select column1 from dict_table where column1 LIKE '%oo%';------logical_plan-01)Filter: dict_table.column1 LIKE Utf8("%oo%")-02)--TableScan: dict_table projection=[column1]-physical_plan-01)CoalesceBatchesExec: target_batch_size=8192-02)--FilterExec: column1@0 LIKE %oo%-03)----DataSourceExec: partitions=1, partition_sizes=[1]--# Ensure casting / coercion works for all operators-# (there should be no casts to Utf8)-query TT-explain select- column1 LIKE '%oo%',- column1 NOT LIKE '%oo%',- column1 ILIKE '%oo%',- column1 NOT ILIKE '%oo%'-from dict_table;------logical_plan-01)Projection: dict_table.column1 LIKE Utf8("%oo%"), dict_table.column1 NOT LIKE Utf8("%oo%"), dict_table.column1 ILIKE Utf8("%oo%"), dict_table.column1 NOT ILIKE Utf8("%oo%")-02)--TableScan: dict_table projection=[column1]-physical_plan-01)ProjectionExec: expr=[column1@0 LIKE %oo% as dict_table.column1 LIKE Utf8("%oo%"), column1@0 NOT LIKE %oo% as dict_table.column1 NOT LIKE Utf8("%oo%"), column1@0 ILIKE %oo% as dict_table.column1 ILIKE Utf8("%oo%"), column1@0 NOT ILIKE %oo% as dict_table.column1 NOT ILIKE Utf8("%oo%")]-02)--DataSourceExec: partitions=1, partition_sizes=[1]--statement ok-drop table strings--statement ok-drop table dict_tablediff --git a/datafusion/sqllogictest/test_files/regexp/README.md b/datafusion/sqllogictest/test_files/regexp/README.mdnew file mode 100644index 0000000000..7e5efc5b5d--- /dev/null+++ b/datafusion/sqllogictest/test_files/regexp/README.md@@ -0,0 +1,59 @@+<!---+ Licensed to the Apache Software Foundation (ASF) under one+ or more contributor license agreements. See the NOTICE file+ distributed with this work for additional information+ regarding copyright ownership. The ASF licenses this file+ to you under the Apache License, Version 2.0 (the+ "License"); you may not use this file except in compliance+ with the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing,+ software distributed under the License is distributed on an+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ KIND, either express or implied. See the License for the+ specific language governing permissions and limitations+ under the License.+-->++# Regexp Test Files++This directory contains test files for regular expression (regexp) functions in DataFusion.++## Directory Structure++```+regexp/+ - init_data.slt.part // Shared test data for regexp functions+ - regexp_like.slt // Tests for regexp_like function+ - regexp_count.slt // Tests for regexp_count function+ - regexp_match.slt // Tests for regexp_match function+ - regexp_replace.slt // Tests for regexp_replace function+```++## Tested Functions++1. `regexp_like`: Check if a string matches a regular expression+2. `regexp_count`: Count occurrences of a pattern in a string+3. `regexp_match`: Extract matching substrings+4. `regexp_replace`: Replace matched substrings++## Test Data++Test data is centralized in the `init_data.slt.part` file and imported into each test file using the `include` directive. This approach ensures:++Consistent test data across different regexp function tests+Easy maintenance of test data+Reduced duplication++## Test Coverage++Each test file covers:++Basic functionality+Case-insensitive matching+Null handling+Start position tests+Capture group handling+Different string types (UTF-8, Unicode)diff --git a/datafusion/sqllogictest/test_files/regexp/init_data.slt.part b/datafusion/sqllogictest/test_files/regexp/init_data.slt.partnew file mode 100644index 0000000000..ed6fb0e872--- /dev/null+++ b/datafusion/sqllogictest/test_files/regexp/init_data.slt.part@@ -0,0 +1,31 @@+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.++statement ok+create table regexp_test_data (str varchar, pattern varchar, start int, flags varchar) as values+ (NULL, '^(a)', 1, 'i'),+ ('abc', '^(a)', 1, 'i'),+ ('ABC', '^(A).*', 1, 'i'),+ ('aBc', '(b|d)', 1, 'i'),+ ('AbC', '(B|D)', 2, null),+ ('aBC', '^(b|c)', 3, null),+ ('4000', '\b4([1-9]\d\d|\d[1-9]\d|\d\d[1-9])\b', 1, null),+ ('4010', '\b4([1-9]\d\d|\d[1-9]\d|\d\d[1-9])\b', 2, null),+ ('Düsseldorf','[\p{Letter}-]+', 3, null),+ ('Москва', '[\p{L}-]+', 4, null),+ ('Köln', '[a-zA-Z]ö[a-zA-Z]{2}', 1, null),+ ('إسرائيل', '^\p{Arabic}+$', 2, null);diff --git a/datafusion/sqllogictest/test_files/regexp/regexp_count.slt b/datafusion/sqllogictest/test_files/regexp/regexp_count.sltnew file mode 100644index 0000000000..f64705429b--- /dev/null+++ b/datafusion/sqllogictest/test_files/regexp/regexp_count.slt@@ -0,0 +1,344 @@+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at++# http://www.apache.org/licenses/LICENSE-2.0++# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.++# Import common test data+include ./init_data.slt.part++# regexp_count tests from postgresql+# https://github.com/postgres/postgres/blob/56d23855c864b7384970724f3ad93fb0fc319e51/src/test/regress/sql/strings.sql#L226-L235++query I+SELECT regexp_count('123123123123123', '(12)3');+----+5++query I+SELECT regexp_count('123123123123', '123', 1);+----+4++query I+SELECT regexp_count('123123123123', '123', 3);+----+3++query I+SELECT regexp_count('123123123123', '123', 33);+----+0++query I+SELECT regexp_count('ABCABCABCABC', 'Abc', 1, '');+----+0++query I+SELECT regexp_count('ABCABCABCABC', 'Abc', 1, 'i');+----+4++statement error+External error: query failed: DataFusion error: Arrow error: Compute error: regexp_count() requires start to be 1 based+SELECT regexp_count('123123123123', '123', 0);++statement error+External error: query failed: DataFusion error: Arrow error: Compute error: regexp_count() requires start to be 1 based+SELECT regexp_count('123123123123', '123', -3);++statement error+External error: statement failed: DataFusion error: Arrow error: Compute error: regexp_count() does not support global flag+SELECT regexp_count('123123123123', '123', 1, 'g');++query I+SELECT regexp_count(str, '\w') from regexp_test_data;+----+0+3+3+3+3+3+4+4+10+6+4+7++query I+SELECT regexp_count(str, '\w{2}', start) from regexp_test_data;+----+0+1+1+1+1+0+2+1+4+1+2+3++query I+SELECT regexp_count(str, 'ab', 1, 'i') from regexp_test_data;+----+0+1+1+1+1+1+0+0+0+0+0+0+++query I+SELECT regexp_count(str, pattern) from regexp_test_data;+----+0+1+1+0+0+0+0+1+1+1+1+1++query I+SELECT regexp_count(str, pattern, start) from regexp_test_data;+----+0+1+1+0+0+0+0+0+1+1+1+1++query I+SELECT regexp_count(str, pattern, start, flags) from regexp_test_data;+----+0+1+1+1+0+0+0+0+1+1+1+1++# test type coercion+query I+SELECT regexp_count(arrow_cast(str, 'Utf8'), arrow_cast(pattern, 'LargeUtf8'), arrow_cast(start, 'Int32'), flags) from regexp_test_data;+----+0+1+1+1+0+0+0+0+1+1+1+1++# test string views++statement ok+CREATE TABLE t_stringview AS+SELECT arrow_cast(str, 'Utf8View') as str, arrow_cast(pattern, 'Utf8View') as pattern, arrow_cast(start, 'Int64') as start, arrow_cast(flags, 'Utf8View') as flags FROM regexp_test_data;++query I+SELECT regexp_count(str, '\w') from t_stringview;+----+0+3+3+3+3+3+4+4+10+6+4+7++query I+SELECT regexp_count(str, '\w{2}', start) from t_stringview;+----+0+1+1+1+1+0+2+1+4+1+2+3++query I+SELECT regexp_count(str, 'ab', 1, 'i') from t_stringview;+----+0+1+1+1+1+1+0+0+0+0+0+0+++query I+SELECT regexp_count(str, pattern) from t_stringview;+----+0+1+1+0+0+0+0+1+1+1+1+1++query I+SELECT regexp_count(str, pattern, start) from t_stringview;+----+0+1+1+0+0+0+0+0+1+1+1+1++query I+SELECT regexp_count(str, pattern, start, flags) from t_stringview;+----+0+1+1+1+0+0+0+0+1+1+1+1++# test type coercion+query I+SELECT regexp_count(arrow_cast(str, 'Utf8'), arrow_cast(pattern, 'LargeUtf8'), arrow_cast(start, 'Int32'), flags) from t_stringview;+----+0+1+1+1+0+0+0+0+1+1+1+1++# NULL tests++query I+SELECT regexp_count(NULL, NULL);+----+0++query I+SELECT regexp_count(NULL, 'a');+----+0++query I+SELECT regexp_count('a', NULL);+----+0++query I+SELECT regexp_count(NULL, NULL, NULL, NULL);+----+0++statement ok+CREATE TABLE empty_table (str varchar, pattern varchar, start int, flags varchar);++query I+SELECT regexp_count(str, pattern, start, flags) from empty_table;+----++statement ok+INSERT INTO empty_table VALUES ('a', NULL, 1, 'i'), (NULL, 'a', 1, 'i'), (NULL, NULL, 1, 'i'), (NULL, NULL, NULL, 'i');++query I+SELECT regexp_count(str, pattern, start, flags) from empty_table;+----+0+0+0+0++statement ok+drop table t_stringview;++statement ok+drop table empty_table;\ No newline at end of filediff --git a/datafusion/sqllogictest/test_files/regexp/regexp_like.slt b/datafusion/sqllogictest/test_files/regexp/regexp_like.sltnew file mode 100644index 0000000000..ec48d62499--- /dev/null+++ b/datafusion/sqllogictest/test_files/regexp/regexp_like.slt@@ -0,0 +1,280 @@+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at++# http://www.apache.org/licenses/LICENSE-2.0++# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.++# Import common test data+include ./init_data.slt.part++query B+SELECT regexp_like(str, pattern, flags) FROM regexp_test_data;+----+NULL+true+true+true+false+false+false+true+true+true+true+true++query B+SELECT str ~ NULL FROM regexp_test_data;+----+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL++query B+select str ~ right('foo', NULL) FROM regexp_test_data;+----+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL++query B+select right('foo', NULL) !~ str FROM regexp_test_data;+----+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL+NULL++query B+SELECT regexp_like('foobarbequebaz', '');+----+true++query B+SELECT regexp_like('', '');+----+true++query B+SELECT regexp_like('foobarbequebaz', '(bar)(beque)');+----+true++query B+SELECT regexp_like('fooBarbeQuebaz', '(bar).*(que)', 'is');+----+true++query B+SELECT regexp_like('foobarbequebaz', '(ba3r)(bequ34e)');+----+false++query B+SELECT regexp_like('foobarbequebaz', '^.*(barbequ[0-9]*e).*$', 'm');+----+true++query B+SELECT regexp_like('aaa-0', '.*-(\d)');+----+true++query B+SELECT regexp_like('bb-1', '.*-(\d)');+----+true++query B+SELECT regexp_like('aa', '.*-(\d)');+----+false++query B+SELECT regexp_like(NULL, '.*-(\d)');+----+NULL++query B+SELECT regexp_like('aaa-0', NULL);+----+NULL++query B+SELECT regexp_like(null, '.*-(\d)');+----+NULL++query error Error during planning: regexp_like\(\) does not support the "global" option+SELECT regexp_like('bb-1', '.*-(\d)', 'g');++query error Error during planning: regexp_like\(\) does not support the "global" option+SELECT regexp_like('bb-1', '.*-(\d)', 'g');++query error Arrow error: Compute error: Regular expression did not compile: CompiledTooBig\(10485760\)+SELECT regexp_like('aaaaa', 'a{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}');++# look-around is not supported and will just return false+query B+SELECT regexp_like('(?<=[A-Z]\w )Smith', 'John Smith', 'i');+----+false++query B+select regexp_like('aaa-555', '.*-(\d*)');+----+true++# multiline string+query B+SELECT 'foo\nbar\nbaz' ~ 'bar';+----+true++statement error+Error during planning: Cannot infer common argument type for regex operation List(Field { name: "item", data_type: Int64, nullable: true, dict_is_ordered: false, metadata+: {} }) ~ List(Field { name: "item", data_type: Int64, nullable: true, dict_is_ordered: false, metadata: {} })+select [1,2] ~ [3];++query B+SELECT 'foo\nbar\nbaz' LIKE '%bar%';+----+true++query B+SELECT NULL LIKE NULL;+----+NULL++query B+SELECT NULL iLIKE NULL;+----+NULL++query B+SELECT NULL not LIKE NULL;+----+NULL++query B+SELECT NULL not iLIKE NULL;+----+NULL++statement ok+create or replace table strings as values+ ('FooBar'),+ ('Foo'),+ ('Foo'),+ ('Bar'),+ ('FooBar'),+ ('Bar'),+ ('Baz');++statement ok+create or replace table dict_table as+select arrow_cast(column1, 'Dictionary(Int32, Utf8)') as column1+from strings;++query T+select column1 from dict_table where column1 LIKE '%oo%';+----+FooBar+Foo+Foo+FooBar++query T+select column1 from dict_table where column1 NOT LIKE '%oo%';+----+Bar+Bar+Baz++query T+select column1 from dict_table where column1 ILIKE '%oO%';+----+FooBar+Foo+Foo+FooBar++query T+select column1 from dict_table where column1 NOT ILIKE '%oO%';+----+Bar+Bar+Baz+++# plan should not cast the column, instead it should use the dictionary directly+query TT+explain select column1 from dict_table where column1 LIKE '%oo%';+----+logical_plan+01)Filter: dict_table.column1 LIKE Utf8("%oo%")+02)--TableScan: dict_table projection=[column1]+physical_plan+01)CoalesceBatchesExec: target_batch_size=8192+02)--FilterExec: column1@0 LIKE %oo%+03)----DataSourceExec: partitions=1, partition_sizes=[1]++# Ensure casting / coercion works for all operators+# (there should be no casts to Utf8)+query TT+explain select+ column1 LIKE '%oo%',+ column1 NOT LIKE '%oo%',+ column1 ILIKE '%oo%',+ column1 NOT ILIKE '%oo%'+from dict_table;+----+logical_plan+01)Projection: dict_table.column1 LIKE Utf8("%oo%"), dict_table.column1 NOT LIKE Utf8("%oo%"), dict_table.column1 ILIKE Utf8("%oo%"), dict_table.column1 NOT ILIKE Utf8("%oo%")+02)--TableScan: dict_table projection=[column1]+physical_plan+01)ProjectionExec: expr=[column1@0 LIKE %oo% as dict_table.column1 LIKE Utf8("%oo%"), column1@0 NOT LIKE %oo% as dict_table.column1 NOT LIKE Utf8("%oo%"), column1@0 ILIKE %oo% as dict_table.column1 ILIKE Utf8("%oo%"), column1@0 NOT ILIKE %oo% as dict_table.column1 NOT ILIKE Utf8("%oo%")]+02)--DataSourceExec: partitions=1, partition_sizes=[1]++statement ok+drop table strings++statement ok+drop table dict_table\ No newline at end of filediff --git a/datafusion/sqllogictest/test_files/regexp/regexp_match.slt b/datafusion/sqllogictest/test_files/regexp/regexp_match.sltnew file mode 100644index 0000000000..4b4cf4f134--- /dev/null+++ b/datafusion/sqllogictest/test_files/regexp/regexp_match.slt@@ -0,0 +1,201 @@+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at++# http://www.apache.org/licenses/LICENSE-2.0++# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.++# Import common test data+include ./init_data.slt.part++query ?+SELECT regexp_match(str, pattern, flags) FROM regexp_test_data;+----+NULL+[a]+[A]+[B]+NULL+NULL+NULL+[010]+[Düsseldorf]+[Москва]+[Köln]+[إسرائيل]++# test string view+statement ok+CREATE TABLE t_stringview AS+SELECT arrow_cast(str, 'Utf8View') as str, arrow_cast(pattern, 'Utf8View') as pattern, arrow_cast(flags, 'Utf8View') as flags FROM regexp_test_data;++query ?+SELECT regexp_match(str, pattern, flags) FROM t_stringview;+----+NULL+[a]+[A]+[B]+NULL+NULL+NULL+[010]+[Düsseldorf]+[Москва]+[Köln]+[إسرائيل]++statement ok+DROP TABLE t_stringview;++query ?+SELECT regexp_match('foobarbequebaz', '');+----+[]++query ?+SELECT regexp_match('', '');+----+[]++query ?+SELECT regexp_match('foobarbequebaz', '(bar)(beque)');+----+[bar, beque]++query ?+SELECT regexp_match('fooBarb+eQuebaz', '(bar).*(que)', 'is');+----+[Bar, Que]++query ?+SELECT regexp_match('foobarbequebaz', '(ba3r)(bequ34e)');+----+NULL++query ?+SELECT regexp_match('foobarbequebaz', '^.*(barbequ[0-9]*e).*$', 'm');+----+[barbeque]++query ?+SELECT regexp_match('aaa-0', '.*-(\d)');+----+[0]++query ?+SELECT regexp_match('bb-1', '.*-(\d)');+----+[1]++query ?+SELECT regexp_match('aa', '.*-(\d)');+----+NULL++query ?+SELECT regexp_match(NULL, '.*-(\d)');+----+NULL++query ?+SELECT regexp_match('aaa-0', NULL);+----+NULL++query ?+SELECT regexp_match(null, '.*-(\d)');+----+NULL++query error Error during planning: regexp_match\(\) does not support the "global" option+SELECT regexp_match('bb-1', '.*-(\d)', 'g');++query error Error during planning: regexp_match\(\) does not support the "global" option+SELECT regexp_match('bb-1', '.*-(\d)', 'g');++query error Arrow error: Compute error: Regular expression did not compile: CompiledTooBig\(10485760\)+SELECT regexp_match('aaaaa', 'a{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}{5}');++# look-around is not supported and will just return null+query ?+SELECT regexp_match('(?<=[A-Z]\w )Smith', 'John Smith', 'i');+----+NULL++# ported test+query ?+SELECT regexp_match('aaa-555', '.*-(\d*)');+----+[555]++query B+select 'abc' ~ null;+----+NULL++query B+select null ~ null;+----+NULL++query B+select null ~ 'abc';+----+NULL++query B+select 'abc' ~* null;+----+NULL++query B+select null ~* null;+----+NULL++query B+select null ~* 'abc';+----+NULL++query B+select 'abc' !~ null;+----+NULL++query B+select null !~ null;+----+NULL++query B+select null !~ 'abc';+----+NULL++query B+select 'abc' !~* null;+----+NULL++query B+select null !~* null;+----+NULL++query B+select null !~* 'abc';+----+NULL\ No newline at end of filediff --git a/datafusion/sqllogictest/test_files/regexp/regexp_replace.slt b/datafusion/sqllogictest/test_files/regexp/regexp_replace.sltnew file mode 100644index 0000000000..d54261f02b--- /dev/null+++ b/datafusion/sqllogictest/test_files/regexp/regexp_replace.slt@@ -0,0 +1,129 @@+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at++# http://www.apache.org/licenses/LICENSE-2.0++# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.++# Import common test data+include ./init_data.slt.part++query T+SELECT regexp_replace(str, pattern, 'X', concat('g', flags)) FROM regexp_test_data;+----+NULL+Xbc+X+aXc+AbC+aBC+4000+X+X+X+X+X++# test string view+statement ok+CREATE TABLE t_stringview AS+SELECT arrow_cast(str, 'Utf8View') as str, arrow_cast(pattern, 'Utf8View') as pattern, arrow_cast(flags, 'Utf8View') as flags FROM regexp_test_data;++query T+SELECT regexp_replace(str, pattern, 'X', concat('g', flags)) FROM t_stringview;+----+NULL+Xbc+X+aXc+AbC+aBC+4000+X+X+X+X+X++statement ok+DROP TABLE t_stringview;++query T+SELECT regexp_replace('ABCabcABC', '(abc)', 'X', 'gi');+----+XXX++query T+SELECT regexp_replace('ABCabcABC', '(abc)', 'X', 'i');+----+XabcABC++query T+SELECT regexp_replace('foobarbaz', 'b..', 'X', 'g');+----+fooXX++query T+SELECT regexp_replace('foobarbaz', 'b..', 'X');+----+fooXbaz++query T+SELECT regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', 'g');+----+fooXarYXazY++query T+SELECT regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', NULL);+----+NULL++query T+SELECT regexp_replace('foobarbaz', 'b(..)', NULL, 'g');+----+NULL++query T+SELECT regexp_replace('foobarbaz', NULL, 'X\\1Y', 'g');+----+NULL++query T+SELECT regexp_replace('Thomas', '.[mN]a.', 'M');+----+ThM++query T+SELECT regexp_replace(NULL, 'b(..)', 'X\\1Y', 'g');+----+NULL++query T+SELECT regexp_replace('foobar', 'bar', 'xx', 'gi')+----+fooxx++query T+SELECT regexp_replace(arrow_cast('foobar', 'Dictionary(Int32, Utf8)'), 'bar', 'xx', 'gi')+----+fooxx++query TTT+select+ regexp_replace(col, NULL, 'c'),+ regexp_replace(col, 'a', NULL),+ regexp_replace(col, 'a', 'c', NULL)+from (values ('a'), ('b')) as tbl(col);+----+NULL NULL NULL+NULL NULL NULL\ No newline at end of file