You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2022/05/25 19:52:52 UTC

[arrow] branch master updated: ARROW-16647: [C++] Add support for unique(), value_counts(), dictionary_encode() with interval types

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

lidavidm 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 05a82b677d ARROW-16647: [C++] Add support for unique(), value_counts(), dictionary_encode() with interval types
05a82b677d is described below

commit 05a82b677d77946bb298d060b578b4c6af5c25fc
Author: okadakk <k....@gmail.com>
AuthorDate: Wed May 25 15:52:43 2022 -0400

    ARROW-16647: [C++] Add support for unique(), value_counts(), dictionary_encode() with interval types
    
    Add support for unique(), value_counts(), dictionary_encode() with interval types.
    
    Closes #13231 from okadakk/add-support-unique-valuecounts-dictencode-with-interval-types
    
    Authored-by: okadakk <k....@gmail.com>
    Signed-off-by: David Li <li...@gmail.com>
---
 cpp/src/arrow/compute/kernels/vector_hash.cc      | 10 ++++++
 cpp/src/arrow/compute/kernels/vector_hash_test.cc | 44 +++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/cpp/src/arrow/compute/kernels/vector_hash.cc b/cpp/src/arrow/compute/kernels/vector_hash.cc
index fccd73e399..bb3572e9eb 100644
--- a/cpp/src/arrow/compute/kernels/vector_hash.cc
+++ b/cpp/src/arrow/compute/kernels/vector_hash.cc
@@ -555,6 +555,7 @@ KernelInit GetHashInit(Type::type type_id) {
     case Type::FLOAT:
     case Type::DATE32:
     case Type::TIME32:
+    case Type::INTERVAL_MONTHS:
       return HashInit<UInt32Type, Action>;
     case Type::INT64:
     case Type::UINT64:
@@ -563,6 +564,7 @@ KernelInit GetHashInit(Type::type type_id) {
     case Type::TIME64:
     case Type::TIMESTAMP:
     case Type::DURATION:
+    case Type::INTERVAL_DAY_TIME:
       return HashInit<UInt64Type, Action>;
     case Type::BINARY:
     case Type::STRING:
@@ -574,6 +576,8 @@ KernelInit GetHashInit(Type::type type_id) {
     case Type::DECIMAL128:
     case Type::DECIMAL256:
       return HashInit<FixedSizeBinaryType, Action>;
+    case Type::INTERVAL_MONTH_DAY_NANO:
+      return HashInit<MonthDayNanoIntervalType, Action>;
     default:
       DCHECK(false);
       return nullptr;
@@ -723,6 +727,12 @@ void AddHashKernels(VectorFunction* func, VectorKernel base, OutputType out_ty)
     base.signature = KernelSignature::Make({InputType::Array(t)}, out_ty);
     DCHECK_OK(func->AddKernel(base));
   }
+
+  for (const auto& ty : IntervalTypes()) {
+    base.init = GetHashInit<Action>(ty->id());
+    base.signature = KernelSignature::Make({InputType::Array(ty)}, out_ty);
+    DCHECK_OK(func->AddKernel(base));
+  }
 }
 
 const FunctionDoc unique_doc(
diff --git a/cpp/src/arrow/compute/kernels/vector_hash_test.cc b/cpp/src/arrow/compute/kernels/vector_hash_test.cc
index 868bac1f4a..ec45239f9c 100644
--- a/cpp/src/arrow/compute/kernels/vector_hash_test.cc
+++ b/cpp/src/arrow/compute/kernels/vector_hash_test.cc
@@ -638,6 +638,50 @@ TEST_F(TestHashKernel, DictEncodeDecimal) {
                                               {}, {0, 0, 1, 0, 2});
 }
 
+TEST_F(TestHashKernel, UniqueIntervalMonth) {
+  CheckUnique<MonthIntervalType, int32_t>(month_interval(), {2, 1, 2, 1},
+                                          {true, false, true, true}, {2, 0, 1},
+                                          {true, false, true});
+
+  CheckUnique<DayTimeIntervalType, DayTimeIntervalType::DayMilliseconds>(
+      day_time_interval(), {{2, 1}, {3, 2}, {2, 1}, {1, 2}}, {true, false, true, true},
+      {{2, 1}, {1, 1}, {1, 2}}, {true, false, true});
+
+  CheckUnique<MonthDayNanoIntervalType, MonthDayNanoIntervalType::MonthDayNanos>(
+      month_day_nano_interval(), {{2, 1, 1}, {3, 2, 1}, {2, 1, 1}, {1, 2, 1}},
+      {true, false, true, true}, {{2, 1, 1}, {1, 1, 1}, {1, 2, 1}}, {true, false, true});
+}
+
+TEST_F(TestHashKernel, ValueCountsIntervalMonth) {
+  CheckValueCounts<MonthIntervalType, int32_t>(month_interval(), {2, 1, 2, 1},
+                                               {true, false, true, true}, {2, 0, 1},
+                                               {true, false, true}, {2, 1, 1});
+
+  CheckValueCounts<DayTimeIntervalType, DayTimeIntervalType::DayMilliseconds>(
+      day_time_interval(), {{2, 1}, {3, 2}, {2, 1}, {1, 2}}, {true, false, true, true},
+      {{2, 1}, {1, 1}, {1, 2}}, {true, false, true}, {2, 1, 1});
+
+  CheckValueCounts<MonthDayNanoIntervalType, MonthDayNanoIntervalType::MonthDayNanos>(
+      month_day_nano_interval(), {{2, 1, 1}, {3, 2, 1}, {2, 1, 1}, {1, 2, 1}},
+      {true, false, true, true}, {{2, 1, 1}, {1, 1, 1}, {1, 2, 1}}, {true, false, true},
+      {2, 1, 1});
+}
+
+TEST_F(TestHashKernel, DictEncodeIntervalMonth) {
+  CheckDictEncode<MonthIntervalType, int32_t>(month_interval(), {2, 2, 1, 2, 3},
+                                              {true, false, true, true, true}, {2, 1, 3},
+                                              {}, {0, 0, 1, 0, 2});
+
+  CheckDictEncode<DayTimeIntervalType, DayTimeIntervalType::DayMilliseconds>(
+      day_time_interval(), {{2, 1}, {2, 1}, {3, 2}, {2, 1}, {1, 2}},
+      {true, false, true, true, true}, {{2, 1}, {3, 2}, {1, 2}}, {}, {0, 0, 1, 0, 2});
+
+  CheckDictEncode<MonthDayNanoIntervalType, MonthDayNanoIntervalType::MonthDayNanos>(
+      month_day_nano_interval(), {{2, 1, 1}, {2, 1, 1}, {3, 2, 1}, {2, 1, 1}, {1, 2, 1}},
+      {true, false, true, true, true}, {{2, 1, 1}, {3, 2, 1}, {1, 2, 1}}, {},
+      {0, 0, 1, 0, 2});
+}
+
 TEST_F(TestHashKernel, DictionaryUniqueAndValueCounts) {
   auto dict_json = "[10, 20, 30, 40]";
   auto dict = ArrayFromJSON(int64(), dict_json);