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/05/06 21:05:02 UTC

[GitHub] [arrow] anthonylouisbsb commented on a change in pull request #10059: ARROW-12410: [C++][Gandiva] Implement regexp_replace function on Gandiva

anthonylouisbsb commented on a change in pull request #10059:
URL: https://github.com/apache/arrow/pull/10059#discussion_r627764037



##########
File path: cpp/src/gandiva/replace_holder.h
##########
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include <re2/re2.h>
+
+#include "arrow/status.h"
+
+#include "gandiva/execution_context.h"
+#include "gandiva/function_holder.h"
+#include "gandiva/node.h"
+#include "gandiva/visibility.h"
+
+namespace gandiva {
+
+/// Function Holder for 'replace'
+class GANDIVA_EXPORT ReplaceHolder : public FunctionHolder {
+ public:
+  ~ReplaceHolder() override = default;
+
+  static Status Make(const FunctionNode& node, std::shared_ptr<ReplaceHolder>* holder);
+
+  static Status Make(const std::string& sql_pattern,
+                     std::shared_ptr<ReplaceHolder>* holder);
+
+  /// Return true if the data matches the pattern.
+  const char* operator()(ExecutionContext* ptr, std::string& user_input,
+                         std::string& replace_input, int32_t* out_length) {
+    int32_t user_input_length = static_cast<int32_t>(user_input.size());
+    int32_t total_replaces = RE2::GlobalReplace(&user_input, regex_, replace_input);
+    bool was_replaced = false;
+
+    if (total_replaces < 0) {
+      return_error(ptr, user_input, replace_input);
+      *out_length = 0;
+    } else if (total_replaces == 0) {
+      *out_length = user_input_length;
+    } else {
+      was_replaced = true;
+    }
+
+    *out_length = static_cast<int32_t>(user_input.size());
+
+    if (!was_replaced) {
+      return user_input.data();

Review comment:
       Problem solved, now, for this case is returning the user input char pointer




-- 
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