hybrid_scan.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cudf/io/parquet.hpp>
11 #include <cudf/io/types.hpp>
12 #include <cudf/types.hpp>
13 #include <cudf/utilities/export.hpp>
14 
15 #include <rmm/resource_ref.hpp>
16 
17 #include <cuda/stream>
18 
19 #include <memory>
20 #include <span>
21 #include <utility>
22 #include <vector>
23 
29 namespace cudf::io::parquet::experimental::detail {
34 class hybrid_scan_reader_impl;
35 
39 class aggregate_reader_metadata;
40 } // namespace cudf::io::parquet::experimental::detail
41 
44 
45 namespace CUDF_EXPORT cudf {
46 namespace io::parquet::experimental {
56 enum class use_data_page_mask : bool {
57  YES = true,
58  NO = false
59 };
60 
82  public:
90  parquet_reader_options const& options);
91 
99 
104 
107 
113 
119 
120  private:
121  std::shared_ptr<detail::aggregate_reader_metadata> _metadata;
122  friend class hybrid_scan_reader;
123 };
124 
375  public:
384  parquet_reader_options const& options);
385 
394  parquet_reader_options const& options);
395 
404 
409 
418  [[nodiscard]] FileMetaData parquet_metadata() const;
419 
425  [[nodiscard]] byte_range_info page_index_byte_range() const;
426 
436  void setup_page_index(cudf::host_span<uint8_t const> page_index_bytes) const;
437 
444  [[nodiscard]] std::vector<size_type> all_row_groups(parquet_reader_options const& options) const;
445 
452  [[nodiscard]] std::size_t total_rows_in_row_groups(
453  std::span<size_type const> row_group_indices) const;
454 
463 
475  [[nodiscard]] std::vector<size_type> filter_row_groups_with_byte_range(
476  std::span<size_type const> row_group_indices, parquet_reader_options const& options) const;
477 
486  [[nodiscard]] std::vector<size_type> filter_row_groups_with_stats(
487  std::span<size_type const> row_group_indices,
488  parquet_reader_options const& options,
489  cuda::stream_ref stream) const;
490 
501  [[nodiscard]] std::vector<byte_range_info> bloom_filters_byte_ranges(
502  std::span<size_type const> row_group_indices, parquet_reader_options const& options) const;
503 
517  [[nodiscard]] std::vector<size_type> filter_row_groups_with_bloom_filters(
518  std::span<cudf::device_span<uint8_t const> const> bloom_filter_data,
519  std::span<size_type const> row_group_indices,
520  parquet_reader_options const& options,
521  cuda::stream_ref stream) const;
522 
530  [[nodiscard]] std::vector<byte_range_info> dictionary_pages_byte_ranges(
531  std::span<size_type const> row_group_indices, parquet_reader_options const& options) const;
532 
544  [[nodiscard]] std::vector<size_type> filter_row_groups_with_dictionary_pages(
545  std::span<cudf::device_span<uint8_t const> const> dictionary_page_data,
546  std::span<size_type const> row_group_indices,
547  parquet_reader_options const& options,
548  cuda::stream_ref stream) const;
549 
560  [[nodiscard]] std::unique_ptr<cudf::column> build_all_true_row_mask(
561  std::span<size_type const> row_group_indices,
562  cuda::stream_ref stream,
564 
576  [[nodiscard]] std::unique_ptr<cudf::column> build_row_mask_with_page_index_stats(
577  std::span<size_type const> row_group_indices,
578  parquet_reader_options const& options,
579  cuda::stream_ref stream,
581 
589  [[nodiscard]] std::vector<byte_range_info> filter_column_chunks_byte_ranges(
590  std::span<size_type const> row_group_indices, parquet_reader_options const& options) const;
591 
606  std::span<size_type const> row_group_indices,
607  std::span<cudf::device_span<uint8_t const> const> column_chunk_data,
608  cudf::mutable_column_view& row_mask,
609  use_data_page_mask mask_data_pages,
610  parquet_reader_options const& options,
611  cuda::stream_ref stream,
613 
621  [[nodiscard]] std::vector<byte_range_info> payload_column_chunks_byte_ranges(
622  std::span<size_type const> row_group_indices, parquet_reader_options const& options) const;
623 
637  std::span<size_type const> row_group_indices,
638  std::span<cudf::device_span<uint8_t const> const> column_chunk_data,
639  cudf::column_view const& row_mask,
640  use_data_page_mask mask_data_pages,
641  parquet_reader_options const& options,
642  cuda::stream_ref stream,
644 
652  [[nodiscard]] std::vector<byte_range_info> all_column_chunks_byte_ranges(
653  std::span<size_type const> row_group_indices, parquet_reader_options const& options) const;
654 
666  std::span<size_type const> row_group_indices,
667  std::span<cudf::device_span<uint8_t const> const> column_chunk_data,
668  parquet_reader_options const& options,
669  cuda::stream_ref stream,
687  std::size_t chunk_read_limit,
688  std::size_t pass_read_limit,
689  std::span<size_type const> row_group_indices,
690  cudf::column_view const& row_mask,
691  use_data_page_mask mask_data_pages,
692  std::span<cudf::device_span<uint8_t const> const> column_chunk_data,
693  parquet_reader_options const& options,
694  cuda::stream_ref stream,
696 
706  cudf::mutable_column_view& row_mask) const;
707 
724  std::size_t chunk_read_limit,
725  std::size_t pass_read_limit,
726  std::span<size_type const> row_group_indices,
727  cudf::column_view const& row_mask,
728  use_data_page_mask mask_data_pages,
729  std::span<cudf::device_span<uint8_t const> const> column_chunk_data,
730  parquet_reader_options const& options,
731  cuda::stream_ref stream,
733 
743  cudf::column_view const& row_mask) const;
744 
760  std::size_t chunk_read_limit,
761  std::size_t pass_read_limit,
762  std::span<size_type const> row_group_indices,
763  std::span<cudf::device_span<uint8_t const> const> column_chunk_data,
764  parquet_reader_options const& options,
765  cuda::stream_ref stream,
767 
774 
792  [[nodiscard]] std::vector<std::vector<cudf::size_type>> construct_row_group_passes(
793  std::span<cudf::size_type const> row_group_indices, std::size_t pass_read_limit) const;
794 
800  [[nodiscard]] bool has_next_table_chunk() const;
801 
802  private:
803  std::unique_ptr<detail::hybrid_scan_reader_impl> _impl;
804 };
805  // end of group
807 
808 } // namespace io::parquet::experimental
809 } // namespace CUDF_EXPORT cudf
Class and helper functions for specifying a byte range within a data source.
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Shareable, pre-parsed Parquet file metadata for the Hybrid Scan reader.
Definition: hybrid_scan.hpp:81
hybrid_scan_metadata(hybrid_scan_metadata &&)=default
Move constructor.
hybrid_scan_metadata & operator=(hybrid_scan_metadata const &)=default
Copy assignment operator.
~hybrid_scan_metadata()
Destructor for the shared Parquet metadata.
hybrid_scan_metadata(FileMetaData const &parquet_metadata, parquet_reader_options const &options)
Own Parquet file metadata from a pre-populated FileMetaData
hybrid_scan_metadata(hybrid_scan_metadata const &)=default
Copy constructor.
hybrid_scan_metadata(cudf::host_span< uint8_t const > footer_bytes, parquet_reader_options const &options)
Parse and own Parquet file metadata from a span of footer bytes.
hybrid_scan_metadata & operator=(hybrid_scan_metadata &&)=default
Move assignment operator.
The experimental parquet reader class to optimally read parquet files subject to highly selective fil...
std::vector< size_type > filter_row_groups_with_bloom_filters(std::span< cudf::device_span< uint8_t const > const > bloom_filter_data, std::span< size_type const > row_group_indices, parquet_reader_options const &options, cuda::stream_ref stream) const
Filter the row groups using column chunk bloom filters.
std::vector< byte_range_info > bloom_filters_byte_ranges(std::span< size_type const > row_group_indices, parquet_reader_options const &options) const
Get byte ranges of bloom filters for row group pruning.
table_with_metadata materialize_filter_columns(std::span< size_type const > row_group_indices, std::span< cudf::device_span< uint8_t const > const > column_chunk_data, cudf::mutable_column_view &row_mask, use_data_page_mask mask_data_pages, parquet_reader_options const &options, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Materializes filter columns and updates the input row mask to only the rows that exist in the output ...
std::vector< std::vector< cudf::size_type > > construct_row_group_passes(std::span< cudf::size_type const > row_group_indices, std::size_t pass_read_limit) const
Partition row groups into passes such that the amount of GPU memory required to read,...
void setup_page_index(cudf::host_span< uint8_t const > page_index_bytes) const
Setup the page index within the Parquet file metadata (FileMetaData)
byte_range_info page_index_byte_range() const
Get the byte range of the page index in the Parquet file.
table_with_metadata materialize_all_columns(std::span< size_type const > row_group_indices, std::span< cudf::device_span< uint8_t const > const > column_chunk_data, parquet_reader_options const &options, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Materializes all (or selected) columns and returns the final output table.
void setup_chunking_for_all_columns(std::size_t chunk_read_limit, std::size_t pass_read_limit, std::span< size_type const > row_group_indices, std::span< cudf::device_span< uint8_t const > const > column_chunk_data, parquet_reader_options const &options, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Setup chunking information for all (or selected) columns and preprocess the input data pages.
void setup_chunking_for_payload_columns(std::size_t chunk_read_limit, std::size_t pass_read_limit, std::span< size_type const > row_group_indices, cudf::column_view const &row_mask, use_data_page_mask mask_data_pages, std::span< cudf::device_span< uint8_t const > const > column_chunk_data, parquet_reader_options const &options, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Setup chunking information for payload columns and preprocess the input data pages.
hybrid_scan_reader(cudf::host_span< uint8_t const > footer_bytes, parquet_reader_options const &options)
Constructor for the experimental parquet reader class to optimally read Parquet files subject to high...
table_with_metadata materialize_filter_columns_chunk(cudf::mutable_column_view &row_mask) const
Materializes a chunk of filter columns and updates the corresponding range of input row mask to only ...
table_with_metadata materialize_payload_columns(std::span< size_type const > row_group_indices, std::span< cudf::device_span< uint8_t const > const > column_chunk_data, cudf::column_view const &row_mask, use_data_page_mask mask_data_pages, parquet_reader_options const &options, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Materialize payload columns and applies the row mask to the output table.
table_with_metadata materialize_payload_columns_chunk(cudf::column_view const &row_mask) const
Materializes a chunk of payload columns and applies the corresponding range of input row mask to the ...
std::unique_ptr< cudf::column > build_all_true_row_mask(std::span< size_type const > row_group_indices, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Builds a boolean (survival) column of size equal to the total number of rows in the row groups contai...
std::vector< byte_range_info > payload_column_chunks_byte_ranges(std::span< size_type const > row_group_indices, parquet_reader_options const &options) const
Get byte ranges of column chunks of payload columns.
hybrid_scan_reader(FileMetaData const &parquet_metadata, parquet_reader_options const &options)
Constructor for the experimental parquet reader class to optimally read Parquet files subject to high...
void reset_column_selection() const
Resets the current column selection.
FileMetaData parquet_metadata() const
Get the Parquet file footer metadata.
hybrid_scan_reader(hybrid_scan_metadata metadata)
Constructor that takes shared ownership of pre-parsed Parquet file metadata.
std::size_t total_rows_in_row_groups(std::span< size_type const > row_group_indices) const
Get the total number of top-level rows in the row groups.
std::vector< byte_range_info > dictionary_pages_byte_ranges(std::span< size_type const > row_group_indices, parquet_reader_options const &options) const
Get byte ranges of column chunk dictionary pages for row group pruning.
std::vector< size_type > filter_row_groups_with_dictionary_pages(std::span< cudf::device_span< uint8_t const > const > dictionary_page_data, std::span< size_type const > row_group_indices, parquet_reader_options const &options, cuda::stream_ref stream) const
Filter the row groups using column chunk dictionary pages.
std::vector< byte_range_info > all_column_chunks_byte_ranges(std::span< size_type const > row_group_indices, parquet_reader_options const &options) const
Get byte ranges of column chunks of all (or selected) columns.
std::vector< size_type > filter_row_groups_with_stats(std::span< size_type const > row_group_indices, parquet_reader_options const &options, cuda::stream_ref stream) const
Filter the input row groups using column chunk statistics.
std::vector< size_type > all_row_groups(parquet_reader_options const &options) const
Get all available row groups from the parquet file.
std::unique_ptr< cudf::column > build_row_mask_with_page_index_stats(std::span< size_type const > row_group_indices, parquet_reader_options const &options, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Builds a boolean column indicating surviving rows using page-level statistics in the page index.
void setup_chunking_for_filter_columns(std::size_t chunk_read_limit, std::size_t pass_read_limit, std::span< size_type const > row_group_indices, cudf::column_view const &row_mask, use_data_page_mask mask_data_pages, std::span< cudf::device_span< uint8_t const > const > column_chunk_data, parquet_reader_options const &options, cuda::stream_ref stream, rmm::device_async_resource_ref mr) const
Setup chunking information for filter columns and preprocess the input data pages.
bool has_next_table_chunk() const
Check if there is any parquet data left to read for the current setup.
~hybrid_scan_reader()
Destructor for the experimental parquet reader class.
std::vector< byte_range_info > filter_column_chunks_byte_ranges(std::span< size_type const > row_group_indices, parquet_reader_options const &options) const
Get byte ranges of column chunks of filter columns.
std::vector< size_type > filter_row_groups_with_byte_range(std::span< size_type const > row_group_indices, parquet_reader_options const &options) const
Filter the row groups using the specified byte range specified by [bytes_to_skip, bytes_to_skip + byt...
table_with_metadata materialize_all_columns_chunk() const
Materializes all (or selected) columns and returns the final output table.
Information about content of a parquet file.
Settings for read_parquet().
Definition: parquet.hpp:70
stores offset and size used to indicate a byte range
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
use_data_page_mask
Whether to compute and use a page mask using the row mask to skip decompression and decoding of the m...
Definition: hybrid_scan.hpp:56
@ YES
Compute and use a data page mask.
@ NO
Do not compute or use a data page mask.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
cuda::std::span< T, Extent > device_span
Device span is an alias of cuda::std::span.
Definition: span.hpp:300
Type definitions for the cuDF-IO API.
cuDF interfaces
Definition: host_udf.hpp:27
APIs for reading and writing Parquet files.
Parquet footer schema structs.
Host span, a non-owning view over a contiguous sequence of host-accessible elements.
Definition: span.hpp:65
Thrift-derived struct describing file-level metadata.
Table with table metadata used by io readers to return the metadata by value.
Definition: types.hpp:271
Type declarations for libcudf.