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

Method run_comparisons

cpp/src/arrow/compute/key_map_internal.cc:332–380  ·  view source on GitHub ↗

Input selection may be: - a range of all ids from 0 to num_keys - 1 - a selection vector with list of ids - a bit-vector marking ids that are included Either selection index vector or selection bit-vector must be provided but both cannot be set at the same time (one must be null). Input and output selection index vectors are allowed to point to the same buffer (in-place filtering of ids). Output

Source from the content-addressed store, hash-verified

330// Output selection vector needs to have enough space for num_keys entries.
331//
332void SwissTable::run_comparisons(const int num_keys,
333 const uint16_t* optional_selection_ids,
334 const uint8_t* optional_selection_bitvector,
335 const uint32_t* groupids, int* out_num_not_equal,
336 uint16_t* out_not_equal_selection,
337 const EqualImpl& equal_impl, void* callback_ctx) const {
338 ARROW_DCHECK(optional_selection_ids || optional_selection_bitvector);
339 ARROW_DCHECK(!optional_selection_ids || !optional_selection_bitvector);
340
341 if (num_keys == 0) {
342 *out_num_not_equal = 0;
343 return;
344 }
345
346 if (!optional_selection_ids && optional_selection_bitvector) {
347 // Count rows with matches (based on stamp comparison)
348 // and decide based on their percentage whether to call dense or sparse comparison
349 // function. Dense comparison means evaluating it for all inputs, even if the
350 // matching stamp was not found. It may be cheaper to evaluate comparison for all
351 // inputs if the extra cost of filtering is higher than the wasted processing of
352 // rows with no match.
353 //
354 // Dense comparison can only be used if there is at least one inserted key,
355 // because otherwise there is no key to compare to.
356 //
357 int64_t num_matches = arrow::internal::CountSetBits(optional_selection_bitvector,
358 /*offset=*/0, num_keys);
359
360 if (num_inserted_ > 0 && num_matches > 0 && num_matches > 3 * num_keys / 4) {
361 uint32_t out_num;
362 equal_impl(num_keys, nullptr, groupids, &out_num, out_not_equal_selection,
363 callback_ctx);
364 *out_num_not_equal = static_cast<int>(out_num);
365 } else {
366 util::bit_util::bits_to_indexes(1, hardware_flags_, num_keys,
367 optional_selection_bitvector, out_num_not_equal,
368 out_not_equal_selection);
369 uint32_t out_num;
370 equal_impl(*out_num_not_equal, out_not_equal_selection, groupids, &out_num,
371 out_not_equal_selection, callback_ctx);
372 *out_num_not_equal = static_cast<int>(out_num);
373 }
374 } else {
375 uint32_t out_num;
376 equal_impl(num_keys, optional_selection_ids, groupids, &out_num,
377 out_not_equal_selection, callback_ctx);
378 *out_num_not_equal = static_cast<int>(out_num);
379 }
380}
381
382// Given starting slot index, search blocks for a matching stamp
383// until one is found or an empty slot is reached.

Callers

nothing calls this directly

Calls 2

bits_to_indexesFunction · 0.85
CountSetBitsFunction · 0.50

Tested by

no test coverage detected