Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex_match does not compile using the g flag #1429

Closed
tobyhede opened this issue Dec 9, 2021 · 1 comment · Fixed by #4203
Closed

regex_match does not compile using the g flag #1429

tobyhede opened this issue Dec 9, 2021 · 1 comment · Fixed by #4203
Labels
bug Something isn't working

Comments

@tobyhede
Copy link
Contributor

tobyhede commented Dec 9, 2021

Describe the bug
The regexp_match function fails to compile when supplied a g flag.

To Reproduce
At the moment many functions including regex match are not working correctly when accessed directly via the dataframe interface (I am working on a fix for this).
To reproduce this bug, setup a test in functions.rs

    test_function!(
            RegexpMatch,
            &[
                lit(ScalarValue::Utf8(Some("abc".to_string()))),
                lit(ScalarValue::Utf8(Some("a..".to_string()))),
                lit(ScalarValue::Utf8(Some("g".to_string()))),
            ],
            Ok(Some("abc")),
            &str,
            Utf8,
            StringArray
        );

This will fail with a compile error from the regex subsystem.

Expected behavior
The regex_match function should accept "g" as the standard regex global expression flag.

Additional context
the regex_match function, that does behave as expected includes some lines to format flags into a rust pattern:
https://github.com/apache/arrow-datafusion/blob/50a98805cdd6d5383f0c124d449ed549ca13428a/datafusion/src/physical_plan/regex_expressions.rs#L139

This mapping is not present in the regex_match function.

@Jefffrey
Copy link
Contributor

Jefffrey commented Nov 14, 2022

If we are using PostgreSQL as baseline, then supplying g flag to regexp_match() should indeed result in an error.

psql (15.1 (Debian 15.1-1.pgdg110+1))
Type "help" for help.

postgres=# select regexp_match('a', '[a-z]', 'g');
ERROR:  regexp_match() does not support the "global" option
HINT:  Use the regexp_matches function instead.
postgres=#

Reference: https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP

Supported flags: https://www.postgresql.org/docs/current/functions-matching.html#POSIX-EMBEDDED-OPTIONS-TABLE

Seems its regexp_matches() which is the one supporting g flag, but doesn't seem to be implemented in Datafusion yet (could raise an issue for this?)

Edit: created PR #4203 to improve the error message (to be like what PostgreSQL spits out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants