kou commented on code in PR #36740:
URL: https://github.com/apache/arrow/pull/36740#discussion_r1267399416
##########
cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:
##########
@@ -196,17 +198,26 @@ class RunEndEncodeImpl {
/*output_run_ends=*/NULLPTR);
std::tie(num_valid_runs, num_output_runs, data_buffer_size) =
counting_loop.CountNumberOfRuns();
+ const int64_t physical_null_count = num_output_runs - num_valid_runs;
Review Comment:
```suggestion
const auto physical_null_count = num_output_runs - num_valid_runs;
```
##########
cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:
##########
@@ -196,17 +198,26 @@ class RunEndEncodeImpl {
/*output_run_ends=*/NULLPTR);
std::tie(num_valid_runs, num_output_runs, data_buffer_size) =
counting_loop.CountNumberOfRuns();
+ const int64_t physical_null_count = num_output_runs - num_valid_runs;
+ DCHECK(!has_validity_buffer || physical_null_count > 0)
+ << "has_validity_buffer is expected to imply physical_null_count > 0";
ARROW_ASSIGN_OR_RAISE(
auto output_array_data,
ree_util::PreallocateREEArray(
- std::move(ree_type), has_validity_buffer, input_length,
num_output_runs,
- num_output_runs - num_valid_runs, ctx_->memory_pool(),
data_buffer_size));
+ std::move(ree_type), has_validity_buffer,
/*logical_length=*/input_length,
+ /*physical_length=*/num_output_runs, ctx_->memory_pool(),
data_buffer_size));
// Initialize the output pointers
auto* output_run_ends =
output_array_data->child_data[0]->template
GetMutableValues<RunEndCType>(1, 0);
auto* output_values_array_data = output_array_data->child_data[1].get();
+ // Set the null_count on the physical array
+ DCHECK(!has_validity_buffer || output_values_array_data->buffers[0])
+ << "has_validity_buffer implies a validity buffer is allocated";
+ DCHECK(output_values_array_data->null_count == kUnknownNullCount ||
+ physical_null_count == 0);
+ output_values_array_data->null_count = physical_null_count;
Review Comment:
How about adding "caller must set values' null_count explicitly" or
something to `PreallocateREEArray()` document?
##########
cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:
##########
@@ -398,17 +409,19 @@ class RunEndDecodeImpl {
}
}
- ARROW_ASSIGN_OR_RAISE(auto output_array_data,
- ree_util::PreallocateValuesArray(
- ree_type->value_type(), has_validity_buffer,
length,
- kUnknownNullCount, ctx_->memory_pool(),
data_buffer_size));
+ ARROW_ASSIGN_OR_RAISE(
+ auto output_array_data,
+ ree_util::PreallocateValuesArray(ree_type->value_type(),
has_validity_buffer,
+ length, ctx_->memory_pool(),
data_buffer_size));
int64_t output_null_count = 0;
if (length > 0) {
RunEndDecodingLoop<RunEndType, ValueType, has_validity_buffer> loop(
input_array_, output_array_data.get());
output_null_count = length - loop.ExpandAllRuns();
}
+ DCHECK(output_array_data->null_count == kUnknownNullCount ||
+ output_array_data->null_count == 0);
Review Comment:
Is this useful?
It seems that this just checks a return value of `PreallocateValuesArray()`.
If this is a post-condition of `PreallocateValuesArray()`, how about doing this
in `PreallocateValuesArray()` not in callers?
##########
cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:
##########
@@ -196,17 +198,26 @@ class RunEndEncodeImpl {
/*output_run_ends=*/NULLPTR);
std::tie(num_valid_runs, num_output_runs, data_buffer_size) =
counting_loop.CountNumberOfRuns();
+ const int64_t physical_null_count = num_output_runs - num_valid_runs;
+ DCHECK(!has_validity_buffer || physical_null_count > 0)
+ << "has_validity_buffer is expected to imply physical_null_count > 0";
ARROW_ASSIGN_OR_RAISE(
auto output_array_data,
ree_util::PreallocateREEArray(
- std::move(ree_type), has_validity_buffer, input_length,
num_output_runs,
- num_output_runs - num_valid_runs, ctx_->memory_pool(),
data_buffer_size));
+ std::move(ree_type), has_validity_buffer,
/*logical_length=*/input_length,
+ /*physical_length=*/num_output_runs, ctx_->memory_pool(),
data_buffer_size));
// Initialize the output pointers
auto* output_run_ends =
output_array_data->child_data[0]->template
GetMutableValues<RunEndCType>(1, 0);
auto* output_values_array_data = output_array_data->child_data[1].get();
+ // Set the null_count on the physical array
+ DCHECK(!has_validity_buffer || output_values_array_data->buffers[0])
+ << "has_validity_buffer implies a validity buffer is allocated";
+ DCHECK(output_values_array_data->null_count == kUnknownNullCount ||
+ physical_null_count == 0);
Review Comment:
Is this useful?
It seems that `output_values_array_data->null_count == kUnknownNullCount` is
always true because `PreallocateREEValues()` uses `kUnknownNullCount`
unconditionally.
##########
cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:
##########
@@ -196,17 +198,26 @@ class RunEndEncodeImpl {
/*output_run_ends=*/NULLPTR);
std::tie(num_valid_runs, num_output_runs, data_buffer_size) =
counting_loop.CountNumberOfRuns();
+ const int64_t physical_null_count = num_output_runs - num_valid_runs;
+ DCHECK(!has_validity_buffer || physical_null_count > 0)
+ << "has_validity_buffer is expected to imply physical_null_count > 0";
ARROW_ASSIGN_OR_RAISE(
auto output_array_data,
ree_util::PreallocateREEArray(
- std::move(ree_type), has_validity_buffer, input_length,
num_output_runs,
- num_output_runs - num_valid_runs, ctx_->memory_pool(),
data_buffer_size));
+ std::move(ree_type), has_validity_buffer,
/*logical_length=*/input_length,
+ /*physical_length=*/num_output_runs, ctx_->memory_pool(),
data_buffer_size));
// Initialize the output pointers
auto* output_run_ends =
output_array_data->child_data[0]->template
GetMutableValues<RunEndCType>(1, 0);
auto* output_values_array_data = output_array_data->child_data[1].get();
+ // Set the null_count on the physical array
+ DCHECK(!has_validity_buffer || output_values_array_data->buffers[0])
+ << "has_validity_buffer implies a validity buffer is allocated";
Review Comment:
Why do we do this in caller not in `PreallocateREEValues()`?
It seems that `PreallocateREEValues()` is responsible for this.
--
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]