lidavidm commented on code in PR #13344:
URL: https://github.com/apache/arrow/pull/13344#discussion_r899011680
##########
python/pyarrow/_compute.pyx:
##########
@@ -2067,16 +2067,18 @@ def _group_by(args, keys, aggregations):
vector[CAggregate] c_aggregations
CDatum result
CAggregate c_aggr
+ shared_ptr[CFunctionOptions] null_opts
_pack_compute_args(args, &c_args)
_pack_compute_args(keys, &c_keys)
for aggr_func_name, aggr_opts in aggregations:
c_aggr.function = tobytes(aggr_func_name)
if aggr_opts is not None:
- c_aggr.options = (<FunctionOptions?> aggr_opts).get_options()
+ # (<FunctionOptions?> aggr_opts).get_options()
Review Comment:
what is the comment for?
##########
cpp/src/arrow/compute/api_aggregate.h:
##########
@@ -401,7 +401,7 @@ struct ARROW_EXPORT Aggregate {
std::string function;
/// options for the aggregation function
- const FunctionOptions* options;
+ std::shared_ptr<FunctionOptions> options;
Review Comment:
is `unique_ptr` possible?
##########
cpp/src/arrow/compute/exec/aggregate.cc:
##########
@@ -61,7 +61,11 @@ Result<std::vector<std::unique_ptr<KernelState>>>
InitKernels(
// use known default options for the named function if possible
auto maybe_function =
ctx->func_registry()->GetFunction(aggregates[i].function);
if (maybe_function.ok()) {
- options = maybe_function.ValueOrDie()->default_options();
+ auto default_opts = maybe_function.ValueOrDie()->default_options();
+ // only update the options if the default options are set
+ if (default_opts != nullptr) {
+ options = default_opts->Copy();
+ }
Review Comment:
```suggestion
FunctionOptions* default_opts =
maybe_function.ValueOrDie()->default_options();
if (default_opts != nullptr) {
options = default_opts->Copy();
}
```
##########
cpp/src/arrow/compute/exec/aggregate_node.cc:
##########
@@ -116,11 +111,8 @@ class ScalarAggregateNode : public ExecNode {
kernels[i] = static_cast<const ScalarAggregateKernel*>(kernel);
if (aggregates[i].options == nullptr) {
- aggregates[i].options = function->default_options();
- }
- if (aggregates[i].options) {
- owned_options[i] = aggregates[i].options->Copy();
- aggregates[i].options = owned_options[i].get();
+ auto opts = function->default_options()->Copy();
+ aggregates[i].options = std::move(opts);
Review Comment:
```suggestion
aggregates[i].options = function->default_options()->Copy();
```
##########
python/pyarrow/_compute.pyx:
##########
@@ -2067,16 +2067,18 @@ def _group_by(args, keys, aggregations):
vector[CAggregate] c_aggregations
CDatum result
CAggregate c_aggr
+ shared_ptr[CFunctionOptions] null_opts
_pack_compute_args(args, &c_args)
_pack_compute_args(keys, &c_keys)
for aggr_func_name, aggr_opts in aggregations:
c_aggr.function = tobytes(aggr_func_name)
if aggr_opts is not None:
- c_aggr.options = (<FunctionOptions?> aggr_opts).get_options()
+ # (<FunctionOptions?> aggr_opts).get_options()
+ c_aggr.options = (<FunctionOptions?>aggr_opts).wrapped
else:
- c_aggr.options = NULL
+ c_aggr.options = null_opts
Review Comment:
`<shared_ptr[CFunctionOptions]>nullptr` should work
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]