Add functions for sha in decimal types

This commit is contained in:
Anthony Louis committed 2021-04-09 19:34:23 -03:00
1 parent 61122220b4
commit 2339345be3
2 files changed
+97 -30

No files matched your search

+89 -30
View File
@@ -155,36 +155,36 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
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.
@@ -208,7 +208,7 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr, int8_t* data_ptr,
// Expand inner macro for all numeric types.
#define SHA_VAR_LEN_PARAMS(INNER) \
INNER(utf8) \
INNER(utf8) \
INNER(binary)
@@ -221,6 +221,36 @@ SHA_VAR_LEN_PARAMS(SHA128_HASH_FUNCTION_BUF)
#undef SHA_NUMERIC_BOOL_DATE_PARAMS
#undef SHA_VAR_LEN_PARAMS
// Add functions for decimal128
GANDIVA_EXPORT
const char* gdv_fn_sha256_from_decimal128(int64_t context, int64_t x_high, uint64_t x_low,
int32_t x_precision, int32_t x_scale,
gdv_boolean x_isvalid, u_int32_t *out_length) {
if(!x_isvalid){
*out_length = 0;
return "";
}
const auto &decimal_128 = gandiva::BasicDecimal128(x_high, x_low);
return gandiva::HashUtils::HashUsingSha256(context, decimal_128.ToBytes().data(),
16, out_length);
}
GANDIVA_EXPORT
const char* gdv_fn_sha128_from_decimal128(int64_t context, int64_t x_high, uint64_t x_low,
int32_t x_precision, int32_t x_scale,
gdv_boolean x_isvalid, u_int32_t *out_length) {
if(!x_isvalid){
*out_length = 0;
return "";
}
const auto &decimal_128 = gandiva::BasicDecimal128(x_high, x_low);
return gandiva::HashUtils::HashUsingSha128(context, decimal_128.ToBytes().data(),
16, out_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,
int64_t* dec_high_from_str, uint64_t* dec_low_from_str) {
@@ -823,5 +853,34 @@ 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));
// gdv_fn_sha128_from_decimal128
args = {
types->i64_type(), // context
types->i64_type(), // high_bits
types->i64_type(), // low_bits
types->i32_type(), // precision
types->i32_type(), // scale
types->i1_type(), // validity
types->i32_ptr_type() // out length
};
engine->AddGlobalMappingForFunc("gdv_fn_sha128_from_decimal128",
types->i8_ptr_type() /*return_type*/, args,
reinterpret_cast<void *>(gdv_fn_sha128_from_decimal128));
// gdv_fn_sha256_from_decimal128
args = {
types->i64_type(), // context
types->i64_type(), // high_bits
types->i64_type(), // low_bits
types->i32_type(), // precision
types->i32_type(), // scale
types->i1_type(), // validity
types->i32_ptr_type() // out length
};
engine->AddGlobalMappingForFunc("gdv_fn_sha256_from_decimal128",
types->i8_ptr_type() /*return_type*/, args,
reinterpret_cast<void *>(gdv_fn_sha256_from_decimal128));
}
} // namespace gandiva
+8
View File
@@ -85,6 +85,14 @@ const char *gdv_fn_sha128_from_utf8(int64_t context,
bool value_validity,
uint32_t *out_length);
const char* gdv_fn_sha256_from_decimal128(int64_t context, int64_t x_high, uint64_t x_low,
int32_t x_precision, int32_t x_scale,
gdv_boolean x_isvalid, uint32_t *out_length);
const char* gdv_fn_sha128_from_decimal128(int64_t context, int64_t x_high, uint64_t x_low,
int32_t x_precision, int32_t x_scale,
gdv_boolean x_isvalid, uint32_t *out_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,
int64_t* dec_high_from_str, uint64_t* dec_low_from_str);