Skip to content

Commit c960fb5

Browse files
ARROW-15661: [Gandiva][C++] Add SHA512 function (apache#12404)
This PR was created to implement SHA512 functions in Gandiva side. This PR implements the follow signatures: FunctionSignature{name =hashSHA512, return type =String, param types =[int8]} FunctionSignature{name =hashSHA512, return type =String, param types =[int16]} FunctionSignature{name =hashSHA512, return type =String, param types =[int32]} FunctionSignature{name =hashSHA512, return type =String, param types =[int64]} FunctionSignature{name =hashSHA512, return type =String, param types =[uint8]} FunctionSignature{name =hashSHA512, return type =String, param types =[uint16]} FunctionSignature{name =hashSHA512, return type =String, param types =[uint32]} FunctionSignature{name =hashSHA512, return type =String, param types =[uint64]} FunctionSignature{name =hashSHA512, return type =String, param types =[float]} FunctionSignature{name =hashSHA512, return type =String, param types =[double]} FunctionSignature{name =hashSHA512, return type =String, param types =[boolean]} FunctionSignature{name =hashSHA512, return type =String, param types =[date64]} FunctionSignature{name =hashSHA512, return type =String, param types =[date32]} FunctionSignature{name =hashSHA512, return type =String, param types =[time32]} FunctionSignature{name =hashSHA512, return type =String, param types =[timestamp]} FunctionSignature{name =hashSHA512, return type =String, param types =[string]} Authored-by: Johnnathan <johnnathanalmeida@gmail.com> Signed-off-by: Pindikura Ravindra <ravindra@dremio.com>
1 parent 461b3b9 commit c960fb5

9 files changed

Lines changed: 723 additions & 1 deletion

cpp/src/gandiva/function_registry_common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ typedef std::unordered_map<const FunctionSignature*, const NativeFunction*, KeyH
235235
kResultNullNever, ARROW_STRINGIFY(gdv_fn_sha1_##TYPE), \
236236
NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors)
237237

238+
// HashSHA512 functions that :
239+
// - NULL handling is of type NULL_NEVER
240+
// - can return errors
241+
//
242+
// The function name includes the base name & input type name. gdv_fn_sha512_float64
243+
#define HASH_SHA512_NULL_NEVER(NAME, ALIASES, TYPE) \
244+
NativeFunction(#NAME, {"sha512"}, DataTypeVector{TYPE()}, utf8(), kResultNullNever, \
245+
ARROW_STRINGIFY(gdv_fn_sha512_##TYPE), \
246+
NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors)
247+
238248
// HashSHA256 functions that :
239249
// - NULL handling is of type NULL_NEVER
240250
// - can return errors

cpp/src/gandiva/function_registry_hash.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ namespace gandiva {
3838
#define HASH_SHA256_NULL_NEVER_FN(name, ALIASES) \
3939
NUMERIC_BOOL_DATE_VAR_LEN_TYPES(HASH_SHA256_NULL_NEVER, name, ALIASES)
4040

41+
#define HASH_SHA512_NULL_NEVER_FN(name, ALIASES) \
42+
NUMERIC_BOOL_DATE_VAR_LEN_TYPES(HASH_SHA512_NULL_NEVER, name, ALIASES)
43+
4144
#define HASH_MD5_NULL_NEVER_FN(name, ALIASES) \
4245
NUMERIC_BOOL_DATE_VAR_LEN_TYPES(HASH_MD5_NULL_NEVER, name, ALIASES)
4346

@@ -60,6 +63,8 @@ std::vector<NativeFunction> GetHashFunctionRegistry() {
6063

6164
HASH_SHA256_NULL_NEVER_FN(hashSHA256, {}),
6265

66+
HASH_SHA512_NULL_NEVER_FN(hashSHA512, {}),
67+
6368
HASH_MD5_NULL_NEVER_FN(hashMD5, {})};
6469

6570
return hash_fn_registry_;

cpp/src/gandiva/gdv_function_stubs.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "arrow/util/base64.h"
2727
#include "arrow/util/bit_util.h"
2828
#include "arrow/util/double_conversion.h"
29-
#include "arrow/util/string_view.h"
3029
#include "arrow/util/value_parsing.h"
3130

3231
#include "gandiva/encrypt_utils.h"

cpp/src/gandiva/gdv_function_stubs.h

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ GANDIVA_EXPORT
105105
const char* gdv_fn_castVARBINARY_int64_int64(int64_t context, gdv_int64 value,
106106
int64_t out_len, int32_t* out_length);
107107

108+
GANDIVA_EXPORT
109+
const char* gdv_fn_sha512_decimal128(int64_t context, int64_t x_high, uint64_t x_low,
110+
int32_t x_precision, int32_t x_scale,
111+
gdv_boolean x_isvalid, int32_t* out_length);
112+
108113
GANDIVA_EXPORT
109114
const char* gdv_fn_sha256_decimal128(int64_t context, int64_t x_high, uint64_t x_low,
110115
int32_t x_precision, int32_t x_scale,
@@ -200,4 +205,132 @@ GANDIVA_EXPORT
200205
const char* gdv_mask_last_n_utf8_int32(int64_t context, const char* data,
201206
int32_t data_len, int32_t n_to_mask,
202207
int32_t* out_len);
208+
209+
GANDIVA_EXPORT
210+
const char* gdv_fn_sha512_int8(int64_t context, gdv_int8 value, bool validity,
211+
int32_t* out_length);
212+
213+
GANDIVA_EXPORT
214+
const char* gdv_fn_sha512_int16(int64_t context, gdv_int16 value, bool validity,
215+
int32_t* out_length);
216+
217+
GANDIVA_EXPORT
218+
const char* gdv_fn_sha512_int32(int64_t context, gdv_int32 value, bool validity,
219+
int32_t* out_length);
220+
221+
GANDIVA_EXPORT
222+
const char* gdv_fn_sha512_int64(int64_t context, gdv_int64 value, bool validity,
223+
int32_t* out_length);
224+
225+
GANDIVA_EXPORT
226+
const char* gdv_fn_sha512_uint8(int64_t context, gdv_uint8 value, bool validity,
227+
int32_t* out_length);
228+
229+
GANDIVA_EXPORT
230+
const char* gdv_fn_sha512_uint16(int64_t context, gdv_uint16 value, bool validity,
231+
int32_t* out_length);
232+
233+
GANDIVA_EXPORT
234+
const char* gdv_fn_sha512_uint32(int64_t context, gdv_uint32 value, bool validity,
235+
int32_t* out_length);
236+
237+
GANDIVA_EXPORT
238+
const char* gdv_fn_sha512_uint64(int64_t context, gdv_uint64 value, bool validity,
239+
int32_t* out_length);
240+
241+
GANDIVA_EXPORT
242+
const char* gdv_fn_sha512_float32(int64_t context, gdv_float32 value, bool validity,
243+
int32_t* out_length);
244+
245+
GANDIVA_EXPORT
246+
const char* gdv_fn_sha512_float64(int64_t context, gdv_float64 value, bool validity,
247+
int32_t* out_length);
248+
249+
GANDIVA_EXPORT
250+
const char* gdv_fn_sha512_boolean(int64_t context, gdv_boolean value, bool validity,
251+
int32_t* out_length);
252+
253+
GANDIVA_EXPORT
254+
const char* gdv_fn_sha512_date64(int64_t context, gdv_date64 value, bool validity,
255+
int32_t* out_length);
256+
257+
GANDIVA_EXPORT
258+
const char* gdv_fn_sha512_date32(int64_t context, gdv_date32 value, bool validity,
259+
int32_t* out_length);
260+
261+
GANDIVA_EXPORT
262+
const char* gdv_fn_sha512_time32(int64_t context, gdv_time32 value, bool validity,
263+
int32_t* out_length);
264+
265+
GANDIVA_EXPORT
266+
const char* gdv_fn_sha512_timestamp(int64_t context, gdv_timestamp value, bool validity,
267+
int32_t* out_length);
268+
269+
GANDIVA_EXPORT
270+
const char* gdv_fn_sha512_utf8(int64_t context, gdv_utf8 value, int32_t value_length,
271+
bool value_validity, int32_t* out_length);
272+
273+
GANDIVA_EXPORT
274+
const char* gdv_fn_sha256_int8(int64_t context, gdv_int8 value, bool validity,
275+
int32_t* out_length);
276+
277+
GANDIVA_EXPORT
278+
const char* gdv_fn_sha256_int16(int64_t context, gdv_int16 value, bool validity,
279+
int32_t* out_length);
280+
281+
GANDIVA_EXPORT
282+
const char* gdv_fn_sha256_int32(int64_t context, gdv_int32 value, bool validity,
283+
int32_t* out_length);
284+
285+
GANDIVA_EXPORT
286+
const char* gdv_fn_sha256_int64(int64_t context, gdv_int64 value, bool validity,
287+
int32_t* out_length);
288+
289+
GANDIVA_EXPORT
290+
const char* gdv_fn_sha256_uint8(int64_t context, gdv_uint8 value, bool validity,
291+
int32_t* out_length);
292+
293+
GANDIVA_EXPORT
294+
const char* gdv_fn_sha256_uint16(int64_t context, gdv_uint16 value, bool validity,
295+
int32_t* out_length);
296+
297+
GANDIVA_EXPORT
298+
const char* gdv_fn_sha256_uint32(int64_t context, gdv_uint32 value, bool validity,
299+
int32_t* out_length);
300+
301+
GANDIVA_EXPORT
302+
const char* gdv_fn_sha256_uint64(int64_t context, gdv_uint64 value, bool validity,
303+
int32_t* out_length);
304+
305+
GANDIVA_EXPORT
306+
const char* gdv_fn_sha256_float32(int64_t context, gdv_float32 value, bool validity,
307+
int32_t* out_length);
308+
309+
GANDIVA_EXPORT
310+
const char* gdv_fn_sha256_float64(int64_t context, gdv_float64 value, bool validity,
311+
int32_t* out_length);
312+
313+
GANDIVA_EXPORT
314+
const char* gdv_fn_sha256_boolean(int64_t context, gdv_boolean value, bool validity,
315+
int32_t* out_length);
316+
317+
GANDIVA_EXPORT
318+
const char* gdv_fn_sha256_date64(int64_t context, gdv_date64 value, bool validity,
319+
int32_t* out_length);
320+
321+
GANDIVA_EXPORT
322+
const char* gdv_fn_sha256_date32(int64_t context, gdv_date32 value, bool validity,
323+
int32_t* out_length);
324+
325+
GANDIVA_EXPORT
326+
const char* gdv_fn_sha256_time32(int64_t context, gdv_time32 value, bool validity,
327+
int32_t* out_length);
328+
329+
GANDIVA_EXPORT
330+
const char* gdv_fn_sha256_timestamp(int64_t context, gdv_timestamp value, bool validity,
331+
int32_t* out_length);
332+
333+
GANDIVA_EXPORT
334+
const char* gdv_fn_sha256_utf8(int64_t context, gdv_utf8 value, int32_t value_length,
335+
bool value_validity, int32_t* out_length);
203336
}

0 commit comments

Comments
 (0)