Skip to content

Is pre-compile pattern string in regexp_match operation #11146

Description

@zhuliquan

Is your feature request related to a problem or challenge?

I noticed below code:

RegexMatch => binary_string_array_flag_op_scalar!(
array,
scalar,
regexp_is_match,
false,
false
),
RegexIMatch => binary_string_array_flag_op_scalar!(
array,
scalar,
regexp_is_match,
false,
true
),
RegexNotMatch => binary_string_array_flag_op_scalar!(
array,
scalar,
regexp_is_match,
true,
false
),
RegexNotIMatch => binary_string_array_flag_op_scalar!(
array,
scalar,
regexp_is_match,
true,
true
),

This looks like every time record_batch is evaluated, it will execute the compiled pattern string and use the compiled results to match arrow-array

Describe the solution you'd like

when building binary physical expr , we can pre-compile pattern string if op is regex_match

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. alamb commented on Jun 27, 2024

    @alamb
    Contributor

    Hi @zhuliquan -- I believe you are correct that the regexp is re-compiled for each batch. This is mentioned as one of the use cases for #8051

    I think it would be a nice improvement to look into pre-compiling the regexp somehow, though last time I checked the only benchmark we have (one of the clickbench queries) compiling the regexp was not a significant consumer of time

  2. zhuliquan commented on Jun 28, 2024

    @zhuliquan
    ContributorAuthor

    Hi @zhuliquan -- I believe you are correct that the regexp is re-compiled for each batch. This is mentioned as one of the use cases for #8051

    I think it would be a nice improvement to look into pre-compiling the regexp somehow, though last time I checked the only benchmark we have (one of the clickbench queries) compiling the regexp was not a significant consumer of time

    I think should pre-compiled when create binary-physical-expr, instead of evaluating record_batch.

    pub fn new(
    left: Arc<dyn PhysicalExpr>,
    op: Operator,
    right: Arc<dyn PhysicalExpr>,
    ) -> Self {
    Self { left, op, right }
    }

  3. alamb commented on Jun 28, 2024

    @alamb
    Contributor

    I think should pre-compiled when create binary-physical-expr, instead of evaluating record_batch.

    I think this makes sense to me. Thank you

    One thing to look into might be to replace the regexp match operator with a function (and have the function's implementation store the precompiled regexp)

    One tricky part might be serialization (in datafusion-proto). We can probably handle it via an extension codec or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions