You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/06/17 16:52:44 UTC

[arrow] branch master updated: ARROW-5580: [C++][Gandiva] Support timestamp functions

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 73ceae4  ARROW-5580: [C++][Gandiva] Support timestamp functions
73ceae4 is described below

commit 73ceae41174f70ed40f5dc5b5365e112727f1567
Author: Prudhvi Porandla <pr...@icloud.com>
AuthorDate: Mon Jun 17 11:52:37 2019 -0500

    ARROW-5580: [C++][Gandiva] Support timestamp functions
    
    Match signatures of Gandiva timestamp functions with arrow
    
    Author: Prudhvi Porandla <pr...@icloud.com>
    Author: prudhvi <pr...@dremio.com>
    
    Closes #4539 from pprudhvi/timestampGandivaFixes and squashes the following commits:
    
    6d7927946 <Prudhvi Porandla> remove unnecessary whitespaces in code
    5062f7065 <Prudhvi Porandla> add spaces
    4d43ba2db <Prudhvi Porandla>   Timestamp arithmetic - Correct function definitions in Gandiva
    c2795e7eb <prudhvi> timestamp_arith: change method signatures in types.h, fix unit tests
    59f5d00c3 <prudhvi> make gandiva timestamp arithmetic compatible with arrow/java
---
 .../function_registry_timestamp_arithmetic.cc      | 16 ++++----
 cpp/src/gandiva/precompiled/time_test.cc           | 34 ++++++++--------
 .../gandiva/precompiled/timestamp_arithmetic.cc    | 12 +++---
 cpp/src/gandiva/precompiled/types.h                | 46 +++++++++++-----------
 4 files changed, 54 insertions(+), 54 deletions(-)

diff --git a/cpp/src/gandiva/function_registry_timestamp_arithmetic.cc b/cpp/src/gandiva/function_registry_timestamp_arithmetic.cc
index 7af7690..7587212 100644
--- a/cpp/src/gandiva/function_registry_timestamp_arithmetic.cc
+++ b/cpp/src/gandiva/function_registry_timestamp_arithmetic.cc
@@ -21,10 +21,10 @@
 namespace gandiva {
 
 #define TIMESTAMP_ADD_FNS(name)                                            \
-  BINARY_GENERIC_SAFE_NULL_IF_NULL(name, timestamp, int32, timestamp),     \
-      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, date64, int32, date64),       \
-      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, timestamp, int64, timestamp), \
-      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, date64, int64, date64)
+  BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int32, timestamp, timestamp),     \
+      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int32, date64, date64),       \
+      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int64, timestamp, timestamp), \
+      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int64, date64, date64)
 
 #define TIMESTAMP_DIFF_FN(name) \
   BINARY_GENERIC_SAFE_NULL_IF_NULL(name, timestamp, timestamp, int32)
@@ -40,10 +40,10 @@ namespace gandiva {
       BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int64, timestamp, timestamp)
 
 #define DATE_DIFF_FNS(name)                                             \
-  BINARY_GENERIC_SAFE_NULL_IF_NULL(name, date64, int32, date64),        \
-      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, timestamp, int32, date64), \
-      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, date64, int64, date64),    \
-      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, timestamp, int64, date64)
+  BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int32, date64, date64),        \
+      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int32, timestamp, date64), \
+      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int64, date64, date64),    \
+      BINARY_GENERIC_SAFE_NULL_IF_NULL(name, int64, timestamp, date64)
 
 std::vector<NativeFunction> GetDateTimeArithmeticFunctionRegistry() {
   static std::vector<NativeFunction> datetime_fn_registry_ = {
diff --git a/cpp/src/gandiva/precompiled/time_test.cc b/cpp/src/gandiva/precompiled/time_test.cc
index aaadf0f..66c48e3 100644
--- a/cpp/src/gandiva/precompiled/time_test.cc
+++ b/cpp/src/gandiva/precompiled/time_test.cc
@@ -219,50 +219,50 @@ TEST(TestTime, TimeStampTrunc) {
 
 TEST(TestTime, TimeStampAdd) {
   EXPECT_EQ(
-      timestampaddSecond_timestamp_int32(StringToTimestamp("2000-05-01 10:20:34"), 30),
+      timestampaddSecond_int32_timestamp(30, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("2000-05-01 10:21:04"));
 
   EXPECT_EQ(
-      timestampaddMinute_timestamp_int64(StringToTimestamp("2000-05-01 10:20:34"), -30),
+      timestampaddMinute_int64_timestamp(-30, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("2000-05-01 09:50:34"));
 
   EXPECT_EQ(
-      timestampaddHour_timestamp_int32(StringToTimestamp("2000-05-01 10:20:34"), 20),
+      timestampaddHour_int32_timestamp(20, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("2000-05-02 06:20:34"));
 
   EXPECT_EQ(
-      timestampaddDay_timestamp_int64(StringToTimestamp("2000-05-01 10:20:34"), -35),
+      timestampaddDay_int64_timestamp(-35, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("2000-03-27 10:20:34"));
 
-  EXPECT_EQ(timestampaddWeek_timestamp_int32(StringToTimestamp("2000-05-01 10:20:34"), 4),
+  EXPECT_EQ(timestampaddWeek_int32_timestamp(4, StringToTimestamp("2000-05-01 10:20:34")),
             StringToTimestamp("2000-05-29 10:20:34"));
 
   EXPECT_EQ(
-      timestampaddMonth_timestamp_int64(StringToTimestamp("2000-05-01 10:20:34"), 10),
+      timestampaddMonth_int64_timestamp(10, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("2001-03-01 10:20:34"));
 
   EXPECT_EQ(
-      timestampaddQuarter_timestamp_int32(StringToTimestamp("2000-05-01 10:20:34"), -2),
+      timestampaddQuarter_int32_timestamp(-2, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("1999-11-01 10:20:34"));
 
-  EXPECT_EQ(timestampaddYear_timestamp_int64(StringToTimestamp("2000-05-01 10:20:34"), 2),
+  EXPECT_EQ(timestampaddYear_int64_timestamp(2, StringToTimestamp("2000-05-01 10:20:34")),
             StringToTimestamp("2002-05-01 10:20:34"));
 
   EXPECT_EQ(
-      timestampaddQuarter_timestamp_int32(StringToTimestamp("2000-05-01 10:20:34"), -5),
+      timestampaddQuarter_int32_timestamp(-5, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("1999-02-01 10:20:34"));
   EXPECT_EQ(
-      timestampaddQuarter_timestamp_int32(StringToTimestamp("2000-05-01 10:20:34"), -6),
+      timestampaddQuarter_int32_timestamp(-6, StringToTimestamp("2000-05-01 10:20:34")),
       StringToTimestamp("1998-11-01 10:20:34"));
 
   // date_add
-  EXPECT_EQ(date_add_timestamp_int32(StringToTimestamp("2000-05-01 00:00:00"), 7),
+  EXPECT_EQ(date_add_int32_timestamp(7, StringToTimestamp("2000-05-01 00:00:00")),
             StringToTimestamp("2000-05-08 00:00:00"));
 
   EXPECT_EQ(add_int32_timestamp(4, StringToTimestamp("2000-05-01 00:00:00")),
             StringToTimestamp("2000-05-05 00:00:00"));
 
-  EXPECT_EQ(add_timestamp_int64(StringToTimestamp("2000-05-01 00:00:00"), 7),
+  EXPECT_EQ(add_int64_timestamp(7, StringToTimestamp("2000-05-01 00:00:00")),
             StringToTimestamp("2000-05-08 00:00:00"));
 
   EXPECT_EQ(date_add_int64_timestamp(4, StringToTimestamp("2000-05-01 00:00:00")),
@@ -272,19 +272,19 @@ TEST(TestTime, TimeStampAdd) {
             StringToTimestamp("2000-03-02 00:00:00"));
 
   // date_sub
-  EXPECT_EQ(date_sub_timestamp_int32(StringToTimestamp("2000-05-01 00:00:00"), 7),
+  EXPECT_EQ(date_sub_int32_timestamp(7, StringToTimestamp("2000-05-01 00:00:00")),
             StringToTimestamp("2000-04-24 00:00:00"));
 
-  EXPECT_EQ(subtract_timestamp_int32(StringToTimestamp("2000-05-01 00:00:00"), -7),
+  EXPECT_EQ(subtract_int32_timestamp(-7, StringToTimestamp("2000-05-01 00:00:00")),
             StringToTimestamp("2000-05-08 00:00:00"));
 
-  EXPECT_EQ(date_diff_timestamp_int64(StringToTimestamp("2000-05-01 00:00:00"), 365),
+  EXPECT_EQ(date_diff_int64_timestamp(365, StringToTimestamp("2000-05-01 00:00:00")),
             StringToTimestamp("1999-05-02 00:00:00"));
 
-  EXPECT_EQ(date_diff_timestamp_int64(StringToTimestamp("2000-03-01 00:00:00"), 1),
+  EXPECT_EQ(date_diff_int64_timestamp(1, StringToTimestamp("2000-03-01 00:00:00")),
             StringToTimestamp("2000-02-29 00:00:00"));
 
-  EXPECT_EQ(date_diff_timestamp_int64(StringToTimestamp("2000-02-29 00:00:00"), 365),
+  EXPECT_EQ(date_diff_int64_timestamp(365, StringToTimestamp("2000-02-29 00:00:00")),
             StringToTimestamp("1999-03-01 00:00:00"));
 }
 
diff --git a/cpp/src/gandiva/precompiled/timestamp_arithmetic.cc b/cpp/src/gandiva/precompiled/timestamp_arithmetic.cc
index fa50637..af4e2db 100644
--- a/cpp/src/gandiva/precompiled/timestamp_arithmetic.cc
+++ b/cpp/src/gandiva/precompiled/timestamp_arithmetic.cc
@@ -98,7 +98,7 @@ TIMESTAMP_DIFF(timestamp)
 
 #define ADD_INT32_TO_TIMESTAMP_FIXED_UNITS(TYPE, NAME, TO_MILLIS) \
   FORCE_INLINE                                                    \
-  TYPE NAME##_##TYPE##_int32(TYPE millis, int32 count) {          \
+  TYPE NAME##_int32_##TYPE(int32 count, TYPE millis) {            \
     return millis + TO_MILLIS * static_cast<TYPE>(count);         \
   }
 
@@ -110,7 +110,7 @@ TIMESTAMP_DIFF(timestamp)
 // since the input millis are since epoch
 #define ADD_INT32_TO_TIMESTAMP_MONTH_UNITS(TYPE, NAME, N_MONTHS)                \
   FORCE_INLINE                                                                  \
-  TYPE NAME##_##TYPE##_int32(TYPE millis, int32 count) {                        \
+  TYPE NAME##_int32_##TYPE(int32 count, TYPE millis) {                          \
     EpochTimePoint tp(millis);                                                  \
     return tp.AddMonths(static_cast<int>(count * N_MONTHS)).MillisSinceEpoch(); \
   }
@@ -118,13 +118,13 @@ TIMESTAMP_DIFF(timestamp)
 // TODO: Handle overflow while converting int64 to millis
 #define ADD_INT64_TO_TIMESTAMP_FIXED_UNITS(TYPE, NAME, TO_MILLIS) \
   FORCE_INLINE                                                    \
-  TYPE NAME##_##TYPE##_int64(TYPE millis, int64 count) {          \
+  TYPE NAME##_int64_##TYPE(int64 count, TYPE millis) {            \
     return millis + TO_MILLIS * static_cast<TYPE>(count);         \
   }
 
 #define ADD_INT64_TO_TIMESTAMP_MONTH_UNITS(TYPE, NAME, N_MONTHS)                \
   FORCE_INLINE                                                                  \
-  TYPE NAME##_##TYPE##_int64(TYPE millis, int64 count) {                        \
+  TYPE NAME##_int64_##TYPE(int64 count, TYPE millis) {                          \
     EpochTimePoint tp(millis);                                                  \
     return tp.AddMonths(static_cast<int>(count * N_MONTHS)).MillisSinceEpoch(); \
   }
@@ -186,13 +186,13 @@ ADD_INT64_TO_TIMESTAMP_FIXED_UNITS(timestamp, date_diff, -1 * MILLIS_IN_DAY)
 
 #define ADD_TIMESTAMP_TO_INT32_FIXED_UNITS(TYPE, NAME, TO_MILLIS) \
   FORCE_INLINE                                                    \
-  TYPE NAME##_int32_##TYPE(int32 count, TYPE millis) {            \
+  TYPE NAME##_##TYPE##_int32(TYPE millis, int32 count) {          \
     return millis + TO_MILLIS * (TYPE)count;                      \
   }
 
 #define ADD_TIMESTAMP_TO_INT64_FIXED_UNITS(TYPE, NAME, TO_MILLIS) \
   FORCE_INLINE                                                    \
-  TYPE NAME##_int64_##TYPE(int64 count, TYPE millis) {            \
+  TYPE NAME##_##TYPE##_int64(TYPE millis, int64 count) {          \
     return millis + TO_MILLIS * (TYPE)count;                      \
   }
 
diff --git a/cpp/src/gandiva/precompiled/types.h b/cpp/src/gandiva/precompiled/types.h
index 7f3b0a0..493a3ae 100644
--- a/cpp/src/gandiva/precompiled/types.h
+++ b/cpp/src/gandiva/precompiled/types.h
@@ -74,32 +74,32 @@ int32 hash32_buf(const uint8* buf, int len, int32 seed);
 int64 hash64(double val, int64 seed);
 int64 hash64_buf(const uint8* buf, int len, int64 seed);
 
-int64 timestampaddSecond_timestamp_int32(timestamp, int32);
-int64 timestampaddMinute_timestamp_int32(timestamp, int32);
-int64 timestampaddHour_timestamp_int32(timestamp, int32);
-int64 timestampaddDay_timestamp_int32(timestamp, int32);
-int64 timestampaddWeek_timestamp_int32(timestamp, int32);
-int64 timestampaddMonth_timestamp_int32(timestamp, int32);
-int64 timestampaddQuarter_timestamp_int32(timestamp, int32);
-int64 timestampaddYear_timestamp_int32(timestamp, int32);
-
-int64 timestampaddSecond_timestamp_int64(timestamp, int64);
-int64 timestampaddMinute_timestamp_int64(timestamp, int64);
-int64 timestampaddHour_timestamp_int64(timestamp, int64);
-int64 timestampaddDay_timestamp_int64(timestamp, int64);
-int64 timestampaddWeek_timestamp_int64(timestamp, int64);
-int64 timestampaddMonth_timestamp_int64(timestamp, int64);
-int64 timestampaddQuarter_timestamp_int64(timestamp, int64);
-int64 timestampaddYear_timestamp_int64(timestamp, int64);
-
-int64 date_add_timestamp_int32(timestamp, int32);
-int64 add_timestamp_int64(timestamp, int64);
+int64 timestampaddSecond_int32_timestamp(int32, timestamp);
+int64 timestampaddMinute_int32_timestamp(int32, timestamp);
+int64 timestampaddHour_int32_timestamp(int32, timestamp);
+int64 timestampaddDay_int32_timestamp(int32, timestamp);
+int64 timestampaddWeek_int32_timestamp(int32, timestamp);
+int64 timestampaddMonth_int32_timestamp(int32, timestamp);
+int64 timestampaddQuarter_int32_timestamp(int32, timestamp);
+int64 timestampaddYear_int32_timestamp(int32, timestamp);
+
+int64 timestampaddSecond_int64_timestamp(int64, timestamp);
+int64 timestampaddMinute_int64_timestamp(int64, timestamp);
+int64 timestampaddHour_int64_timestamp(int64, timestamp);
+int64 timestampaddDay_int64_timestamp(int64, timestamp);
+int64 timestampaddWeek_int64_timestamp(int64, timestamp);
+int64 timestampaddMonth_int64_timestamp(int64, timestamp);
+int64 timestampaddQuarter_int64_timestamp(int64, timestamp);
+int64 timestampaddYear_int64_timestamp(int64, timestamp);
+
+int64 date_add_int32_timestamp(int32, timestamp);
+int64 add_int64_timestamp(int64, timestamp);
 int64 add_int32_timestamp(int32, timestamp);
 int64 date_add_int64_timestamp(int64, timestamp);
 
-int64 date_sub_timestamp_int32(timestamp, int32);
-int64 subtract_timestamp_int32(timestamp, int32);
-int64 date_diff_timestamp_int64(timestamp, int64);
+int64 date_sub_int32_timestamp(int32, timestamp);
+int64 subtract_int32_timestamp(int32, timestamp);
+int64 date_diff_int64_timestamp(int64, timestamp);
 
 bool is_distinct_from_timestamp_timestamp(int64, bool, int64, bool);
 bool is_not_distinct_from_int32_int32(int32, bool, int32, bool);