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

Function AttachStatistics

cpp/src/parquet/arrow/reader_internal.cc:367–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365
366template <typename ArrowType, typename ParquetType>
367void AttachStatistics(::arrow::ArrayData* data,
368 std::unique_ptr<::parquet::ColumnChunkMetaData> metadata,
369 const ReaderContext* ctx) {
370 if (!metadata) {
371 return;
372 }
373
374 using ArrowCType = typename ArrowType::c_type;
375
376 auto statistics = metadata->statistics();
377 if (data->null_count == ::arrow::kUnknownNullCount && !statistics) {
378 return;
379 }
380
381 auto array_statistics = std::make_shared<::arrow::ArrayStatistics>();
382 if (data->null_count != ::arrow::kUnknownNullCount) {
383 array_statistics->null_count = data->null_count;
384 }
385 if (statistics) {
386 if (statistics->HasDistinctCount()) {
387 array_statistics->distinct_count = statistics->distinct_count();
388 }
389 if (statistics->HasMinMax()) {
390 const auto* typed_statistics =
391 checked_cast<const ::parquet::TypedStatistics<ParquetType>*>(statistics.get());
392 const ArrowCType min = typed_statistics->min();
393 const ArrowCType max = typed_statistics->max();
394 if constexpr (std::is_same_v<ArrowCType, bool>) {
395 array_statistics->min = static_cast<bool>(min);
396 array_statistics->max = static_cast<bool>(max);
397 } else if constexpr (std::is_floating_point_v<ArrowCType>) {
398 array_statistics->min = static_cast<double>(min);
399 array_statistics->max = static_cast<double>(max);
400 } else if constexpr (std::is_signed_v<ArrowCType>) {
401 array_statistics->min = static_cast<int64_t>(min);
402 array_statistics->max = static_cast<int64_t>(max);
403 } else {
404 array_statistics->min = static_cast<uint64_t>(min);
405 array_statistics->max = static_cast<uint64_t>(max);
406 }
407 // We can assume that integer/floating point number/boolean
408 // based min/max are always exact if they exist. Apache
409 // Parquet's "Statistics" has "is_min_value_exact" and
410 // "is_max_value_exact" but we can ignore them for integer/
411 // floating point number/boolean based min/max.
412 //
413 // See also the discussion at dev@parquet.apache.org:
414 // https://lists.apache.org/thread/zfnmg5p51b7oylft5w5k4670wgkd4zv4
415 array_statistics->is_min_exact = true;
416 array_statistics->is_max_exact = true;
417 }
418 }
419
420 data->statistics = std::move(array_statistics);
421}
422
423template <typename ArrowType, typename ParquetType>
424Status TransferInt(RecordReader* reader,

Callers

nothing calls this directly

Calls 7

HasDistinctCountMethod · 0.80
HasMinMaxMethod · 0.80
statisticsMethod · 0.45
distinct_countMethod · 0.45
getMethod · 0.45
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected