Skip to content

Commit

Permalink
Two flags was removed from registry and function
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnnathanalmeida committed May 11, 2022
1 parent 9eda39f commit 6324122
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 38 deletions.
6 changes: 2 additions & 4 deletions cpp/src/gandiva/function_registry_string.cc
Expand Up @@ -440,12 +440,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
NativeFunction::kNeedsContext),

NativeFunction("binary", {}, DataTypeVector{binary()}, binary(), kResultNullIfNull,
"castBINARY_binary",
NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
"castBINARY_binary"),

NativeFunction("binary", {}, DataTypeVector{utf8()}, binary(), kResultNullIfNull,
"castBINARY_utf8",
NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
"castBINARY_utf8"),

NativeFunction("castVARBINARY", {}, DataTypeVector{binary(), int64()}, binary(),
kResultNullIfNull, "castVARBINARY_binary_int64",
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/gandiva/precompiled/string_ops.cc
Expand Up @@ -705,12 +705,12 @@ CAST_VARCHAR_FROM_VARLEN_TYPE(binary)
CAST_VARBINARY_FROM_STRING_AND_BINARY(utf8)
CAST_VARBINARY_FROM_STRING_AND_BINARY(binary)

#define CAST_BINARY_FROM_STRING_AND_BINARY(TYPE) \
GANDIVA_EXPORT \
const char* castBINARY_##TYPE(gdv_int64 context, const char* data, gdv_int32 data_len, \
int32_t* out_length) { \
*out_length = data_len; \
return data; \
#define CAST_BINARY_FROM_STRING_AND_BINARY(TYPE) \
GANDIVA_EXPORT \
const char* castBINARY_##TYPE(const char* data, gdv_int32 data_len, \
int32_t* out_length) { \
*out_length = data_len; \
return data; \
}

CAST_BINARY_FROM_STRING_AND_BINARY(utf8)
Expand Down
24 changes: 6 additions & 18 deletions cpp/src/gandiva/precompiled/string_ops_test.cc
Expand Up @@ -880,45 +880,33 @@ TEST(TestGdvFnStubs, TestCastVarbinaryBinary) {
}

TEST(TestGdvFnStubs, TestCastBinaryUtf8) {
gandiva::ExecutionContext ctx;

int64_t ctx_ptr = reinterpret_cast<int64_t>(&ctx);
int32_t out_len = 0;
const char* input = "abc";
const char* out;

out = castBINARY_utf8(ctx_ptr, input, 3, &out_len);
out = castBINARY_utf8(input, 3, &out_len);
EXPECT_EQ(std::string(out, out_len), input);

out = castBINARY_utf8(ctx_ptr, input, 1, &out_len);
out = castBINARY_utf8(input, 1, &out_len);
EXPECT_EQ(std::string(out, out_len), "a");

out = castBINARY_utf8(ctx_ptr, input, -3, &out_len);
out = castBINARY_utf8(input, 0, &out_len);
EXPECT_EQ(std::string(out, out_len), "");
EXPECT_THAT(ctx.get_error(),
::testing::HasSubstr("Output buffer length can't be negative"));
ctx.Reset();
}

TEST(TestGdvFnStubs, TestCastBinaryBinary) {
gandiva::ExecutionContext ctx;

int64_t ctx_ptr = reinterpret_cast<int64_t>(&ctx);
int32_t out_len = 0;
const char* input = "\\x41\\x42\\x43";
const char* out;

out = castBINARY_binary(ctx_ptr, input, 12, &out_len);
out = castBINARY_binary(input, 12, &out_len);
EXPECT_EQ(std::string(out, out_len), input);

out = castBINARY_binary(ctx_ptr, input, 8, &out_len);
out = castBINARY_binary(input, 8, &out_len);
EXPECT_EQ(std::string(out, out_len), "\\x41\\x42");

out = castBINARY_binary(ctx_ptr, input, -10, &out_len);
out = castBINARY_binary(input, 0, &out_len);
EXPECT_EQ(std::string(out, out_len), "");
EXPECT_THAT(ctx.get_error(),
::testing::HasSubstr("Output buffer length can't be negative"));
ctx.Reset();
}

TEST(TestStringOps, TestConcat) {
Expand Down
6 changes: 2 additions & 4 deletions cpp/src/gandiva/precompiled/types.h
Expand Up @@ -573,11 +573,9 @@ const char* castVARBINARY_binary_int64(gdv_int64 context, const char* data,
gdv_int32 data_len, int64_t out_len,
int32_t* out_length);

const char* castBINARY_utf8(gdv_int64 context, const char* data, gdv_int32 data_len,
int32_t* out_length);
const char* castBINARY_utf8(const char* data, gdv_int32 data_len, int32_t* out_length);

const char* castBINARY_binary(gdv_int64 context, const char* data, gdv_int32 data_len,
int32_t* out_length);
const char* castBINARY_binary(const char* data, gdv_int32 data_len, int32_t* out_length);

gdv_int32 levenshtein(int64_t context, const char* in1, int32_t in1_len, const char* in2,
int32_t in2_len);
Expand Down
14 changes: 8 additions & 6 deletions cpp/src/gandiva/tests/projector_test.cc
Expand Up @@ -2729,13 +2729,13 @@ TEST_F(TestProjector, TestCastBinaryUTF) {
EXPECT_TRUE(status.ok());

// Create a row-batch with some sample data
int num_records = 2;
int num_records = 3;

auto array0 = MakeArrowArrayUtf8({"a", "abc"}, {true, true});
auto array0 = MakeArrowArrayUtf8({"a", "abc", ""}, {true, true, true});

auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array0});

auto out_1 = MakeArrowArrayBinary({"a", "abc"}, {true, true});
auto out_1 = MakeArrowArrayBinary({"a", "abc", ""}, {true, true, true});

arrow::ArrayVector outputs;

Expand Down Expand Up @@ -2763,13 +2763,15 @@ TEST_F(TestProjector, TestCastBinaryBinary) {
EXPECT_TRUE(status.ok());

// Create a row-batch with some sample data
int num_records = 2;
int num_records = 3;

auto array0 = MakeArrowArrayUtf8({"\\x41\\x42\\x43", "\\x41\\x42"}, {true, true});
auto array0 =
MakeArrowArrayUtf8({"\\x41\\x42\\x43", "\\x41\\x42", ""}, {true, true, true});

auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array0});

auto out_1 = MakeArrowArrayBinary({"\\x41\\x42\\x43", "\\x41\\x42"}, {true, true});
auto out_1 =
MakeArrowArrayBinary({"\\x41\\x42\\x43", "\\x41\\x42", ""}, {true, true, true});

arrow::ArrayVector outputs;

Expand Down

0 comments on commit 6324122

Please sign in to comment.