mirror of
https://github.com/apache/arrow.git
synced 2026-10-28 16:47:19 +08:00
Implements and expose hash functions
This commit is contained in:
1 parent
1218ce6bc8
commit
513b9a05ac
4 files changed
+26
-6
No files matched your search
@@ -21,6 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "arrow/util/value_parsing.h"
|
||||
#include "gandiva/hash_utils.h"
|
||||
#include "gandiva/engine.h"
|
||||
#include "gandiva/exported_funcs.h"
|
||||
#include "gandiva/in_holder.h"
|
||||
@@ -123,12 +124,13 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
|
||||
}
|
||||
|
||||
char* gdv_fn_sha256_from_numeric(int64_t context, double value){
|
||||
uint64_t value_as_long = gandiva::HashUtils::double_to_long(value);
|
||||
|
||||
|
||||
return gandiva::HashUtils::hash_using_SHA256(context, &value_as_long, sizeof(value_as_long));
|
||||
}
|
||||
|
||||
char* hash_sha256_from_string(int64_t context, const char* value){
|
||||
|
||||
char* gdv_fn_hash_sha256_from_string(int64_t context, const char* value, uint64_t value_length){
|
||||
return gandiva::HashUtils::hash_using_SHA256(context, value, value_length);
|
||||
}
|
||||
|
||||
int32_t gdv_fn_dec_from_string(int64_t context, const char* in, int32_t in_length,
|
||||
@@ -214,6 +216,16 @@ void ExportedStubFunctions::AddMappings(Engine* engine) const {
|
||||
types->i32_type() /*return_type*/, args,
|
||||
reinterpret_cast<void*>(gdv_fn_dec_from_string));
|
||||
|
||||
// gdv_fn_sha256_from_numeric
|
||||
args = {
|
||||
types->i64_type(), // context
|
||||
types->double_type() // value
|
||||
};
|
||||
|
||||
engine->AddGlobalMappingForFunc("gdv_fn_sha256_from_numeric",
|
||||
types->i8_ptr_type() /*return_type*/, args,
|
||||
reinterpret_cast<void *>(gdv_fn_sha256_from_numeric));
|
||||
|
||||
// gdv_fn_dec_to_string
|
||||
args = {
|
||||
types->i64_type(), // context
|
||||
|
||||
@@ -50,7 +50,7 @@ int gdv_fn_time_with_zone(int* time_fields, const char* zone, int zone_len,
|
||||
|
||||
char* gdv_fn_sha256_from_numeric(int64_t context, double value);
|
||||
|
||||
char* hash_sha256_from_string(int64_t context, const char* value, int32_t value_length);
|
||||
char* gdv_fn_hash_sha256_from_string(int64_t context, const char* value, uint64_t value_length);
|
||||
|
||||
int32_t gdv_fn_dec_from_string(int64_t context, const char* in, int32_t in_length,
|
||||
int32_t* precision_from_str, int32_t* scale_from_str,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <cstring>
|
||||
#include "hash_utils.h"
|
||||
#include "gandiva/hash_utils.h"
|
||||
#include "openssl/evp.h"
|
||||
|
||||
namespace gandiva {
|
||||
char * HashUtils::hash_using_SHA256(int64_t context, const void *message, size_t message_length) {
|
||||
char* HashUtils::hash_using_SHA256(int64_t context, const void *message, size_t message_length) {
|
||||
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
|
||||
|
||||
EVP_DigestInit_ex(md_ctx, EVP_sha256(), nullptr);
|
||||
@@ -41,6 +41,12 @@ namespace gandiva {
|
||||
return result_buffer;
|
||||
}
|
||||
|
||||
uint64_t HashUtils::double_to_long(double value) {
|
||||
uint64_t result;
|
||||
memcpy(&result, &value, sizeof(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
void HashUtils::clean_char_array(char *buffer) {
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define ARROW_SRC_HASH_UTILS_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include "gandiva/visibility.h"
|
||||
|
||||
namespace gandiva {
|
||||
@@ -9,6 +10,7 @@ namespace gandiva {
|
||||
public:
|
||||
static inline char *hash_using_SHA256(int64_t context, const void *message, size_t message_length);
|
||||
|
||||
static uint64_t double_to_long(double value);
|
||||
private:
|
||||
static inline void clean_char_array(char *buffer);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user