lidavidm commented on a change in pull request #9838:
URL: https://github.com/apache/arrow/pull/9838#discussion_r604902493
##########
File path: cpp/src/arrow/compute/kernels/scalar_string.cc
##########
@@ -411,40 +411,106 @@ 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);
+ }
+};
+
const FunctionDoc match_substring_doc(
"Match strings against literal pattern",
("For each string in `strings`, emit true iff it contains a given
pattern.\n"
"Null inputs emit null. The pattern must be given in
MatchSubstringOptions."),
{"strings"}, "MatchSubstringOptions");
+#ifdef ARROW_WITH_RE2
+template <typename offset_type>
Review comment:
Got it, I refactored that part. The Knuth-Morris-Pratt implementation
also had to be refactored as it was templated on offset_type, though it seems
that was unnecessary.
--
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]