MCPcopy Create free account
hub / github.com/apache/arrow / Exec

Method Exec

cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:178–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176 : ctx_{ctx}, input_array_{input_array}, output_{out} {}
177
178 Status Exec() {
179 const int64_t input_length = input_array_.length;
180
181 auto run_end_type = TypeTraits<RunEndType>::type_singleton();
182 auto ree_type = std::make_shared<RunEndEncodedType>(
183 run_end_type, input_array_.type->GetSharedPtr());
184 if (input_length == 0) {
185 ARROW_ASSIGN_OR_RAISE(
186 auto output_array_data,
187 ree_util::PreallocateREEArray(std::move(ree_type), has_validity_buffer,
188 /*logical_length=*/input_length,
189 /*physical_length=*/0, ctx_->memory_pool(),
190 /*data_buffer_size=*/0));
191 output_->value = std::move(output_array_data);
192 return Status::OK();
193 }
194
195 // First pass: count the number of runs
196 int64_t num_valid_runs = 0;
197 int64_t num_output_runs = 0;
198 int64_t data_buffer_size = 0; // for string and binary types
199 RETURN_NOT_OK(ValidateRunEndType(run_end_type, input_length));
200
201 RunEndEncodingLoop<RunEndType, ValueType, has_validity_buffer> counting_loop(
202 input_array_,
203 /*output_values_array_data=*/NULLPTR,
204 /*output_run_ends=*/NULLPTR);
205 std::tie(num_valid_runs, num_output_runs, data_buffer_size) =
206 counting_loop.CountNumberOfRuns();
207 const auto physical_null_count = num_output_runs - num_valid_runs;
208 DCHECK(!has_validity_buffer || physical_null_count > 0)
209 << "has_validity_buffer is expected to imply physical_null_count > 0";
210
211 ARROW_ASSIGN_OR_RAISE(
212 auto output_array_data,
213 ree_util::PreallocateREEArray(
214 std::move(ree_type), has_validity_buffer, /*logical_length=*/input_length,
215 /*physical_length=*/num_output_runs, ctx_->memory_pool(), data_buffer_size));
216
217 // Initialize the output pointers
218 auto* output_run_ends =
219 output_array_data->child_data[0]->template GetMutableValues<RunEndCType>(1, 0);
220 auto* output_values_array_data = output_array_data->child_data[1].get();
221 // Set the null_count on the physical array
222 output_values_array_data->null_count = physical_null_count;
223
224 // Second pass: write the runs
225 RunEndEncodingLoop<RunEndType, ValueType, has_validity_buffer> writing_loop(
226 input_array_, output_values_array_data, output_run_ends);
227 [[maybe_unused]] int64_t num_written_runs = writing_loop.WriteEncodedRuns();
228 DCHECK_EQ(num_written_runs, num_output_runs);
229
230 output_->value = std::move(output_array_data);
231 return Status::OK();
232 }
233};
234
235ARROW_NOINLINE Status RunEndEncodeNullArray(const std::shared_ptr<DataType>& run_end_type,

Callers 2

DoExecMethod · 0.45
DoExecMethod · 0.45

Calls 4

ValidateRunEndTypeFunction · 0.85
type_singletonFunction · 0.70
OKFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected