lidavidm commented on a change in pull request #9838:
URL: https://github.com/apache/arrow/pull/9838#discussion_r604824849
##########
File path: cpp/src/arrow/compute/kernels/scalar_string.cc
##########
@@ -411,40 +411,104 @@ void TransformMatchSubstring(const uint8_t* pattern,
int64_t pattern_length,
using MatchSubstringState = OptionsWrapper<MatchSubstringOptions>;
-template <typename Type>
+template <typename Type, template <typename offset_type> class Matcher>
struct MatchSubstring {
using offset_type = typename Type::offset_type;
static void Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
- MatchSubstringOptions arg = MatchSubstringState::Get(ctx);
- const uint8_t* pat = reinterpret_cast<const uint8_t*>(arg.pattern.c_str());
- const int64_t pat_size = arg.pattern.length();
+ // TODO Cache matcher across invocations (for regex compilation)
+ Matcher<offset_type> matcher(ctx, MatchSubstringState::Get(ctx));
+ if (ctx->HasError()) return;
StringBoolTransform<Type>(
ctx, batch,
- [pat, pat_size](const void* offsets, const uint8_t* data, int64_t
length,
- int64_t output_offset, uint8_t* output) {
- TransformMatchSubstring<offset_type>(
- pat, pat_size, reinterpret_cast<const offset_type*>(offsets),
data, length,
- output_offset, output);
+ [&matcher](const void* offsets, const uint8_t* data, int64_t length,
+ int64_t output_offset, uint8_t* output) {
+ matcher.Match(reinterpret_cast<const offset_type*>(offsets), data,
length,
+ output_offset, output);
},
out);
}
};
+template <typename offset_type>
+struct PlainSubstringMatcher {
+ const MatchSubstringOptions& options_;
+
+ PlainSubstringMatcher(KernelContext* ctx, const MatchSubstringOptions&
options)
+ : options_(options) {}
+
+ void Match(const offset_type* offsets, const uint8_t* data, int64_t length,
+ int64_t output_offset, uint8_t* output) {
+ const uint8_t* pat = reinterpret_cast<const
uint8_t*>(options_.pattern.c_str());
+ const int64_t pat_size = options_.pattern.length();
+ TransformMatchSubstring<offset_type>(pat, pat_size, offsets, data, length,
+ output_offset, output);
+ }
+};
+
+template <typename offset_type>
+struct RegexSubstringMatcher {
Review comment:
You are right, good catch.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]