Skip to content

Commit

Permalink
Clang executed to fix some errors in Lint c++
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnnathanalmeida committed May 11, 2022
1 parent 365b452 commit 6c082da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 44 deletions.
8 changes: 4 additions & 4 deletions cpp/src/gandiva/function_registry_string.cc
Expand Up @@ -439,12 +439,12 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
kResultNullIfNull, "right_utf8_int32",
NativeFunction::kNeedsContext),

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

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

NativeFunction("castVARBINARY", {}, DataTypeVector{binary(), int64()}, binary(),
Expand Down
28 changes: 14 additions & 14 deletions cpp/src/gandiva/precompiled/string_ops.cc
Expand Up @@ -705,20 +705,20 @@ 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) { \
int32_t len = static_cast<int32_t>(data_len); \
if (len < 0) { \
gdv_fn_context_set_error_msg(context, "Output buffer length can't be negative"); \
*out_length = 0; \
return ""; \
} \
\
*out_length = len; \
\
return data; \
#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) { \
int32_t len = static_cast<int32_t>(data_len); \
if (len < 0) { \
gdv_fn_context_set_error_msg(context, "Output buffer length can't be negative"); \
*out_length = 0; \
return ""; \
} \
\
*out_length = len; \
\
return data; \
}

CAST_BINARY_FROM_STRING_AND_BINARY(utf8)
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/gandiva/precompiled/string_ops_test.cc
Expand Up @@ -908,13 +908,13 @@ TEST(TestGdvFnStubs, TestCastBinaryBinary) {
const char* input = "\\x41\\x42\\x43";
const char* out;

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

out = castBINARY_binary(ctx_ptr, input, 8,&out_len);
out = castBINARY_binary(ctx_ptr, 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(ctx_ptr, input, -10, &out_len);
EXPECT_EQ(std::string(out, out_len), "");
EXPECT_THAT(ctx.get_error(),
::testing::HasSubstr("Output buffer length can't be negative"));
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/gandiva/precompiled/types.h
Expand Up @@ -573,11 +573,11 @@ 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(gdv_int64 context, 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(gdv_int64 context, 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
28 changes: 9 additions & 19 deletions cpp/src/gandiva/tests/projector_test.cc
Expand Up @@ -2684,24 +2684,21 @@ TEST_F(TestProjector, TestCastVarbinary) {
auto res_out1 = field("res_out1", arrow::binary());

// Build expression
auto cast_expr_1 = TreeExprBuilder::MakeExpression("castVARBINARY", {field0, field1}, res_out1);
auto cast_expr_1 =
TreeExprBuilder::MakeExpression("castVARBINARY", {field0, field1}, res_out1);

std::shared_ptr<Projector> projector;

auto status = Projector::Make(
schema, {cast_expr_1},
TestConfiguration(), &projector);
auto status = Projector::Make(schema, {cast_expr_1}, TestConfiguration(), &projector);

EXPECT_TRUE(status.ok());

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

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

auto array1 = MakeArrowArrayInt64(
{1, 3}, {true, true});
auto array1 = MakeArrowArrayInt64({1, 3}, {true, true});

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

Expand All @@ -2714,7 +2711,6 @@ TEST_F(TestProjector, TestCastVarbinary) {
EXPECT_TRUE(status.ok());

EXPECT_ARROW_ARRAY_EQUALS(out_1, outputs.at(0));

}

TEST_F(TestProjector, TestCastBinaryUTF) {
Expand All @@ -2729,17 +2725,14 @@ TEST_F(TestProjector, TestCastBinaryUTF) {

std::shared_ptr<Projector> projector;

auto status = Projector::Make(
schema, {cast_expr_1},
TestConfiguration(), &projector);
auto status = Projector::Make(schema, {cast_expr_1}, TestConfiguration(), &projector);

EXPECT_TRUE(status.ok());

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

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

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

Expand All @@ -2766,17 +2759,14 @@ TEST_F(TestProjector, TestCastBinaryBinary) {

std::shared_ptr<Projector> projector;

auto status = Projector::Make(
schema, {cast_expr_1},
TestConfiguration(), &projector);
auto status = Projector::Make(schema, {cast_expr_1}, TestConfiguration(), &projector);

EXPECT_TRUE(status.ok());

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

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

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

Expand Down

0 comments on commit 6c082da

Please sign in to comment.