Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-13530: [C++] Implement cumulative sum compute function#12460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
cd6550b067f846a747cb430984e159fad2393644f8dd45c3d236d56b19a9d052c3722f73f7a329ff405e4b42c8fe318bec940c0c25802d01a4a7d374501d7f634273efc388d7df3e6ae6f42a0f56f2d781ceebce0a9e1c95d7d2ea671659aa07d7a11086c0b961518805c799daa27d96f3218afcfe8fc4bd9f1b7258947855ae02a3d3261cbd265d2c53eedecf4c6520997113fcd4272eaf5f3e1148f1e2f3714bc90d5356bba2fc58b36d51933da73667981ae25c71b061ab484bdcd7bba5fcf4e58857441a8126509befc596d1716c4489e8be46af8251309d1f44f1f2df7cb04f8984e3e1afbbf7ff49ac5c36e7203a02fe3e3a02a54be3673dec2e205903f36557File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -135,6 +135,10 @@ static auto kPartitionNthOptionsType = GetFunctionOptionsType<PartitionNthOption | ||
| static auto kSelectKOptionsType = GetFunctionOptionsType<SelectKOptions>( | ||
| DataMember("k", &SelectKOptions::k), | ||
| DataMember("sort_keys", &SelectKOptions::sort_keys)); | ||
| static auto kCumulativeSumOptionsType = GetFunctionOptionsType<CumulativeSumOptions>( | ||
| DataMember("start", &CumulativeSumOptions::start), | ||
| DataMember("skip_nulls", &CumulativeSumOptions::skip_nulls), | ||
| DataMember("check_overflow", &CumulativeSumOptions::check_overflow)); | ||
| } // namespace | ||
| } // namespace internal | ||
| @@ -176,6 +180,18 @@ SelectKOptions::SelectKOptions(int64_t k, std::vector<SortKey> sort_keys) | ||
| sort_keys(std::move(sort_keys)) {} | ||
| constexpr char SelectKOptions::kTypeName[]; | ||
| CumulativeSumOptions::CumulativeSumOptions(double start, bool skip_nulls, | ||
| bool check_overflow) | ||
| : CumulativeSumOptions(std::make_shared<DoubleScalar>(start), skip_nulls, | ||
| check_overflow) {} | ||
| CumulativeSumOptions::CumulativeSumOptions(std::shared_ptr<Scalar> start, bool skip_nulls, | ||
| bool check_overflow) | ||
| : FunctionOptions(internal::kCumulativeSumOptionsType), | ||
| start(std::move(start)), | ||
| skip_nulls(skip_nulls), | ||
| check_overflow(check_overflow) {} | ||
| constexpr char CumulativeSumOptions::kTypeName[]; | ||
| namespace internal { | ||
| void RegisterVectorOptions(FunctionRegistry* registry) { | ||
| DCHECK_OK(registry->AddFunctionOptionsType(kFilterOptionsType)); | ||
| @@ -185,6 +201,7 @@ void RegisterVectorOptions(FunctionRegistry* registry) { | ||
| DCHECK_OK(registry->AddFunctionOptionsType(kSortOptionsType)); | ||
| DCHECK_OK(registry->AddFunctionOptionsType(kPartitionNthOptionsType)); | ||
| DCHECK_OK(registry->AddFunctionOptionsType(kSelectKOptionsType)); | ||
| DCHECK_OK(registry->AddFunctionOptionsType(kCumulativeSumOptionsType)); | ||
| } | ||
| } // namespace internal | ||
| @@ -325,6 +342,15 @@ Result<std::shared_ptr<Array>> DropNull(const Array& values, ExecContext* ctx) { | ||
| return out.make_array(); | ||
| } | ||
| // ---------------------------------------------------------------------- | ||
| // Cumulative functions | ||
| 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); | ||
JabariBooker marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // ---------------------------------------------------------------------- | ||
| // Deprecated functions | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -188,6 +188,27 @@ class ARROW_EXPORT PartitionNthOptions : public FunctionOptions { | ||
| NullPlacement null_placement; | ||
| }; | ||
| /// \brief Options for cumulative sum function | ||
| class ARROW_EXPORT CumulativeSumOptions : public FunctionOptions { | ||
| public: | ||
| explicit CumulativeSumOptions(double start = 0, bool skip_nulls = false, | ||
| bool check_overflow = false); | ||
| explicit CumulativeSumOptions(std::shared_ptr<Scalar> start, bool skip_nulls = false, | ||
| bool check_overflow = false); | ||
| static constexpr char const kTypeName[] = "CumulativeSumOptions"; | ||
| static CumulativeSumOptions Defaults() { return CumulativeSumOptions(); } | ||
| /// Optional starting value for cumulative operation computation | ||
| 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; | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming here is not very good because nulls are never skipped. That said, Pandas uses a similar naming and I don't have a better suggestion. @jorisvandenbossche Any opinion? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where I took the naming from actually. | ||
| /// When true, returns an Invalid Status when overflow is detected | ||
| bool check_overflow = false; | ||
Comment on lines
+208
to
+209
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are two different functions ("cumulative_sum" and "cumulative_sum_checked"), I don't think it makes sense to also have an option for this. Also, it seems actually ignored... ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is inline with the existing scalar arithmetic functions that uses a | ||
| }; | ||
| /// @} | ||
| /// \brief Filter with a boolean selection filter | ||
| @@ -522,6 +543,12 @@ Result<Datum> DictionaryEncode( | ||
| const DictionaryEncodeOptions& options = DictionaryEncodeOptions::Defaults(), | ||
| ExecContext* ctx = NULLPTR); | ||
| ARROW_EXPORT | ||
| Result<Datum> CumulativeSum( | ||
| const Datum& values, | ||
| const CumulativeSumOptions& options = CumulativeSumOptions::Defaults(), | ||
| ExecContext* ctx = NULLPTR); | ||
| // ---------------------------------------------------------------------- | ||
| // Deprecated functions | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.