mirror of
https://github.com/apache/arrow.git
synced 2026-10-28 16:47:19 +08:00
Change class to first class functions
This commit is contained in:
1 parent
220735e0da
commit
9a6ecd328e
3 files changed
+48
-59
No files matched your search
@@ -128,11 +128,11 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
|
||||
const char *gdv_fn_sha1_##TYPE(int64_t context, gdv_##TYPE value, \
|
||||
bool validity, int32_t *out_length) { \
|
||||
if (!validity) { \
|
||||
return gandiva::HashUtils::HashUsingSha1(context, NULLPTR, \
|
||||
return gandiva::gdv_hash_using_sha1(context, NULLPTR, \
|
||||
0, out_length); \
|
||||
} \
|
||||
auto value_as_long = gandiva::HashUtils::DoubleToLong((double)value); \
|
||||
const char *result = gandiva::HashUtils::HashUsingSha1(context, \
|
||||
auto value_as_long = gandiva::gdv_double_to_long((double)value); \
|
||||
const char *result = gandiva::gdv_hash_using_sha1(context, \
|
||||
&value_as_long, \
|
||||
sizeof(value_as_long), \
|
||||
out_length); \
|
||||
@@ -148,10 +148,10 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
|
||||
bool value_validity, \
|
||||
int32_t *out_length) { \
|
||||
if (!value_validity) { \
|
||||
return gandiva::HashUtils::HashUsingSha1(context, NULLPTR, \
|
||||
return gandiva::gdv_hash_using_sha1(context, NULLPTR, \
|
||||
0, out_length); \
|
||||
} \
|
||||
return gandiva::HashUtils::HashUsingSha1(context, value, \
|
||||
return gandiva::gdv_hash_using_sha1(context, value, \
|
||||
value_length, out_length); \
|
||||
}
|
||||
|
||||
@@ -160,11 +160,11 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
|
||||
const char *gdv_fn_sha256_##TYPE(int64_t context, gdv_##TYPE value, \
|
||||
bool validity, int32_t *out_length) { \
|
||||
if (!validity) { \
|
||||
return gandiva::HashUtils::HashUsingSha256(context, NULLPTR, \
|
||||
return gandiva::gdv_hash_using_sha256(context, NULLPTR, \
|
||||
0, out_length); \
|
||||
} \
|
||||
auto value_as_long = gandiva::HashUtils::DoubleToLong((double)value); \
|
||||
const char *result = gandiva::HashUtils::HashUsingSha256(context, \
|
||||
auto value_as_long = gandiva::gdv_double_to_long((double)value); \
|
||||
const char *result = gandiva::gdv_hash_using_sha256(context, \
|
||||
&value_as_long, \
|
||||
sizeof(value_as_long), \
|
||||
out_length); \
|
||||
@@ -179,11 +179,11 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
|
||||
bool value_validity, \
|
||||
int32_t *out_length) { \
|
||||
if (!value_validity) { \
|
||||
return gandiva::HashUtils::HashUsingSha256(context, NULLPTR, \
|
||||
return gandiva::gdv_hash_using_sha256(context, NULLPTR, \
|
||||
0, out_length); \
|
||||
} \
|
||||
\
|
||||
return gandiva::HashUtils::HashUsingSha256(context, value, \
|
||||
return gandiva::gdv_hash_using_sha256(context, value, \
|
||||
value_length, out_length); \
|
||||
}
|
||||
|
||||
@@ -227,12 +227,12 @@ const char* gdv_fn_sha256_decimal128(int64_t context, int64_t x_high, uint64_t x
|
||||
int32_t /*x_precision*/, int32_t /*x_scale*/,
|
||||
gdv_boolean x_isvalid, int32_t *out_length) {
|
||||
if (!x_isvalid) {
|
||||
return gandiva::HashUtils::HashUsingSha256(context, NULLPTR,
|
||||
return gandiva::gdv_hash_using_sha256(context, NULLPTR,
|
||||
0, out_length);
|
||||
}
|
||||
|
||||
const gandiva::BasicDecimal128 decimal_128(x_high, x_low);
|
||||
return gandiva::HashUtils::HashUsingSha256(context, decimal_128.ToBytes().data(),
|
||||
return gandiva::gdv_hash_using_sha256(context, decimal_128.ToBytes().data(),
|
||||
16, out_length);
|
||||
}
|
||||
|
||||
@@ -241,12 +241,12 @@ const char* gdv_fn_sha1_decimal128(int64_t context, int64_t x_high, uint64_t x_l
|
||||
int32_t /*x_precision*/, int32_t /*x_scale*/,
|
||||
gdv_boolean x_isvalid, int32_t *out_length) {
|
||||
if (!x_isvalid) {
|
||||
return gandiva::HashUtils::HashUsingSha1(context, NULLPTR,
|
||||
return gandiva::gdv_hash_using_sha1(context, NULLPTR,
|
||||
0, out_length);
|
||||
}
|
||||
|
||||
const gandiva::BasicDecimal128 decimal_128(x_high, x_low);
|
||||
return gandiva::HashUtils::HashUsingSha1(context, decimal_128.ToBytes().data(),
|
||||
return gandiva::gdv_hash_using_sha1(context, decimal_128.ToBytes().data(),
|
||||
16, out_length);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,29 +18,29 @@
|
||||
#include <cstring>
|
||||
#include "openssl/evp.h"
|
||||
#include "gandiva/hash_utils.h"
|
||||
#include "gandiva/execution_context.h"
|
||||
#include "gandiva/gdv_function_stubs.h"
|
||||
#include "arrow/util/logging.h"
|
||||
|
||||
namespace gandiva {
|
||||
const char* HashUtils::HashUsingSha256(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
int32_t *out_length) {
|
||||
const char* gdv_hash_using_sha256(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
int32_t *out_length) {
|
||||
constexpr int sha256_result_length = 64;
|
||||
return HashUtils::GetHash(context, message, message_length, EVP_sha256(),
|
||||
return gdv_hash_using_sha(context, message, message_length, EVP_sha256(),
|
||||
sha256_result_length, out_length);
|
||||
}
|
||||
const char* HashUtils::HashUsingSha1(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
int32_t *out_length) {
|
||||
|
||||
const char* gdv_hash_using_sha1(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
int32_t *out_length) {
|
||||
constexpr int sha1_result_length = 40;
|
||||
return HashUtils::GetHash(context, message, message_length, EVP_sha1(),
|
||||
return gdv_hash_using_sha(context, message, message_length, EVP_sha1(),
|
||||
sha1_result_length, out_length);
|
||||
}
|
||||
|
||||
const char* HashUtils::GetHash(int64_t context,
|
||||
const char* gdv_hash_using_sha(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
const EVP_MD *hash_type,
|
||||
@@ -49,8 +49,8 @@ namespace gandiva {
|
||||
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (md_ctx == nullptr) {
|
||||
HashUtils::ErrorMessage(context, "Could not create the context "
|
||||
"for SHA processing.");
|
||||
gdv_fn_context_set_error_msg(context,
|
||||
"Could not create the context for SHA processing.");
|
||||
*out_length = 0;
|
||||
return "";
|
||||
}
|
||||
@@ -72,8 +72,8 @@ namespace gandiva {
|
||||
auto* result = static_cast<unsigned char*>(OPENSSL_malloc(hash_digest_size));
|
||||
|
||||
if (result == nullptr) {
|
||||
HashUtils::ErrorMessage(context, "Could not allocate memory "
|
||||
"for SHA processing.");
|
||||
gdv_fn_context_set_error_msg(context,
|
||||
"Could not allocate memory for SHA processing");
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
*out_length = 0;
|
||||
return "";
|
||||
@@ -84,8 +84,8 @@ namespace gandiva {
|
||||
|
||||
if(result_length != hash_digest_size &&
|
||||
result_buf_size != (2 * hash_digest_size)){
|
||||
HashUtils::ErrorMessage(context, "Could not obtain the hash "
|
||||
"for the defined value.");
|
||||
gdv_fn_context_set_error_msg(context,
|
||||
"Could not obtain the hash for the defined value");
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
OPENSSL_free(result);
|
||||
|
||||
@@ -124,14 +124,9 @@ namespace gandiva {
|
||||
return result_buffer;
|
||||
}
|
||||
|
||||
uint64_t HashUtils::DoubleToLong(double value) {
|
||||
uint64_t gdv_double_to_long(double value) {
|
||||
uint64_t result;
|
||||
memcpy(&result, &value, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -24,31 +24,25 @@
|
||||
#include "openssl/evp.h"
|
||||
|
||||
namespace gandiva {
|
||||
class GANDIVA_EXPORT HashUtils {
|
||||
public:
|
||||
static const char *HashUsingSha256(int64_t context,
|
||||
const void *message,
|
||||
size_t message_length,
|
||||
int32_t *out_length);
|
||||
|
||||
static const char *HashUsingSha1(int64_t context,
|
||||
const void *message,
|
||||
size_t message_length,
|
||||
int32_t *out_length);
|
||||
const char* gdv_hash_using_sha256(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
int32_t *out_length);
|
||||
|
||||
static uint64_t DoubleToLong(double value);
|
||||
private:
|
||||
static inline void CleanCharArray(char *buffer);
|
||||
const char* gdv_hash_using_sha1(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
int32_t *out_length);
|
||||
|
||||
static const char *GetHash(int64_t context,
|
||||
const void *message,
|
||||
size_t message_length,
|
||||
const EVP_MD *hash_type,
|
||||
uint32_t result_buf_size,
|
||||
int32_t *out_length);
|
||||
const char* gdv_hash_using_sha(int64_t context,
|
||||
const void* message,
|
||||
size_t message_length,
|
||||
const EVP_MD *hash_type,
|
||||
uint32_t result_buf_size,
|
||||
int32_t *out_length);
|
||||
|
||||
static void ErrorMessage(int64_t context_ptr, char const *err_msg);
|
||||
};
|
||||
uint64_t gdv_double_to_long(double value);
|
||||
} // namespace gandiva
|
||||
|
||||
#endif //ARROW_SRC_HASH_UTILS_H_
|
||||
Reference in new issue
Block a user