ayushpranjal-dremio commented on code in PR #12306:
URL: https://github.com/apache/arrow/pull/12306#discussion_r869330723
##########
cpp/src/gandiva/gdv_function_stubs.cc:
##########
@@ -296,6 +296,215 @@ CAST_NUMERIC_FROM_VARBINARY(double, arrow::DoubleType,
FLOAT8)
#undef GDV_FN_CAST_VARCHAR_INTEGER
#undef GDV_FN_CAST_VARCHAR_REAL
+GDV_FORCE_INLINE
+int64_t unsigned_long_div(int64_t x, int32_t m) {
+ if (x >= 0) {
+ return x / m;
+ }
+ return x / m + 2 * (LONG_MAX / m) + 2 / m + (x % m + 2 * (LONG_MAX % m) + 2
% m) / m;
+}
+
+GDV_FORCE_INLINE
+int64_t encode(int32_t radix, int32_t fromPos, const char* value, int32_t
valueLen) {
Review Comment:
Add a comment on what this function is supposed to do. Also add unit tests
for helper functions.
##########
cpp/src/gandiva/gdv_function_stubs.cc:
##########
@@ -296,6 +296,215 @@ CAST_NUMERIC_FROM_VARBINARY(double, arrow::DoubleType,
FLOAT8)
#undef GDV_FN_CAST_VARCHAR_INTEGER
#undef GDV_FN_CAST_VARCHAR_REAL
+GDV_FORCE_INLINE
+int64_t unsigned_long_div(int64_t x, int32_t m) {
+ if (x >= 0) {
+ return x / m;
+ }
+ return x / m + 2 * (LONG_MAX / m) + 2 / m + (x % m + 2 * (LONG_MAX % m) + 2
% m) / m;
+}
+
+GDV_FORCE_INLINE
+int64_t encode(int32_t radix, int32_t fromPos, const char* value, int32_t
valueLen) {
+ int64_t val = 0;
+ int64_t bound = unsigned_long_div(-1 - radix, radix);
+
+ for (int i = fromPos; i < valueLen && value[i] >= 0; i++) {
+ if (val >= bound) {
+ if (unsigned_long_div(-1 - value[i], radix) < val) {
+ return -1;
+ }
+ }
+ val = val * radix + value[i];
+ }
+ return val;
+}
+
+GDV_FORCE_INLINE
+void decode(uint64_t val, int32_t radix, char* value, int32_t valueLen) {
Review Comment:
Add a comment on what this function is supposed to do. Also add unit tests
for helper functions.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]