Fix linter suggestions on c++ files

This commit is contained in:
João Pedro authored and Anthony Louis committed 2021-04-09 19:34:23 -03:00
1 parent d044ab4920
commit ea58b145d1
5 files changed
+143 -111

No files matched your search

+67 -68
View File
@@ -123,72 +123,68 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
return 0;
}
#define SHA128_HASH_FUNCTION(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha128_from_##TYPE(int64_t context, gdv_##TYPE value, \
bool validity, u_int32_t *out_length) { \
if(!validity){ \
*out_length = 0; \
return ""; \
} \
\
auto value_as_long = gandiva::HashUtils::DoubleToLong((double)value); \
\
const char *result = gandiva::HashUtils::HashUsingSha128(context, \
&value_as_long, \
sizeof(value_as_long), \
out_length); \
\
return result; \
} \
#define SHA128_HASH_FUNCTION(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha128_from_##TYPE(int64_t context, gdv_##TYPE value, \
bool validity, u_int32_t *out_length) { \
if(!validity){ \
*out_length = 0; \
return ""; \
} \
auto value_as_long = gandiva::HashUtils::DoubleToLong((double)value); \
const char *result = gandiva::HashUtils::HashUsingSha128(context, \
&value_as_long, \
sizeof(value_as_long), \
out_length); \
\
return result; \
} \
#define SHA128_HASH_FUNCTION_BUF(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha128_from_##TYPE(int64_t context, \
gdv_##TYPE value, \
int32_t value_length, \
bool value_validity, \
u_int32_t *out_length) { \
if(!value_validity){ \
*out_length = 0; \
return ""; \
} \
\
return gandiva::HashUtils::HashUsingSha128(context, value, value_length, out_length); \
#define SHA128_HASH_FUNCTION_BUF(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha128_from_##TYPE(int64_t context, \
gdv_##TYPE value, \
int32_t value_length, \
bool value_validity, \
u_int32_t *out_length) { \
if(!value_validity){ \
*out_length = 0; \
return ""; \
} \
return gandiva::HashUtils::HashUsingSha128(context, value, \
value_length, out_length); \
}
#define SHA256_HASH_FUNCTION(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha256_from_##TYPE(int64_t context, gdv_##TYPE value, \
bool validity, u_int32_t *out_length) { \
if(!validity){ \
*out_length = 0; \
return ""; \
} \
\
auto value_as_long = gandiva::HashUtils::DoubleToLong((double)value); \
\
const char *result = gandiva::HashUtils::HashUsingSha256(context, \
&value_as_long, \
sizeof(value_as_long), \
out_length); \
\
return result; \
} \
#define SHA256_HASH_FUNCTION(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha256_from_##TYPE(int64_t context, gdv_##TYPE value, \
bool validity, u_int32_t *out_length) { \
if(!validity){ \
*out_length = 0; \
return ""; \
} \
auto value_as_long = gandiva::HashUtils::DoubleToLong((double)value); \
const char *result = gandiva::HashUtils::HashUsingSha256(context, \
&value_as_long, \
sizeof(value_as_long),\
out_length); \
return result; \
} \
#define SHA256_HASH_FUNCTION_BUF(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha256_from_##TYPE(int64_t context, \
gdv_##TYPE value, \
int32_t value_length, \
bool value_validity, \
u_int32_t *out_length) { \
if(!value_validity){ \
*out_length = 0; \
return ""; \
} \
\
return gandiva::HashUtils::HashUsingSha256(context, value, value_length, out_length); \
#define SHA256_HASH_FUNCTION_BUF(TYPE) \
GANDIVA_EXPORT \
const char *gdv_fn_sha256_from_##TYPE(int64_t context, \
gdv_##TYPE value, \
int32_t value_length, \
bool value_validity, \
u_int32_t *out_length) { \
if(!value_validity){ \
*out_length = 0; \
return ""; \
} \
\
return gandiva::HashUtils::HashUsingSha256(context, value, \
value_length, out_length); \
}
// Expand inner macro for all numeric types.
@@ -582,7 +578,8 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
};
engine->AddGlobalMappingForFunc("gdv_fn_sha128_from_date32",
types->i8_ptr_type() /*return_type*/, args,
reinterpret_cast<void *>(gdv_fn_sha128_from_date32));
reinterpret_cast<void *>(gdv_fn_sha128_from_date32)
);
// gdv_fn_sha128_from_time32
args = {
@@ -593,7 +590,8 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
};
engine->AddGlobalMappingForFunc("gdv_fn_sha128_from_time32",
types->i8_ptr_type() /*return_type*/, args,
reinterpret_cast<void *>(gdv_fn_sha128_from_time32));
reinterpret_cast<void *>(gdv_fn_sha128_from_time32)
);
// gdv_fn_sha128_from_timestamp
args = {
@@ -604,7 +602,9 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
};
engine->AddGlobalMappingForFunc("gdv_fn_sha128_from_timestamp",
types->i8_ptr_type() /*return_type*/, args,
reinterpret_cast<void *>(gdv_fn_sha128_from_timestamp));
reinterpret_cast<void *>(
gdv_fn_sha128_from_timestamp
));
// gdv_fn_hash_sha128_from_utf8
args = {
@@ -630,7 +630,8 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
engine->AddGlobalMappingForFunc("gdv_fn_sha128_from_binary",
types->i8_ptr_type() /*return_type*/, args,
reinterpret_cast<void *>(gdv_fn_sha128_from_binary));
reinterpret_cast<void *>(gdv_fn_sha128_from_binary)
);
// gdv_fn_sha256_from_int8
args = {
@@ -822,7 +823,5 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
engine->AddGlobalMappingForFunc("gdv_fn_sha256_from_binary",
types->i8_ptr_type() /*return_type*/, args,
reinterpret_cast<void *>(gdv_fn_sha256_from_binary));
}
} // namespace gandiva
+4 -2
View File
@@ -67,7 +67,8 @@ bool in_expr_lookup_utf8(int64_t ptr, const char* data, int data_len, bool in_va
int gdv_fn_time_with_zone(int* time_fields, const char* zone, int zone_len,
int64_t* ret_time);
const char *gdv_fn_sha256_from_float64(int64_t context, double value, bool validity, unsigned int *out_length);
const char *gdv_fn_sha256_from_float64(int64_t context, double value, bool validity,
unsigned int *out_length);
const char *gdv_fn_sha256_from_utf8(int64_t context,
char *value,
@@ -75,7 +76,8 @@ const char *gdv_fn_sha256_from_utf8(int64_t context,
bool value_validity,
uint32_t *out_length);
const char *gdv_fn_sha128_from_float64(int64_t context, double value, bool validity, unsigned int *out_length);
const char *gdv_fn_sha128_from_float64(int64_t context, double value, bool validity,
unsigned int *out_length);
const char *gdv_fn_sha128_from_utf8(int64_t context,
char *value,
+18 -12
View File
@@ -27,7 +27,8 @@ namespace gandiva {
u_int32_t* out_length) {
// The buffer size is the hash size + null character
int sha256_result_length = 65;
return HashUtils::GetHash(context, message, message_length, EVP_sha256(), sha256_result_length, out_length);
return HashUtils::GetHash(context, message, message_length, EVP_sha256(),
sha256_result_length, out_length);
}
const char* HashUtils::HashUsingSha128(int64_t context,
const void* message,
@@ -35,7 +36,8 @@ namespace gandiva {
u_int32_t* out_length) {
// The buffer size is the hash size + null character
int sha128_result_length = 41;
return HashUtils::GetHash(context, message, message_length, EVP_sha1(), sha128_result_length, out_length);
return HashUtils::GetHash(context, message, message_length, EVP_sha1(),
sha128_result_length, out_length);
}
const char* HashUtils::GetHash(int64_t context,
@@ -46,21 +48,24 @@ namespace gandiva {
u_int32_t* out_length) {
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
if(md_ctx == nullptr){
HashUtils::ErrorMessage(context, "Could not allocate memory for SHA processing.");
if (md_ctx == nullptr) {
HashUtils::ErrorMessage(context, "Could not allocate memory "
"for SHA processing.");
return "";
}
int evp_success_status = 1;
if(EVP_DigestInit_ex(md_ctx, hash_type, nullptr) != evp_success_status){
HashUtils::ErrorMessage(context, "Could not obtain the hash for the defined value.");
if (EVP_DigestInit_ex(md_ctx, hash_type, nullptr) != evp_success_status) {
HashUtils::ErrorMessage(context, "Could not obtain the hash "
"for the defined value.");
EVP_MD_CTX_free(md_ctx);
return "";
}
if(EVP_DigestUpdate(md_ctx, message, message_length) != evp_success_status){
HashUtils::ErrorMessage(context, "Could not obtain the hash for the defined value.");
if (EVP_DigestUpdate(md_ctx, message, message_length) != evp_success_status) {
HashUtils::ErrorMessage(context, "Could not obtain the hash for "
"the defined value.");
EVP_MD_CTX_free(md_ctx);
return "";
}
@@ -68,8 +73,9 @@ namespace gandiva {
int hash_size = EVP_MD_size(hash_type);
auto* result = static_cast<unsigned char*>(OPENSSL_malloc(hash_size));
if(result == nullptr){
HashUtils::ErrorMessage(context, "Could not allocate memory for SHA processing.");
if (result == nullptr) {
HashUtils::ErrorMessage(context, "Could not allocate memory "
"for SHA processing.");
EVP_MD_CTX_free(md_ctx);
return "";
}
@@ -114,8 +120,8 @@ namespace gandiva {
buffer[0] = '\0';
}
void HashUtils::ErrorMessage(int64_t context_ptr, char const *err_msg){
void HashUtils::ErrorMessage(int64_t context_ptr, char const *err_msg) {
auto context = reinterpret_cast<gandiva::ExecutionContext*>(context_ptr);
context->set_error_msg(err_msg);
}
} // namespace gandiva
} // namespace gandiva
+1 -1
View File
@@ -49,6 +49,6 @@ namespace gandiva {
static void ErrorMessage(int64_t context_ptr, char const *err_msg);
};
}
} // namespace gandiva
#endif //ARROW_SRC_HASH_UTILS_H_
+53 -28
View File
@@ -56,8 +56,10 @@ TEST_F(TestHash, TestSimple) {
// hash64(a)
auto node_a = TreeExprBuilder::MakeField(field_a);
auto literal_10 = TreeExprBuilder::MakeLiteral((int32_t)10);
auto hash32 = TreeExprBuilder::MakeFunction("hash32", {node_a, literal_10}, int32());
auto hash64 = TreeExprBuilder::MakeFunction("hash64", {node_a}, int64());
auto hash32 = TreeExprBuilder::MakeFunction("hash32",
{node_a, literal_10}, int32());
auto hash64 = TreeExprBuilder::MakeFunction("hash64",
{node_a}, int64());
auto expr_0 = TreeExprBuilder::MakeExpression(hash32, res_0);
auto expr_1 = TreeExprBuilder::MakeExpression(hash64, res_1);
@@ -108,9 +110,11 @@ TEST_F(TestHash, TestBuf) {
// hash32(a)
// hash64(a, 10)
auto node_a = TreeExprBuilder::MakeField(field_a);
auto literal_10 = TreeExprBuilder::MakeLiteral((int64_t)10);
auto hash32 = TreeExprBuilder::MakeFunction("hash32", {node_a}, int32());
auto hash64 = TreeExprBuilder::MakeFunction("hash64", {node_a, literal_10}, int64());
auto literal_10 = TreeExprBuilder::MakeLiteral(static_cast<int64_t>(10));
auto hash32 = TreeExprBuilder::MakeFunction("hash32",
{node_a}, int32());
auto hash64 = TreeExprBuilder::MakeFunction("hash64",
{node_a, literal_10}, int64());
auto expr_0 = TreeExprBuilder::MakeExpression(hash32, res_0);
auto expr_1 = TreeExprBuilder::MakeExpression(hash64, res_1);
@@ -166,25 +170,30 @@ TEST_F(TestHash, TestSha256Simple) {
// build expressions.
// hashSHA256(a)
auto node_a = TreeExprBuilder::MakeField(field_a);
auto hashSha256_1 = TreeExprBuilder::MakeFunction("hashSHA256", {node_a}, utf8());
auto hashSha256_1 = TreeExprBuilder::MakeFunction("hashSHA256",
{node_a}, utf8());
auto expr_0 = TreeExprBuilder::MakeExpression(hashSha256_1, res_0);
auto node_b = TreeExprBuilder::MakeField(field_b);
auto hashSha256_2 = TreeExprBuilder::MakeFunction("hashSHA256", {node_b}, utf8());
auto hashSha256_2 = TreeExprBuilder::MakeFunction("hashSHA256",
{node_b}, utf8());
auto expr_1 = TreeExprBuilder::MakeExpression(hashSha256_2, res_1);
auto node_c = TreeExprBuilder::MakeField(field_c);
auto hashSha256_3 = TreeExprBuilder::MakeFunction("hashSHA256", {node_c}, utf8());
auto hashSha256_3 = TreeExprBuilder::MakeFunction("hashSHA256",
{node_c}, utf8());
auto expr_2 = TreeExprBuilder::MakeExpression(hashSha256_3, res_2);
auto node_d = TreeExprBuilder::MakeField(field_d);
auto hashSha256_4 = TreeExprBuilder::MakeFunction("hashSHA256", {node_d}, utf8());
auto hashSha256_4 = TreeExprBuilder::MakeFunction("hashSHA256",
{node_d}, utf8());
auto expr_3 = TreeExprBuilder::MakeExpression(hashSha256_4, res_3);
// Build a projector for the expressions.
std::shared_ptr<Projector> projector;
auto status =
Projector::Make(schema, {expr_0, expr_1, expr_2, expr_3}, TestConfiguration(), &projector);
Projector::Make(schema, {expr_0, expr_1, expr_2, expr_3},
TestConfiguration(), &projector);
EXPECT_TRUE(status.ok()) << status.message();
// Create a row-batch with some sample data
@@ -204,8 +213,9 @@ TEST_F(TestHash, TestSha256Simple) {
MakeArrowArrayFloat64({1.0, 0.0}, validity_array);
// prepare input record batch
auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array_int32, array_int64,
array_float32, array_float64});
auto in_batch = arrow::RecordBatch::Make(schema, num_records,
{array_int32, array_int64,
array_float32, array_float64});
// Evaluate expression
arrow::ArrayVector outputs;
@@ -228,7 +238,8 @@ TEST_F(TestHash, TestSha256Varlen) {
// build expressions.
// hashSHA256(a)
auto node_a = TreeExprBuilder::MakeField(field_a);
auto hashSha256 = TreeExprBuilder::MakeFunction("hashSHA256", {node_a}, utf8());
auto hashSha256 = TreeExprBuilder::MakeFunction("hashSHA256",
{node_a}, utf8());
auto expr_0 = TreeExprBuilder::MakeExpression(hashSha256, res_0);
// Build a projector for the expressions.
@@ -240,8 +251,10 @@ TEST_F(TestHash, TestSha256Varlen) {
// Create a row-batch with some sample data
int num_records = 3;
std::string first_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn\nY [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]";
std::string second_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeın\nY [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ] コンニチハ";
std::string first_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn\nY "
"[ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]";
std::string second_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeın\nY "
"[ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ] コンニチハ";
auto array_a =
MakeArrowArrayUtf8({"foo", first_string, second_string}, {false, true, true});
@@ -259,7 +272,8 @@ TEST_F(TestHash, TestSha256Varlen) {
EXPECT_EQ(response->GetScalar(0).ValueOrDie()->ToString(), "");
for (int i = 1; i < num_records; ++i) {
const auto &value_at_position = response->GetScalar(i).ValueOrDie()->ToString();
EXPECT_NE(value_at_position, response->GetScalar(i - 1).ValueOrDie()->ToString());
EXPECT_NE(value_at_position,
response->GetScalar(i - 1).ValueOrDie()->ToString());
}
}
@@ -280,25 +294,30 @@ TEST_F(TestHash, TestSha128Simple) {
// build expressions.
// hashSHA128(a)
auto node_a = TreeExprBuilder::MakeField(field_a);
auto hashSha128_1 = TreeExprBuilder::MakeFunction("hashSHA128", {node_a}, utf8());
auto hashSha128_1 = TreeExprBuilder::MakeFunction("hashSHA128",
{node_a}, utf8());
auto expr_0 = TreeExprBuilder::MakeExpression(hashSha128_1, res_0);
auto node_b = TreeExprBuilder::MakeField(field_b);
auto hashSha128_2 = TreeExprBuilder::MakeFunction("hashSHA128", {node_b}, utf8());
auto hashSha128_2 = TreeExprBuilder::MakeFunction("hashSHA128",
{node_b}, utf8());
auto expr_1 = TreeExprBuilder::MakeExpression(hashSha128_2, res_1);
auto node_c = TreeExprBuilder::MakeField(field_c);
auto hashSha128_3 = TreeExprBuilder::MakeFunction("hashSHA128", {node_c}, utf8());
auto hashSha128_3 = TreeExprBuilder::MakeFunction("hashSHA128",
{node_c}, utf8());
auto expr_2 = TreeExprBuilder::MakeExpression(hashSha128_3, res_2);
auto node_d = TreeExprBuilder::MakeField(field_d);
auto hashSha128_4 = TreeExprBuilder::MakeFunction("hashSHA128", {node_d}, utf8());
auto hashSha128_4 = TreeExprBuilder::MakeFunction("hashSHA128",
{node_d}, utf8());
auto expr_3 = TreeExprBuilder::MakeExpression(hashSha128_4, res_3);
// Build a projector for the expressions.
std::shared_ptr<Projector> projector;
auto status =
Projector::Make(schema, {expr_0, expr_1, expr_2, expr_3}, TestConfiguration(), &projector);
Projector::Make(schema, {expr_0, expr_1, expr_2, expr_3},
TestConfiguration(), &projector);
EXPECT_TRUE(status.ok()) << status.message();
// Create a row-batch with some sample data
@@ -318,8 +337,9 @@ TEST_F(TestHash, TestSha128Simple) {
MakeArrowArrayFloat64({1.0, 0.0}, validity_array);
// prepare input record batch
auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array_int32, array_int64,
array_float32, array_float64});
auto in_batch = arrow::RecordBatch::Make(schema, num_records,
{array_int32, array_int64,
array_float32, array_float64});
// Evaluate expression
arrow::ArrayVector outputs;
@@ -342,7 +362,8 @@ TEST_F(TestHash, TestSha128Varlen) {
// build expressions.
// hashSHA128(a)
auto node_a = TreeExprBuilder::MakeField(field_a);
auto hashSha128 = TreeExprBuilder::MakeFunction("hashSHA128", {node_a}, utf8());
auto hashSha128 = TreeExprBuilder::MakeFunction("hashSHA128",
{node_a}, utf8());
auto expr_0 = TreeExprBuilder::MakeExpression(hashSha128, res_0);
// Build a projector for the expressions.
@@ -354,11 +375,14 @@ TEST_F(TestHash, TestSha128Varlen) {
// Create a row-batch with some sample data
int num_records = 3;
std::string first_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn\nY [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]";
std::string second_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeın\nY [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ] コンニチハ";
std::string first_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn\nY [ˈʏpsilɔn], "
"Yen [jɛn], Yoga [ˈjoːgɑ]";
std::string second_string = "ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeın\nY [ˈʏpsilɔn], "
"Yen [jɛn], Yoga [ˈjoːgɑ] コンニチハ";
auto array_a =
MakeArrowArrayUtf8({"foo", first_string, second_string}, {false, true, true});
MakeArrowArrayUtf8({"foo", first_string, second_string},
{false, true, true});
// prepare input record batch
auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array_a});
@@ -373,7 +397,8 @@ TEST_F(TestHash, TestSha128Varlen) {
EXPECT_EQ(response->GetScalar(0).ValueOrDie()->ToString(), "");
for (int i = 1; i < num_records; ++i) {
const auto &value_at_position = response->GetScalar(i).ValueOrDie()->ToString();
EXPECT_NE(value_at_position, response->GetScalar(i - 1).ValueOrDie()->ToString());
EXPECT_NE(value_at_position,
response->GetScalar(i - 1).ValueOrDie()->ToString());
}
}
} // namespace gandiva