Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-7205 : [C++][Gandiva] Implement regexp_like in Gandiva #8844

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cpp/src/gandiva/expr_decomposer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ Status ExprDecomposer::Visit(const FieldNode& node) {
// time.
const FunctionNode ExprDecomposer::TryOptimize(const FunctionNode& node) {
if (node.descriptor()->name() == "like") {
return LikeHolder::TryOptimize(node);
return SQLLikeHolder::TryOptimize(node);
} else if (node.descriptor()->name() == "regexp_matches" ||
node.descriptor()->name() == "regexp_like") {
return RegexpMatchesHolder::TryOptimize(node);
} else {
return node;
}
Expand Down
7 changes: 4 additions & 3 deletions cpp/src/gandiva/function_holder_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <unordered_map>

#include "arrow/status.h"

#include "gandiva/function_holder.h"
#include "gandiva/like_holder.h"
#include "gandiva/node.h"
Expand Down Expand Up @@ -62,8 +61,10 @@ class FunctionHolderRegistry {
private:
static map_type& makers() {
static map_type maker_map = {
{"like", LAMBDA_MAKER(LikeHolder)},
{"ilike", LAMBDA_MAKER(LikeHolder)},
{"like", LAMBDA_MAKER(SQLLikeHolder)},
{"ilike", LAMBDA_MAKER(SQLLikeHolder)},
{"regexp_matches", LAMBDA_MAKER(RegexpMatchesHolder)},
{"regexp_like", LAMBDA_MAKER(RegexpMatchesHolder)},
{"to_date", LAMBDA_MAKER(ToDateHolder)},
{"random", LAMBDA_MAKER(RandomGeneratorHolder)},
{"rand", LAMBDA_MAKER(RandomGeneratorHolder)},
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/gandiva/function_registry_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
kResultNullIfNull, "gdv_fn_ilike_utf8_utf8",
NativeFunction::kNeedsFunctionHolder),

NativeFunction("regexp_matches", {"regexp_like"}, DataTypeVector{utf8(), utf8()},
boolean(), kResultNullIfNull, "gdv_fn_regexp_matches_utf8_utf8",
NativeFunction::kNeedsFunctionHolder),

NativeFunction("ltrim", {}, DataTypeVector{utf8(), utf8()}, utf8(),
kResultNullIfNull, "ltrim_utf8_utf8", NativeFunction::kNeedsContext),

Expand Down
25 changes: 20 additions & 5 deletions cpp/src/gandiva/gdv_function_stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ extern "C" {

bool gdv_fn_like_utf8_utf8(int64_t ptr, const char* data, int data_len,
const char* pattern, int pattern_len) {
gandiva::LikeHolder* holder = reinterpret_cast<gandiva::LikeHolder*>(ptr);
gandiva::RegexpMatchesHolder* holder =
reinterpret_cast<gandiva::RegexpMatchesHolder*>(ptr);
return (*holder)(std::string(data, data_len));
}

bool gdv_fn_like_utf8_utf8_utf8(int64_t ptr, const char* data, int data_len,
const char* pattern, int pattern_len,
const char* escape_char, int escape_char_len) {
gandiva::LikeHolder* holder = reinterpret_cast<gandiva::LikeHolder*>(ptr);
return (*holder)(std::string(data, data_len));
return gdv_fn_like_utf8_utf8(ptr, data, data_len, pattern, pattern_len);
}

bool gdv_fn_ilike_utf8_utf8(int64_t ptr, const char* data, int data_len,
const char* pattern, int pattern_len) {
gandiva::LikeHolder* holder = reinterpret_cast<gandiva::LikeHolder*>(ptr);
return (*holder)(std::string(data, data_len));
return gdv_fn_like_utf8_utf8(ptr, data, data_len, pattern, pattern_len);
}

bool gdv_fn_regexp_matches_utf8_utf8(int64_t ptr, const char* data, int data_len,
const char* pattern, int pattern_len) {
return gdv_fn_like_utf8_utf8(ptr, data, data_len, pattern, pattern_len);
}

const char* gdv_fn_regexp_replace_utf8_utf8(
Expand Down Expand Up @@ -911,6 +915,17 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
types->i1_type() /*return_type*/, args,
reinterpret_cast<void*>(gdv_fn_ilike_utf8_utf8));

// gdv_fn_regexp_matches_utf8_utf8
args = {types->i64_type(), // int64_t ptr
types->i8_ptr_type(), // const char* data
types->i32_type(), // int data_len
types->i8_ptr_type(), // const char* pattern
types->i32_type()}; // int pattern_len

engine->AddGlobalMappingForFunc(
"gdv_fn_regexp_matches_utf8_utf8", types->i1_type() /*return_type*/, args,
reinterpret_cast<void*>(gdv_fn_regexp_matches_utf8_utf8));

// gdv_fn_regexp_replace_utf8_utf8
args = {types->i64_type(), // int64_t ptr
types->i64_type(), // int64_t holder_ptr
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/gandiva/gdv_function_stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ bool gdv_fn_like_utf8_utf8_utf8(int64_t ptr, const char* data, int data_len,
bool gdv_fn_ilike_utf8_utf8(int64_t ptr, const char* data, int data_len,
const char* pattern, int pattern_len);

bool gdv_fn_regexp_matches_utf8_utf8(int64_t ptr, const char* data, int data_len,
const char* pattern, int pattern_len);

int64_t gdv_fn_to_date_utf8_utf8_int32(int64_t context, int64_t ptr, const char* data,
int data_len, bool in1_validity,
const char* pattern, int pattern_len,
Expand Down
Loading