diff --git a/cpp/src/arrow/compute/kernels/aggregate_test.cc b/cpp/src/arrow/compute/kernels/aggregate_test.cc index c8b13862ae3..c7cdf3fd91e 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_test.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_test.cc @@ -1384,8 +1384,6 @@ template class TestFloatingMinMaxKernel : public TestPrimitiveMinMaxKernel {}; class TestBooleanMinMaxKernel : public TestPrimitiveMinMaxKernel {}; -class TestDayTimeIntervalMinMaxKernel - : public TestPrimitiveMinMaxKernel {}; TEST_F(TestBooleanMinMaxKernel, Basics) { ScalarAggregateOptions options; diff --git a/cpp/src/arrow/compute/kernels/codegen_internal.h b/cpp/src/arrow/compute/kernels/codegen_internal.h index aa199f494da..a4914edbc8b 100644 --- a/cpp/src/arrow/compute/kernels/codegen_internal.h +++ b/cpp/src/arrow/compute/kernels/codegen_internal.h @@ -1225,6 +1225,8 @@ ArrayKernelExec GenerateTypeAgnosticPrimitive(detail::GetTypeId get_id) { case Type::DURATION: case Type::INTERVAL_DAY_TIME: return Generator::Exec; + case Type::INTERVAL_MONTH_DAY_NANO: + return Generator::Exec; default: DCHECK(false); return ExecFail; diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc b/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc index ef64974be72..c62ae83d39b 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc @@ -286,7 +286,8 @@ TEST(Grouper, SupportedKeys) { ASSERT_OK(internal::Grouper::Make({timestamp(unit), duration(unit)})); } - ASSERT_OK(internal::Grouper::Make({day_time_interval(), month_interval()})); + ASSERT_OK(internal::Grouper::Make( + {day_time_interval(), month_interval(), month_day_nano_interval()})); ASSERT_RAISES(NotImplemented, internal::Grouper::Make({struct_({field("", int64())})})); diff --git a/cpp/src/arrow/compute/kernels/scalar_if_else.cc b/cpp/src/arrow/compute/kernels/scalar_if_else.cc index 6195d1381a0..88bc7ca2e76 100644 --- a/cpp/src/arrow/compute/kernels/scalar_if_else.cc +++ b/cpp/src/arrow/compute/kernels/scalar_if_else.cc @@ -375,7 +375,9 @@ struct IfElseFunctor {}; // internal::GenerateTypeAgnosticPrimitive forwards types to the corresponding unsigned // int type template -struct IfElseFunctor> { +struct IfElseFunctor::value || + std::is_same::value>> { using T = typename TypeTraits::CType; // A - Array, S - Scalar, X = Array/Scalar @@ -1295,7 +1297,8 @@ struct CopyFixedWidth { }; template -struct CopyFixedWidth> { +struct CopyFixedWidth< + Type, enable_if_t::value || is_interval_type::value>> { using CType = typename TypeTraits::CType; static void CopyScalar(const Scalar& scalar, const int64_t length, uint8_t* raw_out_values, const int64_t out_offset) { diff --git a/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc b/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc index 7bcbb814ada..8c869ceef89 100644 --- a/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc @@ -345,6 +345,15 @@ TEST_F(TestIfElseKernel, DayTimeInterval) { ArrayFromJSON(ty, "[[1, 2], [3, -4], [-5, 6], [15, 16]]")); } +TEST_F(TestIfElseKernel, MonthDayNanoInterval) { + auto ty = month_day_nano_interval(); + CheckWithDifferentShapes( + ArrayFromJSON(boolean(), "[true, true, true, false]"), + ArrayFromJSON(ty, "[[1, 2, -3], [3, -4, 5], [-5, 6, 7], [-7, -8, -9]]"), + ArrayFromJSON(ty, "[[-9, -10, 11], [11, -12, 0], [-13, 14, -1], [15, 16, 2]]"), + ArrayFromJSON(ty, "[[1, 2, -3], [3, -4, 5], [-5, 6, 7], [15, 16, 2]]")); +} + TEST_F(TestIfElseKernel, IfElseDispatchBest) { std::string name = "if_else"; ASSERT_OK_AND_ASSIGN(auto function, GetFunctionRegistry()->GetFunction(name)); @@ -1368,6 +1377,22 @@ TEST(TestCaseWhen, DayTimeInterval) { ArrayFromJSON(type, "[null, null, null, [6, 6]]")); } +TEST(TestCaseWhen, MonthDayNanoInterval) { + auto type = month_day_nano_interval(); + auto cond1 = ArrayFromJSON(boolean(), "[true, true, null, null]"); + auto cond2 = ArrayFromJSON(boolean(), "[true, false, true, null]"); + auto values_null = ArrayFromJSON(type, "[null, null, null, null]"); + auto values1 = ArrayFromJSON(type, R"([[0, 1, -2], null, [-3, 4, 5], [-6, -7, -8]])"); + auto values2 = ArrayFromJSON(type, R"([[1, 2, 3], [4, 5, 6], null, [0, 2, 4]])"); + + CheckScalar("case_when", {MakeStruct({cond1, cond2}), values1, values2}, + ArrayFromJSON(type, R"([[0, 1, -2], null, null, null])")); + CheckScalar("case_when", {MakeStruct({cond1, cond2}), values1, values2, values1}, + ArrayFromJSON(type, R"([[0, 1, -2], null, null, [-6, -7, -8]])")); + CheckScalar("case_when", {MakeStruct({cond1, cond2}), values_null, values2, values1}, + ArrayFromJSON(type, R"([null, null, null, [-6, -7, -8]])")); +} + TEST(TestCaseWhen, Decimal) { for (const auto& type : std::vector>{decimal128(3, 2), decimal256(3, 2)}) { @@ -2425,6 +2450,35 @@ TEST(TestCoalesce, DayTimeInterval) { ArrayFromJSON(type, "[[1, 2], [1, 2], [1, 2], [1, 2]]")); } +TEST(TestCoalesce, MonthDayNanoInterval) { + auto type = month_day_nano_interval(); + auto scalar_null = ScalarFromJSON(type, "null"); + auto scalar1 = ScalarFromJSON(type, "[1, 2, 3]"); + auto values_null = ArrayFromJSON(type, "[null, null, null, null]"); + auto values1 = ArrayFromJSON(type, "[null, [3, 4, 5], [5, 6, 7], [7, 8, 9]]"); + auto values2 = + ArrayFromJSON(type, "[[9, 10, 0], [11, 12, 1], [13, 14, 2], [15, 16, 3]]"); + auto values3 = ArrayFromJSON(type, "[[17, 18, 4], [19, 20, 5], [21, 22, 6], null]"); + CheckScalar("coalesce", {values_null}, values_null); + CheckScalar("coalesce", {values_null, scalar1}, + ArrayFromJSON(type, "[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]")); + CheckScalar("coalesce", {values_null, values1}, values1); + CheckScalar("coalesce", {values_null, values2}, values2); + CheckScalar("coalesce", {values1, values_null}, values1); + CheckScalar("coalesce", {values2, values_null}, values2); + CheckScalar("coalesce", {scalar_null, values1}, values1); + CheckScalar("coalesce", {values1, scalar_null}, values1); + CheckScalar("coalesce", {values2, values1, values_null}, values2); + CheckScalar("coalesce", {values1, scalar1}, + ArrayFromJSON(type, "[[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]]")); + CheckScalar("coalesce", {values1, values2}, + ArrayFromJSON(type, "[[9, 10, 0], [3, 4, 5], [5, 6, 7], [7, 8, 9]]")); + CheckScalar("coalesce", {values1, values2, values3}, + ArrayFromJSON(type, "[[9, 10, 0], [3, 4, 5], [5, 6, 7], [7, 8, 9]]")); + CheckScalar("coalesce", {scalar1, values1}, + ArrayFromJSON(type, "[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]")); +} + TEST(TestCoalesce, Decimal) { for (const auto& type : std::vector>{decimal128(3, 2), decimal256(3, 2)}) { @@ -2834,6 +2888,29 @@ TEST(TestChoose, DayTimeInterval) { *MakeArrayOfNull(type, 5)); } +TEST(TestChoose, MonthDayNanoInterval) { + auto type = month_day_nano_interval(); + auto indices1 = ArrayFromJSON(int64(), "[0, 1, 0, 1, null]"); + auto values1 = ArrayFromJSON(type, "[[10, 1, 0], [10, 1, 0], null, null, [10, 1, 0]]"); + auto values2 = ArrayFromJSON(type, "[[2, 20, 4], [2, 20, 4], null, null, [2, 20, 4]]"); + auto nulls = ArrayFromJSON(type, "[null, null, null, null, null]"); + CheckScalar("choose", {indices1, values1, values2}, + ArrayFromJSON(type, "[[10, 1, 0], [2, 20, 4], null, null, null]")); + CheckScalar("choose", {indices1, ScalarFromJSON(type, "[1, 2, 3]"), values1}, + ArrayFromJSON(type, "[[1, 2, 3], [10, 1, 0], [1, 2, 3], null, null]")); + CheckScalar("choose", {ScalarFromJSON(int64(), "0"), values1, values2}, values1); + CheckScalar("choose", {ScalarFromJSON(int64(), "1"), values1, values2}, values2); + CheckScalar("choose", {ScalarFromJSON(int64(), "null"), values1, values2}, nulls); + auto scalar1 = ScalarFromJSON(type, "[10, 1, 0]"); + CheckScalar("choose", {ScalarFromJSON(int64(), "0"), scalar1, values2}, + *MakeArrayFromScalar(*scalar1, 5)); + CheckScalar("choose", {ScalarFromJSON(int64(), "1"), scalar1, values2}, values2); + CheckScalar("choose", {ScalarFromJSON(int64(), "null"), values1, values2}, nulls); + auto scalar_null = ScalarFromJSON(type, "null"); + CheckScalar("choose", {ScalarFromJSON(int64(), "0"), scalar_null, values2}, + *MakeArrayOfNull(type, 5)); +} + TEST(TestChoose, Decimal) { for (const auto& type : {decimal128(3, 2), decimal256(3, 2)}) { auto indices1 = ArrayFromJSON(int64(), "[0, 1, 0, 1, null]"); diff --git a/cpp/src/arrow/compute/kernels/vector_replace.cc b/cpp/src/arrow/compute/kernels/vector_replace.cc index eca9c4bb72c..7f204b529eb 100644 --- a/cpp/src/arrow/compute/kernels/vector_replace.cc +++ b/cpp/src/arrow/compute/kernels/vector_replace.cc @@ -210,7 +210,9 @@ template struct ReplaceWithMask {}; template -struct ReplaceWithMask> { +struct ReplaceWithMask::value || + std::is_same::value>> { using T = typename TypeTraits::CType; static void CopyData(const DataType&, uint8_t* out, const int64_t out_offset, diff --git a/cpp/src/arrow/compute/kernels/vector_replace_test.cc b/cpp/src/arrow/compute/kernels/vector_replace_test.cc index f1e5750ca95..e12a42e5254 100644 --- a/cpp/src/arrow/compute/kernels/vector_replace_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_replace_test.cc @@ -149,6 +149,14 @@ class TestReplaceDayTimeInterval : public TestReplaceKernel } }; +class TestReplaceMonthDayNanoInterval + : public TestReplaceKernel { + protected: + std::shared_ptr type() override { + return TypeTraits::type_singleton(); + } +}; + template class TestReplaceBinary : public TestReplaceKernel { protected: @@ -209,12 +217,12 @@ TYPED_TEST(TestReplaceNumeric, ReplaceWithMask) { this->mask("[null, null, null, null]"), this->array("[]"), this->array("[null, null, null, null]")); this->Assert(ReplaceWithMask, this->array("[0, 1, 2, 3, 4, 5]"), - this->mask("[true, true, false, false, null, null]"), - this->array("[10, null]"), this->array("[10, null, 2, 3, null, null]")); + this->mask("[false, false, null, null, true, true]"), + this->array("[10, null]"), this->array("[0, 1, null, null, 10, null]")); this->Assert(ReplaceWithMask, this->array("[null, null, null, null, null, null]"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array("[10, null]"), - this->array("[10, null, null, null, null, null]")); + this->array("[null, null, null, null, 10, null]")); this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), this->scalar("1"), this->array("[]")); @@ -223,8 +231,8 @@ TYPED_TEST(TestReplaceNumeric, ReplaceWithMask) { this->Assert(ReplaceWithMask, this->array("[0, 1]"), this->mask("[true, true]"), this->scalar("null"), this->array("[null, null]")); this->Assert(ReplaceWithMask, this->array("[0, 1, 2]"), - this->mask("[true, false, null]"), this->scalar("10"), - this->array("[10, 1, null]")); + this->mask("[false, null, true]"), this->scalar("10"), + this->array("[0, null, 10]")); } TYPED_TEST(TestReplaceNumeric, ReplaceWithMaskRandom) { @@ -325,13 +333,13 @@ TEST_F(TestReplaceBoolean, ReplaceWithMask) { this->mask("[null, null, null, null]"), this->array("[]"), this->array("[null, null, null, null]")); this->Assert(ReplaceWithMask, this->array("[true, true, true, true, true, true]"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array("[false, null]"), - this->array("[false, null, true, true, null, null]")); + this->array("[true, true, null, null, false, null]")); this->Assert(ReplaceWithMask, this->array("[null, null, null, null, null, null]"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array("[false, null]"), - this->array("[false, null, null, null, null, null]")); + this->array("[null, null, null, null, false, null]")); this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), this->scalar("true"), this->array("[]")); @@ -340,8 +348,8 @@ TEST_F(TestReplaceBoolean, ReplaceWithMask) { this->Assert(ReplaceWithMask, this->array("[false, false]"), this->mask("[true, true]"), this->scalar("null"), this->array("[null, null]")); this->Assert(ReplaceWithMask, this->array("[false, false, false]"), - this->mask("[true, false, null]"), this->scalar("true"), - this->array("[true, false, null]")); + this->mask("[false, null, true]"), this->scalar("true"), + this->array("[false, null, true]")); } TEST_F(TestReplaceBoolean, ReplaceWithMaskErrors) { @@ -412,13 +420,13 @@ TEST_F(TestReplaceFixedSizeBinary, ReplaceWithMask) { this->array(R"([null, null, null, null])")); this->Assert(ReplaceWithMask, this->array(R"(["aaa", "bbb", "ccc", "ddd", "eee", "fff"])"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array(R"(["ggg", null])"), - this->array(R"(["ggg", null, "ccc", "ddd", null, null])")); + this->array(R"(["aaa", "bbb", null, null, "ggg", null])")); this->Assert(ReplaceWithMask, this->array(R"([null, null, null, null, null, null])"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array(R"(["aaa", null])"), - this->array(R"(["aaa", null, null, null, null, null])")); + this->array(R"([null, null, null, null, "aaa", null])")); this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), this->scalar(R"("zzz")"), this->array("[]")); @@ -429,8 +437,8 @@ TEST_F(TestReplaceFixedSizeBinary, ReplaceWithMask) { this->mask("[true, true]"), this->scalar("null"), this->array("[null, null]")); this->Assert(ReplaceWithMask, this->array(R"(["aaa", "bbb", "ccc"])"), - this->mask("[true, false, null]"), this->scalar(R"("zzz")"), - this->array(R"(["zzz", "bbb", null])")); + this->mask("[false, null, true]"), this->scalar(R"("zzz")"), + this->array(R"(["aaa", null, "zzz"])")); } TEST_F(TestReplaceFixedSizeBinary, ReplaceWithMaskErrors) { @@ -493,13 +501,13 @@ TYPED_TEST(TestReplaceDecimal, ReplaceWithMask) { this->array("[null, null, null, null]")); this->Assert(ReplaceWithMask, this->array(R"(["0.00", "1.00", "2.00", "3.00", "4.00", "5.00"])"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array(R"(["10.00", null])"), - this->array(R"(["10.00", null, "2.00", "3.00", null, null])")); + this->array(R"(["0.00", "1.00", null, null, "10.00", null])")); this->Assert(ReplaceWithMask, this->array("[null, null, null, null, null, null]"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array(R"(["10.00", null])"), - this->array(R"(["10.00", null, null, null, null, null])")); + this->array(R"([null, null, null, null, "10.00", null])")); this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), this->scalar(R"("1.00")"), this->array("[]")); @@ -510,8 +518,8 @@ TYPED_TEST(TestReplaceDecimal, ReplaceWithMask) { this->mask("[true, true]"), this->scalar("null"), this->array("[null, null]")); this->Assert(ReplaceWithMask, this->array(R"(["0.00", "1.00", "2.00"])"), - this->mask("[true, false, null]"), this->scalar(R"("10.00")"), - this->array(R"(["10.00", "1.00", null])")); + this->mask("[false, null, true]"), this->scalar(R"("10.00")"), + this->array(R"(["0.00", null, "10.00"])")); } TEST_F(TestReplaceDayTimeInterval, ReplaceWithMask) { @@ -560,12 +568,12 @@ TEST_F(TestReplaceDayTimeInterval, ReplaceWithMask) { this->array("[null, null, null, null]")); this->Assert( ReplaceWithMask, this->array("[[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]"), - this->mask("[true, true, false, false, null, null]"), this->array("[[3, 4], null]"), - this->array("[[3, 4], null, [1, 2], [1, 2], null, null]")); + this->mask("[false, false, null, null, true, true]"), this->array("[[3, 4], null]"), + this->array("[[1, 2], [1, 2], null, null, [3, 4], null]")); this->Assert(ReplaceWithMask, this->array("[null, null, null, null, null, null]"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array("[[3, 4], null]"), - this->array("[[3, 4], null, null, null, null, null]")); + this->array("[null, null, null, null, [3, 4], null]")); this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), this->scalar("[7, 8]"), this->array("[]")); @@ -576,8 +584,82 @@ TEST_F(TestReplaceDayTimeInterval, ReplaceWithMask) { this->mask("[true, true]"), this->scalar("null"), this->array("[null, null]")); this->Assert(ReplaceWithMask, this->array("[[1, 2], [3, 4], [5, 6]]"), - this->mask("[true, false, null]"), this->scalar("[7, 8]"), - this->array("[[7, 8], [3, 4], null]")); + this->mask("[false, null, true]"), this->scalar("[7, 8]"), + this->array("[[1, 2], null, [7, 8]]")); +} + +TEST_F(TestReplaceMonthDayNanoInterval, ReplaceWithMask) { + this->Assert(ReplaceWithMask, this->array("[]"), this->mask_scalar(false), + this->array("[]"), this->array("[]")); + this->Assert(ReplaceWithMask, this->array("[]"), this->mask_scalar(true), + this->array("[]"), this->array("[]")); + this->Assert(ReplaceWithMask, this->array("[]"), this->null_mask_scalar(), + this->array("[]"), this->array("[]")); + + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4]]"), this->mask_scalar(false), + this->array("[]"), this->array("[[1, 2, 4]]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4]]"), this->mask_scalar(true), + this->array("[[3, 4, -2]]"), this->array("[[3, 4, -2]]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4]]"), this->null_mask_scalar(), + this->array("[]"), this->array("[null]")); + + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [3, 4, -2]]"), + this->mask_scalar(false), this->scalar("[7, 0, 8]"), + this->array("[[1, 2, 4], [3, 4, -2]]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [3, 4, -2]]"), + this->mask_scalar(true), this->scalar("[7, 0, 8]"), + this->array("[[7, 0, 8], [7, 0, 8]]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [3, 4, -2]]"), + this->mask_scalar(true), this->scalar("null"), + this->array("[null, null]")); + + this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), this->array("[]"), + this->array("[]")); + this->Assert(ReplaceWithMask, + this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], [1, 2, 4]]"), + this->mask("[false, false, false, false]"), this->array("[]"), + this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], [1, 2, 4]]")); + this->Assert(ReplaceWithMask, + this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], [1, 2, 4]]"), + this->mask("[true, true, true, true]"), + this->array("[[3, 4, -2], [3, 4, -2], [3, 4, -2], [3, 4, -2]]"), + this->array("[[3, 4, -2], [3, 4, -2], [3, 4, -2], [3, 4, -2]]")); + this->Assert(ReplaceWithMask, + this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], [1, 2, 4]]"), + this->mask("[null, null, null, null]"), this->array("[]"), + this->array("[null, null, null, null]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], null]"), + this->mask("[false, false, false, false]"), this->array("[]"), + this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], null]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], null]"), + this->mask("[true, true, true, true]"), + this->array("[[3, 4, -2], [3, 4, -2], [3, 4, -2], [3, 4, -2]]"), + this->array("[[3, 4, -2], [3, 4, -2], [3, 4, -2], [3, 4, -2]]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], null]"), + this->mask("[null, null, null, null]"), this->array("[]"), + this->array("[null, null, null, null]")); + this->Assert( + ReplaceWithMask, + this->array("[[1, 2, 4], [1, 2, 4], [1, 2, 4], [1, 2, 4], [1, 2, 4], [1, 2, 4]]"), + this->mask("[false, false, null, null, true, true]"), + this->array("[[3, 4, -2], null]"), + this->array("[[1, 2, 4], [1, 2, 4], null, null, [3, 4, -2], null]")); + this->Assert(ReplaceWithMask, this->array("[null, null, null, null, null, null]"), + this->mask("[false, false, null, null, true, true]"), + this->array("[[3, 4, -2], null]"), + this->array("[null, null, null, null, [3, 4, -2], null]")); + + this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), + this->scalar("[7, 0, 8]"), this->array("[]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [3, 4, -2]]"), + this->mask("[true, true]"), this->scalar("[7, 0, 8]"), + this->array("[[7, 0, 8], [7, 0, 8]]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [3, 4, -2]]"), + this->mask("[true, true]"), this->scalar("null"), + this->array("[null, null]")); + this->Assert(ReplaceWithMask, this->array("[[1, 2, 4], [3, 4, -2], [-5, 6, 7]]"), + this->mask("[false, null, true]"), this->scalar("[7, 0, 8]"), + this->array("[[1, 2, 4], null, [7, 0, 8]]")); } TYPED_TEST(TestReplaceBinary, ReplaceWithMask) { @@ -627,13 +709,13 @@ TYPED_TEST(TestReplaceBinary, ReplaceWithMask) { this->array(R"([null, null, null, null])")); this->Assert(ReplaceWithMask, this->array(R"(["a", "bb", "ccc", "dddd", "eeeee", "f"])"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array(R"(["ggg", null])"), - this->array(R"(["ggg", null, "ccc", "dddd", null, null])")); + this->array(R"(["a", "bb", null, null, "ggg", null])")); this->Assert(ReplaceWithMask, this->array(R"([null, null, null, null, null, null])"), - this->mask("[true, true, false, false, null, null]"), + this->mask("[false, false, null, null, true, true]"), this->array(R"(["a", null])"), - this->array(R"(["a", null, null, null, null, null])")); + this->array(R"([null, null, null, null, "a", null])")); this->Assert(ReplaceWithMask, this->array("[]"), this->mask("[]"), this->scalar(R"("zzz")"), this->array("[]")); @@ -642,8 +724,8 @@ TYPED_TEST(TestReplaceBinary, ReplaceWithMask) { this->Assert(ReplaceWithMask, this->array(R"(["a", "bb"])"), this->mask("[true, true]"), this->scalar("null"), this->array("[null, null]")); this->Assert(ReplaceWithMask, this->array(R"(["a", "bb", "ccc"])"), - this->mask("[true, false, null]"), this->scalar(R"("zzz")"), - this->array(R"(["zzz", "bb", null])")); + this->mask("[false, null, true]"), this->scalar(R"("zzz")"), + this->array(R"(["a", null, "zzz"])")); } TYPED_TEST(TestReplaceBinary, ReplaceWithMaskRandom) { diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc index 309815606ef..bed7536319e 100644 --- a/cpp/src/arrow/type.cc +++ b/cpp/src/arrow/type.cc @@ -2374,7 +2374,7 @@ void InitStaticData() { timestamp(TimeUnit::NANO)}; // Interval types - g_interval_types = {day_time_interval(), month_interval()}; + g_interval_types = {day_time_interval(), month_interval(), month_day_nano_interval()}; // Base binary types (without FixedSizeBinary) g_base_binary_types = {binary(), utf8(), large_binary(), large_utf8()}; diff --git a/cpp/src/arrow/type_traits.h b/cpp/src/arrow/type_traits.h index 56d059287b3..5e4c975d3a2 100644 --- a/cpp/src/arrow/type_traits.h +++ b/cpp/src/arrow/type_traits.h @@ -235,6 +235,7 @@ struct TypeTraits { using ArrayType = MonthDayNanoIntervalArray; using BuilderType = MonthDayNanoIntervalBuilder; using ScalarType = MonthDayNanoIntervalScalar; + using CType = MonthDayNanoIntervalType::c_type; static constexpr int64_t bytes_required(int64_t elements) { return elements *