You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/10 16:03:28 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #10471: ARROW-12952: [C++] Add count_substring_regex

pitrou commented on a change in pull request #10471:
URL: https://github.com/apache/arrow/pull/10471#discussion_r649293252



##########
File path: cpp/src/arrow/compute/kernels/scalar_string.cc
##########
@@ -1001,21 +1058,51 @@ const FunctionDoc count_substring_doc(
      "Null inputs emit null. The pattern must be given in MatchSubstringOptions."),
     {"strings"}, "MatchSubstringOptions");
 
+#ifdef ARROW_WITH_RE2
+const FunctionDoc count_substring_regex_doc(
+    "Count occurrences of substring",
+    ("For each string in `strings`, emit the number of occurrences of the given "
+     "regex pattern.\n"
+     "Null inputs emit null. The pattern must be given in MatchSubstringOptions."),
+    {"strings"}, "MatchSubstringOptions");
+#endif
+
 void AddCountSubstring(FunctionRegistry* registry) {
-  auto func = std::make_shared<ScalarFunction>("count_substring", Arity::Unary(),
-                                               &count_substring_doc);
-  for (const auto& ty : BaseBinaryTypes()) {
-    std::shared_ptr<DataType> offset_type;
-    if (ty->id() == Type::type::LARGE_BINARY || ty->id() == Type::type::LARGE_STRING) {
-      offset_type = int64();
-    } else {
-      offset_type = int32();
+  {
+    auto func = std::make_shared<ScalarFunction>("count_substring", Arity::Unary(),
+                                                 &count_substring_doc);
+    for (const auto& ty : BaseBinaryTypes()) {
+      std::shared_ptr<DataType> offset_type;
+      if (ty->id() == Type::type::LARGE_BINARY || ty->id() == Type::type::LARGE_STRING) {
+        offset_type = int64();
+      } else {
+        offset_type = int32();
+      }

Review comment:
       Nit, but may use `offset_bit_width()` from `type_traits.h`
   (e.g `offset_bit_width(ty->id()) == 64  ? int64() : int32()`)




-- 
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:
users@infra.apache.org