anthonylouisbsb commented on a change in pull request #9707:
URL: https://github.com/apache/arrow/pull/9707#discussion_r597855417



##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -122,6 +123,133 @@ 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_##TYPE(int64_t context, gdv_##TYPE value,          
       \
+                                        bool validity, 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_##TYPE(int64_t context,                            
    \
+                                        gdv_##TYPE value,                      
    \
+                                        int32_t value_length,                  
    \
+                                        bool value_validity,                   
    \
+                                        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_##TYPE(int64_t context, gdv_##TYPE value,          
         \
+                                        bool validity, 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_##TYPE(int64_t context,                            
         \
+                                        gdv_##TYPE value,                      
         \
+                                        int32_t value_length,                  
         \
+                                        bool value_validity,                   
         \
+                                        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.
+#define SHA_NUMERIC_BOOL_DATE_PARAMS(INNER) \
+  INNER(int8)                          \
+  INNER(int16)                         \
+  INNER(int32)                         \
+  INNER(int64)                         \
+  INNER(uint8)                         \
+  INNER(uint16)                        \
+  INNER(uint32)                        \
+  INNER(uint64)                        \
+  INNER(float32)                       \
+  INNER(float64)                       \
+  INNER(boolean)                       \
+  INNER(date64)                        \
+  INNER(date32)                        \
+  INNER(time32)                        \
+  INNER(timestamp)
+
+
+// Expand inner macro for all numeric types.
+#define SHA_VAR_LEN_PARAMS(INNER) \
+  INNER(utf8)                     \
+  INNER(binary)
+
+
+SHA_NUMERIC_BOOL_DATE_PARAMS(SHA256_HASH_FUNCTION)
+SHA_VAR_LEN_PARAMS(SHA256_HASH_FUNCTION_BUF)
+
+SHA_NUMERIC_BOOL_DATE_PARAMS(SHA128_HASH_FUNCTION)
+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_decimal128(int64_t context, int64_t x_high, uint64_t 
x_low,
+                                     int32_t x_precision, int32_t x_scale,

Review comment:
       Suggestion applied




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to