projjal commented on a change in pull request #9861:
URL: https://github.com/apache/arrow/pull/9861#discussion_r609404186



##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -1246,6 +1246,69 @@ const char* convert_fromUTF8_binary(gdv_int64 context, 
const char* bin_in, gdv_i
   return ret;
 }
 
+#define CONVERT_TO_FN(TYPE)                                                    
          \
+  FORCE_INLINE                                                                 
          \
+  const char* convert_to##TYPE##_binary(gdv_int64 context, gdv_##TYPE value,   
          \
+                                        gdv_int32* out_len) {                  
          \
+    *out_len = sizeof(value);                                                  
          \
+    char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, 
*out_len)); \
+    if (ret == nullptr) {                                                      
          \
+      gdv_fn_context_set_error_msg(context,                                    
          \
+                                   "Could not allocate memory for output 
string");       \
+      *out_len = 0;                                                            
          \
+      return "";                                                               
          \
+    }                                                                          
          \
+    memcpy(ret, &value, *out_len);                                             
          \
+    return ret;                                                                
          \
+  }
+
+// Expand inner macro for all numeric types.
+#define NUMERIC_BOOL_DATE_TYPES(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)
+
+NUMERIC_BOOL_DATE_TYPES(CONVERT_TO_FN)
+
+#undef NUMERIC_BOOL_DATE_TYPES
+#undef CONVERT_TO_FN
+
+#define CONVERT_TO_FN_BUF_OP(TYPE)                                             
          \
+  FORCE_INLINE                                                                 
          \
+  const char* convert_to##TYPE##_binary(gdv_int64 context, const char* value,  
          \
+                                        gdv_int32 value_len, gdv_int32* 
out_len) {       \
+    *out_len = value_len;                                                      
          \
+    char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, 
*out_len)); \

Review comment:
       You can just return the original pointer and length instead of doing a 
malloc and memcpy

##########
File path: cpp/src/gandiva/precompiled/decimal_wrapper.cc
##########
@@ -430,4 +430,18 @@ char* castVARCHAR_decimal128_int64(int64_t context, 
int64_t x_high, uint64_t x_l
   return dec_str;
 }
 
+FORCE_INLINE
+const char* convert_todecimal128_binary(int64_t context, int64_t x_high, 
uint64_t x_low,
+                                        int32_t x_precision, int32_t x_scale,
+                                        int32_t* out_length) {
+  char* dec_str = gdv_fn_dec_to_string(context, x_high, x_low, x_scale, 
out_length);

Review comment:
       convert to binary and convert to string should be different. cast to 
string returns the string representation while convert to binary would return 
the 128 bytes

##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -1246,6 +1246,69 @@ const char* convert_fromUTF8_binary(gdv_int64 context, 
const char* bin_in, gdv_i
   return ret;
 }
 
+#define CONVERT_TO_FN(TYPE)                                                    
          \

Review comment:
       may can also add functions for bigendian outputs




-- 
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