diff --git a/cpp/src/arrow/array/diff.cc b/cpp/src/arrow/array/diff.cc index 6d9619bb8aa..0a50de0f1f1 100644 --- a/cpp/src/arrow/array/diff.cc +++ b/cpp/src/arrow/array/diff.cc @@ -464,7 +464,7 @@ class MakeFormatterImpl { impl_ = [](const Array& array, int64_t index, std::ostream* os) { auto month_day_nanos = checked_cast(array).Value(index); - *os << month_day_nanos.months << "m" << month_day_nanos.days << "d" + *os << month_day_nanos.months << "M" << month_day_nanos.days << "d" << month_day_nanos.nanoseconds << "ns"; }; return Status::OK(); diff --git a/cpp/src/arrow/array/diff_test.cc b/cpp/src/arrow/array/diff_test.cc index c5cf94fc069..d802a52cdc2 100644 --- a/cpp/src/arrow/array/diff_test.cc +++ b/cpp/src/arrow/array/diff_test.cc @@ -507,7 +507,7 @@ TEST_F(DiffTest, UnifiedDiffFormatter) { target_ = ArrayFromJSON(month_day_nano_interval(), R"([])"); AssertDiffAndFormat(R"( @@ -0, +0 @@ --2m3d1ns +-2M3d1ns )"); // lists diff --git a/cpp/src/arrow/compute/kernels/codegen_internal.h b/cpp/src/arrow/compute/kernels/codegen_internal.h index f9ce34b06e0..847522bb865 100644 --- a/cpp/src/arrow/compute/kernels/codegen_internal.h +++ b/cpp/src/arrow/compute/kernels/codegen_internal.h @@ -923,6 +923,10 @@ using ScalarBinaryEqualTypes = ScalarBinary; template using ScalarBinaryNotNullEqualTypes = ScalarBinaryNotNull; +template +using ScalarBinaryNotNullStatefulEqualTypes = + ScalarBinaryNotNullStateful; + } // namespace applicator // ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/compute/kernels/scalar_temporal.cc b/cpp/src/arrow/compute/kernels/scalar_temporal.cc index 674be60d42b..decf180a252 100644 --- a/cpp/src/arrow/compute/kernels/scalar_temporal.cc +++ b/cpp/src/arrow/compute/kernels/scalar_temporal.cc @@ -50,6 +50,7 @@ using arrow_vendored::date::trunc; using arrow_vendored::date::weekday; using arrow_vendored::date::weeks; using arrow_vendored::date::year_month_day; +using arrow_vendored::date::year_month_weekday; using arrow_vendored::date::years; using arrow_vendored::date::zoned_time; using arrow_vendored::date::literals::dec; @@ -59,7 +60,7 @@ using arrow_vendored::date::literals::mon; using arrow_vendored::date::literals::sun; using arrow_vendored::date::literals::thu; using arrow_vendored::date::literals::wed; -using internal::applicator::ScalarUnaryNotNull; +using internal::applicator::ScalarBinaryNotNullStatefulEqualTypes; using internal::applicator::SimpleUnary; using DayOfWeekState = OptionsWrapper; @@ -81,6 +82,75 @@ Result GetLocale(const std::string& locale) { } } +Status CheckTimezones(const ExecBatch& batch) { + const auto& timezone = GetInputTimezone(batch.values[0]); + for (int i = 1; i < batch.num_values(); i++) { + const auto& other_timezone = GetInputTimezone(batch.values[i]); + if (other_timezone != timezone) { + return Status::TypeError("Got differing time zone '", other_timezone, + "' for argument ", i + 1, "; expected '", timezone, "'"); + } + } + return Status::OK(); +} + +Status ValidateDayOfWeekOptions(const DayOfWeekOptions& options) { + if (options.week_start < 1 || 7 < options.week_start) { + return Status::Invalid( + "week_start must follow ISO convention (Monday=1, Sunday=7). Got week_start=", + options.week_start); + } + return Status::OK(); +} + +int64_t GetQuarter(const year_month_day& ymd) { + return static_cast((static_cast(ymd.month()) - 1) / 3); +} + +template