Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions cpp/src/arrow/compute/api_vector.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,6 +161,17 @@ static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOpti
DataMember("start", &CumulativeSumOptions::start),
DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls),
DataMember("check_overflow", &CumulativeSumOptions::check_overflow));
static auto kCumulativeProductOptionsType =
GetFunctionOptionsType<CumulativeProductOptions>(
DataMember("start", &CumulativeProductOptions::start),
DataMember("skip_nulls", &CumulativeProductOptions::skip_nulls),
DataMember("check_overflow", &CumulativeProductOptions::check_overflow));
static auto kCumulativeMinOptionsType = GetFunctionOptionsType<CumulativeMinOptions>(
DataMember("start", &CumulativeMinOptions::start),
DataMember("skip_nulls", &CumulativeMinOptions::skip_nulls));
static auto kCumulativeMaxOptionsType = GetFunctionOptionsType<CumulativeMaxOptions>(
DataMember("start", &CumulativeMaxOptions::start),
DataMember("skip_nulls", &CumulativeMaxOptions::skip_nulls));
static auto kRankOptionsType = GetFunctionOptionsType<RankOptions>(
DataMember("sort_keys", &RankOptions::sort_keys),
DataMember("null_placement", &RankOptions::null_placement),
Expand DownExpand Up@@ -218,6 +229,38 @@ CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool s
check_overflow(check_overflow) {}
constexpr char CumulativeSumOptions::kTypeName[];

CumulativeProductOptions::CumulativeProductOptions(double start, bool skip_nulls,
bool check_overflow)
: CumulativeProductOptions(std::make_shared<DoubleScalar>(start), skip_nulls,
check_overflow) {}
CumulativeProductOptions::CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls, bool check_overflow)
: FunctionOptions(internal::kCumulativeProductOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls),
check_overflow(check_overflow) {}
constexpr char CumulativeProductOptions::kTypeName[];

CumulativeMinOptions::CumulativeMinOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType), skip_nulls(skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(double start, bool skip_nulls)
: CumulativeMinOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMinOptions::CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMinOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMinOptions::kTypeName[];

CumulativeMaxOptions::CumulativeMaxOptions(bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType), skip_nulls(skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(double start, bool skip_nulls)
: CumulativeMaxOptions(std::make_shared<DoubleScalar>(start), skip_nulls) {}
CumulativeMaxOptions::CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls)
: FunctionOptions(internal::kCumulativeMaxOptionsType),
start(std::move(start)),
skip_nulls(skip_nulls) {}
constexpr char CumulativeMaxOptions::kTypeName[];

RankOptions::RankOptions(std::vector<SortKey> sort_keys, NullPlacement null_placement,
RankOptions::Tiebreaker tiebreaker)
: FunctionOptions(internal::kRankOptionsType),
Expand All@@ -236,6 +279,9 @@ void RegisterVectorOptions(FunctionRegistry* registry) {
DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeProductOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMinOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeMaxOptionsType));
DCHECK_OK(registry->AddFunctionOptionsType(kRankOptionsType));
}
} // namespace internal
Expand DownExpand Up@@ -379,8 +425,27 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) {

Result<Datum> CumulativeSum(const Datum& values, const CumulativeSumOptions& options,
ExecContext* ctx) {
auto func_name = (options.check_overflow) ? "cumulative_sum_checked" : "cumulative_sum";
return CallFunction(func_name, {Datum(values)}, &options, ctx);
return CallFunction(
options.check_overflow ? "cumulative_sum_checked" : "cumulative_sum",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeProduct(const Datum& values,
const CumulativeProductOptions& options,
ExecContext* ctx) {
return CallFunction(
options.check_overflow ? "cumulative_product_checked" : "cumulative_product",
{Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMin(const Datum& values, const CumulativeMinOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_min", {Datum(values)}, &options, ctx);
}

Result<Datum> CumulativeMax(const Datum& values, const CumulativeMaxOptions& options,
ExecContext* ctx) {
return CallFunction("cumulative_max", {Datum(values)}, &options, ctx);
}

// ----------------------------------------------------------------------
Expand Down
87 changes: 86 additions & 1 deletion cpp/src/arrow/compute/api_vector.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -235,7 +235,10 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
static constexpr char const kTypeName[] = "CumulativeSumOptions";
static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); }

/// Optional starting value for cumulative operation computation
const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative sum
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
Expand All@@ -246,6 +249,70 @@ class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions {
bool check_overflow = false;
};

/// \brief Options for cumulative product function
class ARROW_EXPORT CumulativeProductOptions : public FunctionOptions {
public:
explicit CumulativeProductOptions(double start = 1, bool skip_nulls = false,
bool check_overflow = false);
explicit CumulativeProductOptions(std::shared_ptr<Scalar> start,
bool skip_nulls = false, bool check_overflow = false);
static constexpr char const kTypeName[] = "CumulativeProductOptions";
static CumulativeProductOptions Defaults() { return CumulativeProductOptions(); }

const bool is_minmax = false;
const bool is_max = false;

/// Optional starting value for cumulative product
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;

/// When true, returns an Invalid Status when overflow is detected
bool check_overflow = false;
};

/// \brief Options for cumulative min functions
class ARROW_EXPORT CumulativeMinOptions : public FunctionOptions {
public:
explicit CumulativeMinOptions(bool skip_nulls = false);
explicit CumulativeMinOptions(double start, bool skip_nulls = false);
explicit CumulativeMinOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMinOptions";
static CumulativeMinOptions Defaults() { return CumulativeMinOptions(); }

const bool is_minmax = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be more idiomatic to have this as constexpr static bool, then below use if (OptionsType::is_minmax)

const bool is_max = false;

/// Optional starting value for cumulative min
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// \brief Options for cumulative max functions
class ARROW_EXPORT CumulativeMaxOptions : public FunctionOptions {
public:
explicit CumulativeMaxOptions(bool skip_nulls = false);
explicit CumulativeMaxOptions(double start, bool skip_nulls = false);
explicit CumulativeMaxOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false);
static constexpr char const kTypeName[] = "CumulativeMaxOptions";
static CumulativeMaxOptions Defaults() { return CumulativeMaxOptions(); }

const bool is_minmax = true;
const bool is_max = true;

/// Optional starting value for cumulative max
std::shared_ptr<Scalar> start;

/// If true, nulls in the input are ignored and produce a corresponding null output.
/// When false, the first null encountered is propagated through the remaining output.
bool skip_nulls = false;
};

/// @}

/// \brief Filter with a boolean selection filter
Expand DownExpand Up@@ -586,6 +653,24 @@ Result<Datum> CumulativeSum(
const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeProduct(
const Datum& values,
const CumulativeProductOptions& options = CumulativeProductOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMin(
const Datum& values,
const CumulativeMinOptions& options = CumulativeMinOptions::Defaults(),
ExecContext* ctx = NULLPTR);

ARROW_EXPORT
Result<Datum> CumulativeMax(
const Datum& values,
const CumulativeMaxOptions& options = CumulativeMaxOptions::Defaults(),
ExecContext* ctx = NULLPTR);

// ----------------------------------------------------------------------
// Deprecated functions

Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -597,6 +597,55 @@ struct Sign {
}
};

struct Min {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left < right) ? left : right;
}
};
struct Max {
template <typename T, typename Arg0, typename Arg1>
static constexpr T Call(KernelContext*, Arg0 left, Arg1 right, Status*) {
return (left > right) ? left : right;
}
};

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

} // namespace internal
} // namespace compute
} // namespace arrow
38 changes: 1 addition & 37 deletions cpp/src/arrow/compute/kernels/hash_aggregate.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
#include "arrow/compute/kernel.h"
#include "arrow/compute/kernels/aggregate_internal.h"
#include "arrow/compute/kernels/aggregate_var_std_internal.h"
#include "arrow/compute/kernels/base_arithmetic_internal.h"
#include "arrow/compute/kernels/common.h"
#include "arrow/compute/kernels/row_encoder.h"
#include "arrow/compute/kernels/util_internal.h"
Expand DownExpand Up@@ -1199,43 +1200,6 @@ HashAggregateKernel MakeApproximateMedianKernel(HashAggregateFunction* tdigest_f

// ----------------------------------------------------------------------
// MinMax implementation

template <typename CType>
struct AntiExtrema {
static constexpr CType anti_min() { return std::numeric_limits<CType>::max(); }
static constexpr CType anti_max() { return std::numeric_limits<CType>::min(); }
};

template <>
struct AntiExtrema<bool> {
static constexpr bool anti_min() { return true; }
static constexpr bool anti_max() { return false; }
};

template <>
struct AntiExtrema<float> {
static constexpr float anti_min() { return std::numeric_limits<float>::infinity(); }
static constexpr float anti_max() { return -std::numeric_limits<float>::infinity(); }
};

template <>
struct AntiExtrema<double> {
static constexpr double anti_min() { return std::numeric_limits<double>::infinity(); }
static constexpr double anti_max() { return -std::numeric_limits<double>::infinity(); }
};

template <>
struct AntiExtrema<Decimal128> {
static constexpr Decimal128 anti_min() { return BasicDecimal128::GetMaxSentinel(); }
static constexpr Decimal128 anti_max() { return BasicDecimal128::GetMinSentinel(); }
};

template <>
struct AntiExtrema<Decimal256> {
static constexpr Decimal256 anti_min() { return BasicDecimal256::GetMaxSentinel(); }
static constexpr Decimal256 anti_max() { return BasicDecimal256::GetMinSentinel(); }
};

template <typename Type, typename Enable = void>
struct GroupedMinMaxImpl final : public GroupedAggregator {
using CType = typename TypeTraits<Type>::CType;
Expand Down
Loading