ishaaaan17 opened a new pull request, #53160:
URL: https://github.com/apache/arrow/pull/53160

   ### rationale for this change
   
   in `cpp/src/arrow/compute/kernels/scalar_string_ascii.cc`, the string 
matching kernels (`match_substring`, `starts_with`, `ends_with`, 
`match_substring_regex` and `match_like`) rebuild their matcher on every call 
to `Exec`. for regex matchers that means the RE2 DFA is recompiled for every 
batch in a stream or chunked array. plain matchers reallocate and rebuild the 
Knuth-Morris-Pratt prefix table each time.
   
   this also closes out the existing todo in `MatchSubstring`:
   `// TODO Cache matcher across invocations (for regex compilation)`.
   
   ### what changes are included in this PR?
   
   - replaced `OptionsWrapper<MatchSubstringOptions>` with a 
`MatchSubstringState : public KernelState` that caches the plain and regex 
matchers.
   - kept `MatchSubstringState::Get(ctx)` so other kernels and tests that use 
the old accessor still work.
   - `PlainSubstringMatcher`, `PlainStartsWithMatcher`, `PlainEndsWithMatcher` 
and `RegexSubstringMatcher` now reuse their compiled matchers across batches.
   - `MatchLike` looks at the SQL LIKE pattern and sets up the converter state 
once, instead of once per batch.
   - ran `clang-format`.
   
   ### are these changes tested?
   
   yes, by the existing kernel tests in 
`cpp/src/arrow/compute/kernels/scalar_string_test.cc`. they run the matching 
kernels over chunks, slices and scalars through `CheckScalarUnary`.
   
   ### are there any user-facing changes?
   
   no public api changes.
   
   ### was ai used for this PR?
   
   in line with the [ai generation 
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
 here is how ai was used.
   
   **pr code and description written by:**
   - [x] human
   - [x] ai
   
   **reviewed before submission by:**
   - [x] human
   - [ ] ai
   - [ ] not reviewed
   
   i used an llm assistant to look at different ways of caching the matchers 
and to draft the first version of the changes. i then went through and reworked 
the design myself, checked that the old state accessors still work, made sure 
the options are stored safely, and formatted the code.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to