| 513 | using OnStatistics = |
| 514 | std::function<Status(const EnumeratedStatistics& enumerated_statistics)>; |
| 515 | Status EnumerateStatistics(const RecordBatch& record_batch, OnStatistics on_statistics) { |
| 516 | EnumeratedStatistics statistics; |
| 517 | statistics.nth_statistics = 0; |
| 518 | statistics.start_new_column = true; |
| 519 | statistics.nth_column = std::nullopt; |
| 520 | |
| 521 | statistics.key = ARROW_STATISTICS_KEY_ROW_COUNT_EXACT; |
| 522 | statistics.type = int64(); |
| 523 | statistics.value = record_batch.num_rows(); |
| 524 | RETURN_NOT_OK(on_statistics(statistics)); |
| 525 | statistics.start_new_column = false; |
| 526 | |
| 527 | const auto& schema = record_batch.schema(); |
| 528 | const auto num_fields = schema->num_fields(); |
| 529 | for (int nth_column = 0; nth_column < num_fields; ++nth_column) { |
| 530 | const auto& field = schema->field(nth_column); |
| 531 | auto column_statistics = record_batch.column(nth_column)->statistics(); |
| 532 | if (!column_statistics) { |
| 533 | continue; |
| 534 | } |
| 535 | |
| 536 | statistics.start_new_column = true; |
| 537 | statistics.nth_column = nth_column; |
| 538 | if (column_statistics->null_count.has_value()) { |
| 539 | statistics.nth_statistics++; |
| 540 | if (std::holds_alternative<int64_t>(column_statistics->null_count.value())) { |
| 541 | statistics.key = ARROW_STATISTICS_KEY_NULL_COUNT_EXACT; |
| 542 | statistics.type = int64(); |
| 543 | statistics.value = std::get<int64_t>(column_statistics->null_count.value()); |
| 544 | RETURN_NOT_OK(on_statistics(statistics)); |
| 545 | } else { |
| 546 | statistics.key = ARROW_STATISTICS_KEY_NULL_COUNT_APPROXIMATE; |
| 547 | statistics.type = float64(); |
| 548 | statistics.value = std::get<double>(column_statistics->null_count.value()); |
| 549 | RETURN_NOT_OK(on_statistics(statistics)); |
| 550 | } |
| 551 | statistics.start_new_column = false; |
| 552 | } |
| 553 | |
| 554 | if (column_statistics->distinct_count.has_value()) { |
| 555 | statistics.nth_statistics++; |
| 556 | if (std::holds_alternative<int64_t>(column_statistics->distinct_count.value())) { |
| 557 | statistics.key = ARROW_STATISTICS_KEY_DISTINCT_COUNT_EXACT; |
| 558 | statistics.type = int64(); |
| 559 | statistics.value = std::get<int64_t>(column_statistics->distinct_count.value()); |
| 560 | } else { |
| 561 | statistics.key = ARROW_STATISTICS_KEY_DISTINCT_COUNT_APPROXIMATE; |
| 562 | statistics.type = float64(); |
| 563 | statistics.value = std::get<double>(column_statistics->distinct_count.value()); |
| 564 | } |
| 565 | |
| 566 | RETURN_NOT_OK(on_statistics(statistics)); |
| 567 | statistics.start_new_column = false; |
| 568 | } |
| 569 | |
| 570 | if (column_statistics->max_byte_width.has_value()) { |
| 571 | statistics.nth_statistics++; |
| 572 | if (std::holds_alternative<int64_t>(column_statistics->max_byte_width.value())) { |
no test coverage detected