parquet.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
9 #include <cudf/io/detail/parquet.hpp>
10 #include <cudf/io/types.hpp>
12 #include <cudf/types.hpp>
13 #include <cudf/utilities/export.hpp>
15 
16 #include <memory>
17 #include <optional>
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
27 namespace CUDF_EXPORT cudf {
28 namespace io {
34 constexpr size_t default_row_group_size_bytes =
35  std::numeric_limits<size_t>::max();
36 constexpr size_type default_row_group_size_rows = 1'000'000;
37 constexpr size_t default_max_page_size_bytes = 512 * 1024;
39 constexpr int32_t default_column_index_truncate_length = 64;
40 constexpr size_t default_max_dictionary_size = 1024 * 1024;
42 
52 [[nodiscard]] bool is_supported_read_parquet(compression_type compression);
53 
63 [[nodiscard]] bool is_supported_write_parquet(compression_type compression);
64 
66 
71  source_info _source;
72 
73  // Column selection options. At most one of these may be set at a time.
74 
75  // Path in schema of column names to read; `nullopt` is all
76  std::optional<std::vector<std::string>> _column_names;
77  // Indices of top-level columns to read; `nullopt` is all
78  std::optional<std::vector<cudf::size_type>> _column_indices;
79  // Parquet field IDs of columns/fields to read; `nullopt` is all
80  std::optional<std::vector<int32_t>> _column_field_ids;
81 
82  // List of individual row groups to read (ignored if empty)
83  std::vector<std::vector<size_type>> _row_groups;
84  // Number of rows to skip from the start; Parquet stores the number of rows as int64_t
85  int64_t _skip_rows = 0;
86  // Number of rows to read; `nullopt` is all
87  std::optional<int64_t> _num_rows;
88 
89  // Read row groups that start at or after this byte offset into the source
90  size_t _skip_bytes = 0;
91  // Read row groups that start before _num_bytes bytes after _skip_bytes into the source
92  std::optional<size_t> _num_bytes;
93 
94  // Predicate filter as AST to filter output rows.
95  std::optional<std::reference_wrapper<ast::expression const>> _filter;
96 
97  // Whether to store string data as categorical type
98  bool _convert_strings_to_categories = false;
99  // Whether to use PANDAS metadata to load columns
100  bool _use_pandas_metadata = true;
101  // Whether to read and use ARROW schema
102  bool _use_arrow_schema = true;
103  // Whether to allow reading matching select columns from mismatched Parquet files.
104  bool _allow_mismatched_pq_schemas = false;
105  // Whether to ignore non-existent projected columns
106  bool _ignore_missing_columns = true;
107  // Cast timestamp columns to a specific type
108  data_type _timestamp_type{type_id::EMPTY};
109  // Cast decimal columns to a specific width
110  type_id _decimal_width{type_id::EMPTY};
111  // Whether to use JIT compilation for filtering
112  bool _use_jit_filter = false;
113  // Whether column name matching is case sensitive. In case of multiple
114  // case-insensitive matches, the first matched column is selected
115  bool _case_sensitive_names = true;
116  // Whether to prepend a source file index column to the output
117  bool _prepend_source_index_column = false;
118  // Whether to prepend a file-local row index column to the output
119  bool _prepend_row_index_column = false;
120 
121  std::optional<std::vector<reader_column_schema>> _reader_column_schema;
122 
128  explicit parquet_reader_options(source_info src) : _source{std::move(src)} {}
129 
131 
132  public:
139  explicit parquet_reader_options() = default;
140 
149 
155  [[nodiscard]] source_info const& get_source() const { return _source; }
156 
162  [[nodiscard]] bool is_enabled_convert_strings_to_categories() const
163  {
164  return _convert_strings_to_categories;
165  }
166 
172  [[nodiscard]] bool is_enabled_use_pandas_metadata() const { return _use_pandas_metadata; }
173 
179  [[nodiscard]] bool is_enabled_use_arrow_schema() const { return _use_arrow_schema; }
180 
188  [[nodiscard]] bool is_enabled_allow_mismatched_pq_schemas() const
189  {
190  return _allow_mismatched_pq_schemas;
191  }
192 
200  [[nodiscard]] bool is_enabled_ignore_missing_columns() const { return _ignore_missing_columns; }
201 
207  [[nodiscard]] std::optional<std::vector<reader_column_schema>> get_column_schema() const
208  {
209  return _reader_column_schema;
210  }
211 
217  [[nodiscard]] int64_t get_skip_rows() const { return _skip_rows; }
218 
225  [[nodiscard]] std::optional<int64_t> const& get_num_rows() const { return _num_rows; }
226 
233  [[nodiscard]] size_t get_skip_bytes() const { return _skip_bytes; }
234 
241  [[nodiscard]] std::optional<size_t> const& get_num_bytes() const { return _num_bytes; }
242 
248  [[nodiscard]] [[deprecated("Use `get_column_names` instead.")]] auto const& get_columns() const
249  {
250  return _column_names;
251  }
252 
258  [[nodiscard]] auto const& get_column_names() const { return _column_names; }
259 
265  [[nodiscard]] auto const& get_column_indices() const { return _column_indices; }
266 
272  [[nodiscard]] auto const& get_column_field_ids() const { return _column_field_ids; }
273 
279  [[nodiscard]] auto const& get_row_groups() const { return _row_groups; }
280 
286  [[nodiscard]] auto const& get_filter() const { return _filter; }
287 
293  [[nodiscard]] data_type get_timestamp_type() const { return _timestamp_type; }
294 
300  [[nodiscard]] type_id get_decimal_width() const { return _decimal_width; }
301 
307  [[nodiscard]] bool is_enabled_use_jit_filter() const { return _use_jit_filter; }
308 
317  [[nodiscard]] bool is_enabled_case_sensitive_names() const { return _case_sensitive_names; }
318 
324  [[nodiscard]] bool is_enabled_prepend_source_index_column() const
325  {
326  return _prepend_source_index_column;
327  }
328 
338  [[nodiscard]] bool is_enabled_prepend_row_index_column() const
339  {
340  return _prepend_row_index_column;
341  }
342 
348  void set_source(source_info src) { _source = std::move(src); }
349 
372  [[deprecated("Use `set_column_names` instead.")]] void set_columns(
373  std::vector<std::string> column_names)
374  {
375  set_column_names(std::move(column_names));
376  }
377 
398  void set_column_names(std::vector<std::string> column_names)
399  {
400  CUDF_EXPECTS(not _column_indices.has_value(),
401  "Cannot select columns by names and indices simultaneously");
402  CUDF_EXPECTS(not _column_field_ids.has_value(),
403  "Cannot select columns by names and field IDs simultaneously");
404  _column_names = std::move(column_names);
405  }
406 
418  void set_column_indices(std::vector<cudf::size_type> col_indices)
419  {
420  CUDF_EXPECTS(not _column_names.has_value(),
421  "Cannot select columns by indices and names simultaneously");
422  CUDF_EXPECTS(not _column_field_ids.has_value(),
423  "Cannot select columns by indices and field IDs simultaneously");
424  CUDF_EXPECTS(
425  not _allow_mismatched_pq_schemas,
426  "Cannot select columns by indices and allow mismatched Parquet schemas simultaneously");
427  _column_indices = std::move(col_indices);
428  }
429 
436  void set_column_field_ids(std::vector<int32_t> column_field_ids)
437  {
438  CUDF_EXPECTS(not _column_names.has_value(),
439  "Cannot select columns by field IDs and names simultaneously");
440  CUDF_EXPECTS(not _column_indices.has_value(),
441  "Cannot select columns by field IDs and indices simultaneously");
442  _column_field_ids = std::move(column_field_ids);
443  }
444 
471  void set_row_groups(std::vector<std::vector<size_type>> row_groups);
472 
503  void set_filter(ast::expression const& filter) { _filter = filter; }
504 
510  void enable_convert_strings_to_categories(bool val) { _convert_strings_to_categories = val; }
511 
517  void enable_use_pandas_metadata(bool val) { _use_pandas_metadata = val; }
518 
524  void enable_use_arrow_schema(bool val) { _use_arrow_schema = val; }
525 
534  {
535  CUDF_EXPECTS(
536  not val or not _column_indices.has_value(),
537  "Cannot enable reading mismatched Parquet schemas when selecting columns by index");
538  _allow_mismatched_pq_schemas = val;
539  }
540 
547  void enable_ignore_missing_columns(bool val) { _ignore_missing_columns = val; }
548 
555  void set_column_schema(std::vector<reader_column_schema> val)
556  {
557  _reader_column_schema = std::move(val);
558  }
559 
565  void set_skip_rows(int64_t val);
566 
575  void set_num_rows(int64_t val);
576 
582  void set_skip_bytes(size_t val);
583 
589  void set_num_bytes(size_t val);
590 
596  void set_timestamp_type(data_type type) { _timestamp_type = type; }
597 
604  void set_decimal_width(type_id width) { _decimal_width = width; }
605 
611  void enable_use_jit_filter(bool val) { _use_jit_filter = val; }
612 
621  void enable_case_sensitive_names(bool val) { _case_sensitive_names = val; }
622 
628  void enable_prepend_source_index_column(bool val) { _prepend_source_index_column = val; }
629 
635  void enable_prepend_row_index_column(bool val) { _prepend_row_index_column = val; }
636 };
637 
642  parquet_reader_options options;
643 
644  public:
652 
658  explicit parquet_reader_options_builder(source_info src) : options{std::move(src)} {}
659 
668  [[deprecated("Use `column_names` instead.")]] parquet_reader_options_builder& columns(
669  std::vector<std::string> column_names)
670  {
671  return this->column_names(std::move(column_names));
672  }
673 
680  parquet_reader_options_builder& column_names(std::vector<std::string> column_names)
681  {
682  options.set_column_names(std::move(column_names));
683  return *this;
684  }
685 
692  parquet_reader_options_builder& column_indices(std::vector<cudf::size_type> col_indices)
693  {
694  options.set_column_indices(std::move(col_indices));
695  return *this;
696  }
697 
705  parquet_reader_options_builder& column_field_ids(std::vector<int32_t> column_field_ids)
706  {
707  options.set_column_field_ids(std::move(column_field_ids));
708  return *this;
709  }
710 
715  parquet_reader_options_builder& row_groups(std::vector<std::vector<size_type>> row_groups)
716  {
717  options.set_row_groups(std::move(row_groups));
718  return *this;
719  }
720 
726  {
727  options.set_filter(filter);
728  return *this;
729  }
730 
738  {
740  return *this;
741  }
742 
750  {
751  options.enable_use_pandas_metadata(val);
752  return *this;
753  }
754 
762  {
763  options.enable_use_arrow_schema(val);
764  return *this;
765  }
766 
777  {
779  return *this;
780  }
781 
790  {
791  options.enable_ignore_missing_columns(val);
792  return *this;
793  }
794 
801  parquet_reader_options_builder& set_column_schema(std::vector<reader_column_schema> val)
802  {
803  options.set_column_schema(std::move(val));
804  return *this;
805  }
806 
814  {
815  options.set_skip_rows(val);
816  return *this;
817  }
818 
829  {
830  options.set_num_rows(val);
831  return *this;
832  }
833 
841  {
842  options.set_skip_bytes(val);
843  return *this;
844  }
845 
853  {
854  options.set_num_bytes(val);
855  return *this;
856  }
857 
865  {
866  options.set_timestamp_type(type);
867  return *this;
868  }
869 
878  {
879  options.set_decimal_width(width);
880  return *this;
881  }
882 
890  {
891  options.enable_use_jit_filter(val);
892  return *this;
893  }
894 
905  {
906  options.enable_case_sensitive_names(val);
907  return *this;
908  }
909 
917  {
919  return *this;
920  }
921 
929  {
930  options.enable_prepend_row_index_column(val);
931  return *this;
932  }
933 
937  operator parquet_reader_options&&() { return std::move(options); }
938 
946  parquet_reader_options&& build() { return std::move(options); }
947 };
948 
970  parquet_reader_options const& options,
973 
999  std::vector<std::unique_ptr<cudf::io::datasource>>&& sources,
1000  std::vector<parquet::FileMetaData>&& parquet_metadatas,
1001  parquet_reader_options const& options,
1004 
1015  public:
1023 
1038  std::size_t chunk_read_limit,
1039  parquet_reader_options const& options,
1042 
1060  std::size_t chunk_read_limit,
1061  std::vector<std::unique_ptr<cudf::io::datasource>>&& sources,
1062  std::vector<parquet::FileMetaData>&& parquet_metadatas,
1063  parquet_reader_options const& options,
1066 
1087  std::size_t chunk_read_limit,
1088  std::size_t pass_read_limit,
1089  parquet_reader_options const& options,
1092 
1116  std::size_t chunk_read_limit,
1117  std::size_t pass_read_limit,
1118  std::vector<std::unique_ptr<cudf::io::datasource>>&& sources,
1119  std::vector<parquet::FileMetaData>&& parquet_metadatas,
1120  parquet_reader_options const& options,
1123 
1132 
1138  [[nodiscard]] bool has_next() const;
1139 
1151  [[nodiscard]] table_with_metadata read_chunk() const;
1152 
1153  private:
1154  std::unique_ptr<cudf::io::parquet::detail::chunked_reader> reader;
1155 };
1156  // end of group
1167  int column_idx{};
1168  bool is_descending{false};
1169  bool is_nulls_first{true};
1170 };
1171 
1176  // Specify the sink to use for writer output
1177  sink_info _sink;
1178  // Specify the compression format to use
1179  compression_type _compression = compression_type::SNAPPY;
1180  // Specify the level of statistics in the output file
1182  // Optional associated metadata
1183  std::optional<table_input_metadata> _metadata;
1184  // Optional footer key_value_metadata
1185  std::vector<std::map<std::string, std::string>> _user_data;
1186  // Parquet writer can write INT96 or TIMESTAMP_MICROS. Defaults to TIMESTAMP_MICROS.
1187  // If true then overrides any per-column setting in _metadata.
1188  bool _write_timestamps_as_int96 = false;
1189  // Parquet writer can write timestamps as UTC
1190  // Defaults to true because libcudf timestamps are implicitly UTC
1191  bool _write_timestamps_as_UTC = true;
1192  // Whether to write ARROW schema
1193  bool _write_arrow_schema = false;
1194  // Maximum size of each row group (unless smaller than a single page)
1195  size_t _row_group_size_bytes = default_row_group_size_bytes;
1196  // Maximum number of rows in row group (unless smaller than a single page)
1197  size_type _row_group_size_rows = default_row_group_size_rows;
1198  // Maximum size of each page (uncompressed)
1199  size_t _max_page_size_bytes = default_max_page_size_bytes;
1200  // Maximum number of rows in a page
1201  size_type _max_page_size_rows = default_max_page_size_rows;
1202  // Maximum size of min or max values in column index
1203  int32_t _column_index_truncate_length = default_column_index_truncate_length;
1204  // When to use dictionary encoding for data
1205  dictionary_policy _dictionary_policy = dictionary_policy::ADAPTIVE;
1206  // Maximum size of column chunk dictionary (in bytes)
1207  size_t _max_dictionary_size = default_max_dictionary_size;
1208  // Maximum number of rows in a page fragment
1209  std::optional<size_type> _max_page_fragment_size;
1210  // Optional compression statistics
1211  std::shared_ptr<writer_compression_statistics> _compression_stats;
1212  // write V2 page headers?
1213  bool _v2_page_headers = false;
1214  // enable per-page compression decision for V2?
1215  bool _page_level_compression = false;
1216  // Which columns in _table are used for sorting
1217  std::optional<std::vector<sorting_column>> _sorting_columns;
1218 
1219  protected:
1225  explicit parquet_writer_options_base(sink_info sink) : _sink(std::move(sink)) {}
1226 
1227  public:
1234 
1240  [[nodiscard]] sink_info const& get_sink() const { return _sink; }
1241 
1247  [[nodiscard]] compression_type get_compression() const { return _compression; }
1248 
1254  [[nodiscard]] statistics_freq get_stats_level() const { return _stats_level; }
1255 
1261  [[nodiscard]] auto const& get_metadata() const { return _metadata; }
1262 
1268  [[nodiscard]] std::vector<std::map<std::string, std::string>> const& get_key_value_metadata()
1269  const
1270  {
1271  return _user_data;
1272  }
1273 
1279  [[nodiscard]] bool is_enabled_int96_timestamps() const { return _write_timestamps_as_int96; }
1280 
1286  [[nodiscard]] auto is_enabled_utc_timestamps() const { return _write_timestamps_as_UTC; }
1287 
1293  [[nodiscard]] auto is_enabled_write_arrow_schema() const { return _write_arrow_schema; }
1294 
1300  [[nodiscard]] auto get_row_group_size_bytes() const { return _row_group_size_bytes; }
1301 
1307  [[nodiscard]] auto get_row_group_size_rows() const { return _row_group_size_rows; }
1308 
1316  [[nodiscard]] auto get_max_page_size_bytes() const
1317  {
1318  return std::min(_max_page_size_bytes, get_row_group_size_bytes());
1319  }
1320 
1328  [[nodiscard]] auto get_max_page_size_rows() const
1329  {
1330  return std::min(_max_page_size_rows, get_row_group_size_rows());
1331  }
1332 
1338  [[nodiscard]] auto get_column_index_truncate_length() const
1339  {
1340  return _column_index_truncate_length;
1341  }
1342 
1348  [[nodiscard]] dictionary_policy get_dictionary_policy() const { return _dictionary_policy; }
1349 
1355  [[nodiscard]] auto get_max_dictionary_size() const { return _max_dictionary_size; }
1356 
1362  [[nodiscard]] auto get_max_page_fragment_size() const { return _max_page_fragment_size; }
1363 
1369  [[nodiscard]] std::shared_ptr<writer_compression_statistics> get_compression_statistics() const
1370  {
1371  return _compression_stats;
1372  }
1373 
1379  [[nodiscard]] auto is_enabled_write_v2_headers() const { return _v2_page_headers; }
1380 
1390  [[nodiscard]] auto is_enabled_page_level_compression() const { return _page_level_compression; }
1391 
1397  [[nodiscard]] auto const& get_sorting_columns() const { return _sorting_columns; }
1398 
1405 
1411  void set_key_value_metadata(std::vector<std::map<std::string, std::string>> metadata);
1412 
1425 
1432  void enable_int96_timestamps(bool req);
1433 
1439  void enable_utc_timestamps(bool val);
1440 
1447 
1453  void set_row_group_size_bytes(size_t size_bytes);
1454 
1461 
1467  void set_max_page_size_bytes(size_t size_bytes);
1468 
1475 
1481  void set_column_index_truncate_length(int32_t size_bytes);
1482 
1489 
1495  void set_max_dictionary_size(size_t size_bytes);
1496 
1503 
1509  void set_compression_statistics(std::shared_ptr<writer_compression_statistics> comp_stats);
1510 
1516  void enable_write_v2_headers(bool val);
1517 
1528 
1534  void set_sorting_columns(std::vector<sorting_column> sorting_columns);
1535 };
1536 
1540 template <class BuilderT, class OptionsT>
1542  OptionsT _options;
1543 
1544  protected:
1550  inline OptionsT& get_options() { return _options; }
1551 
1557  explicit parquet_writer_options_builder_base(OptionsT options);
1558 
1559  public:
1566 
1573  BuilderT& metadata(table_input_metadata metadata);
1574 
1581  BuilderT& key_value_metadata(std::vector<std::map<std::string, std::string>> metadata);
1582 
1590 
1597  BuilderT& compression(compression_type compression);
1598 
1605  BuilderT& row_group_size_bytes(size_t val);
1606 
1614 
1625  BuilderT& max_page_size_bytes(size_t val);
1626 
1635 
1649  BuilderT& column_index_truncate_length(int32_t val);
1650 
1669 
1681  BuilderT& max_dictionary_size(size_t val);
1682 
1694 
1702  std::shared_ptr<writer_compression_statistics> const& comp_stats);
1703 
1710  BuilderT& int96_timestamps(bool enabled);
1711 
1718  BuilderT& utc_timestamps(bool enabled);
1719 
1726  BuilderT& write_arrow_schema(bool enabled);
1727 
1734  BuilderT& write_v2_headers(bool enabled);
1735 
1746  BuilderT& page_level_compression(bool enabled);
1747 
1754  BuilderT& sorting_columns(std::vector<sorting_column> sorting_columns);
1755 
1759  operator OptionsT&&();
1760 
1768  OptionsT&& build();
1769 };
1770 
1772 
1777  // Sets of columns to output
1778  table_view _table;
1779  // Partitions described as {start_row, num_rows} pairs
1780  std::vector<partition_info> _partitions;
1781  // Column chunks file paths to be set in the raw output metadata. One per output file
1782  std::vector<std::string> _column_chunks_file_paths;
1783 
1785 
1792  explicit parquet_writer_options(sink_info const& sink, table_view table);
1793 
1794  public:
1801 
1811 
1818 
1824  [[nodiscard]] table_view get_table() const { return _table; }
1825 
1831  [[nodiscard]] std::vector<partition_info> const& get_partitions() const { return _partitions; }
1832 
1838  [[nodiscard]] std::vector<std::string> const& get_column_chunks_file_paths() const
1839  {
1840  return _column_chunks_file_paths;
1841  }
1842 
1849  void set_partitions(std::vector<partition_info> partitions);
1850 
1857  void set_column_chunks_file_paths(std::vector<std::string> file_paths);
1858 };
1859 
1864  : public parquet_writer_options_builder_base<parquet_writer_options_builder,
1865  parquet_writer_options> {
1866  public:
1872  explicit parquet_writer_options_builder() = default;
1873 
1881 
1889  parquet_writer_options_builder& partitions(std::vector<partition_info> partitions);
1890 
1898  parquet_writer_options_builder& column_chunks_file_paths(std::vector<std::string> file_paths);
1899 };
1900 
1919 std::unique_ptr<std::vector<uint8_t>> write_parquet(
1921 
1931 std::unique_ptr<std::vector<uint8_t>> merge_row_group_metadata(
1932  std::vector<std::unique_ptr<std::vector<uint8_t>>> const& metadata_list);
1933 
1935 
1946 
1948 
1949  public:
1956 
1965 };
1966 
1971  : public parquet_writer_options_builder_base<chunked_parquet_writer_options_builder,
1972  chunked_parquet_writer_options> {
1973  public:
1980 
1987 };
1988 
2009  public:
2016 
2030 
2046  std::vector<partition_info> const& partitions = {});
2047 
2057  std::unique_ptr<std::vector<uint8_t>> close(
2058  std::vector<std::string> const& column_chunks_file_path = {});
2059 
2061  std::unique_ptr<parquet::detail::writer> writer;
2062 };
2063  // end of group
2065 
2066 } // namespace io
2067 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:286
The chunked parquet reader class to read Parquet file iteratively in to a series of tables,...
Definition: parquet.hpp:1014
table_with_metadata read_chunk() const
Read a chunk of rows in the given Parquet file.
bool has_next() const
Check if there is any data in the given file has not yet read.
chunked_parquet_reader(std::size_t chunk_read_limit, std::vector< std::unique_ptr< cudf::io::datasource >> &&sources, std::vector< parquet::FileMetaData > &&parquet_metadatas, parquet_reader_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Constructor for chunked reader using pre-existing Parquet datasources and file metadatas.
chunked_parquet_reader(std::size_t chunk_read_limit, std::size_t pass_read_limit, parquet_reader_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Constructor for chunked reader.
chunked_parquet_reader(std::size_t chunk_read_limit, parquet_reader_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Constructor for chunked reader.
chunked_parquet_reader(std::size_t chunk_read_limit, std::size_t pass_read_limit, std::vector< std::unique_ptr< cudf::io::datasource >> &&sources, std::vector< parquet::FileMetaData > &&parquet_metadatas, parquet_reader_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Constructor for chunked reader using pre-existing Parquet datasources and file metadatas.
~chunked_parquet_reader()
Destructor, destroying the internal reader instance.
chunked_parquet_reader()
Default constructor, this should never be used.
Class to build chunked_parquet_writer_options.
Definition: parquet.hpp:1972
chunked_parquet_writer_options_builder()=default
Default constructor.
chunked_parquet_writer_options_builder(sink_info const &sink)
Constructor from sink.
Settings for chunked_parquet_writer.
Definition: parquet.hpp:1939
static chunked_parquet_writer_options_builder builder(sink_info const &sink)
creates builder to build chunked_parquet_writer_options.
chunked_parquet_writer_options()=default
Default constructor.
chunked parquet writer class to handle options and write tables in chunks.
Definition: parquet.hpp:2008
~chunked_parquet_writer()
Default destructor. This is added to not leak detail API.
chunked_parquet_writer(chunked_parquet_writer_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream())
Constructor with chunked writer options.
std::unique_ptr< std::vector< uint8_t > > close(std::vector< std::string > const &column_chunks_file_path={})
Finishes the chunked/streamed write process.
std::unique_ptr< parquet::detail::writer > writer
Unique pointer to impl writer class.
Definition: parquet.hpp:2061
chunked_parquet_writer & write(table_view const &table, std::vector< partition_info > const &partitions={})
Writes table to output.
chunked_parquet_writer()
Default constructor, this should never be used. This is added just to satisfy cython....
Builds parquet_reader_options to use for read_parquet().
Definition: parquet.hpp:641
parquet_reader_options_builder & prepend_source_index_column(bool val)
Sets whether to prepend a source file index column to the output.
Definition: parquet.hpp:916
parquet_reader_options_builder & num_bytes(size_t val)
Sets number of bytes after skipping to end reading row groups at.
Definition: parquet.hpp:852
parquet_reader_options_builder & use_arrow_schema(bool val)
Sets to enable/disable use of arrow schema to read.
Definition: parquet.hpp:761
parquet_reader_options_builder(source_info src)
Constructor from source info.
Definition: parquet.hpp:658
parquet_reader_options_builder & decimal_width(type_id width)
Sets the decimal width used to cast decimal columns.
Definition: parquet.hpp:877
parquet_reader_options_builder & use_jit_filter(bool val)
Sets whether to use JIT for filtering.
Definition: parquet.hpp:889
parquet_reader_options_builder & skip_rows(int64_t val)
Sets number of rows to skip.
Definition: parquet.hpp:813
parquet_reader_options_builder & column_field_ids(std::vector< int32_t > column_field_ids)
Sets the Parquet field IDs of columns/fields to be read from all input sources.
Definition: parquet.hpp:705
parquet_reader_options_builder & allow_mismatched_pq_schemas(bool val)
Sets to enable/disable reading of matching projected and filter columns from mismatched Parquet sourc...
Definition: parquet.hpp:776
parquet_reader_options_builder & column_names(std::vector< std::string > column_names)
Sets names of the columns to be read.
Definition: parquet.hpp:680
parquet_reader_options_builder & ignore_missing_columns(bool val)
Sets to enable/disable ignoring of non-existent projected columns while reading.
Definition: parquet.hpp:789
parquet_reader_options_builder & skip_bytes(size_t val)
Sets bytes to skip before starting reading row groups.
Definition: parquet.hpp:840
parquet_reader_options_builder & prepend_row_index_column(bool val)
Sets whether to prepend a file-local row index column to the output.
Definition: parquet.hpp:928
parquet_reader_options_builder & timestamp_type(data_type type)
timestamp_type used to cast timestamp columns.
Definition: parquet.hpp:864
parquet_reader_options_builder & use_pandas_metadata(bool val)
Sets to enable/disable use of pandas metadata to read.
Definition: parquet.hpp:749
parquet_reader_options_builder()=default
Default constructor.
parquet_reader_options_builder & num_rows(int64_t val)
Sets number of rows to read.
Definition: parquet.hpp:828
parquet_reader_options_builder & row_groups(std::vector< std::vector< size_type >> row_groups)
Specifies which row groups to read from each input source.
Definition: parquet.hpp:715
parquet_reader_options_builder & set_column_schema(std::vector< reader_column_schema > val)
Sets reader metadata.
Definition: parquet.hpp:801
parquet_reader_options_builder & columns(std::vector< std::string > column_names)
Sets names of the columns to be read.
Definition: parquet.hpp:668
parquet_reader_options_builder & column_indices(std::vector< cudf::size_type > col_indices)
Sets the indices of top-level columns to be read from all input sources.
Definition: parquet.hpp:692
parquet_reader_options && build()
move parquet_reader_options member once it's built.
Definition: parquet.hpp:946
parquet_reader_options_builder & filter(ast::expression const &filter)
Sets AST based filter for predicate pushdown.
Definition: parquet.hpp:725
parquet_reader_options_builder & case_sensitive_names(bool val)
Sets whether column name matching is case sensitive.
Definition: parquet.hpp:904
parquet_reader_options_builder & convert_strings_to_categories(bool val)
Sets enable/disable conversion of strings to categories.
Definition: parquet.hpp:737
Settings for read_parquet().
Definition: parquet.hpp:70
data_type get_timestamp_type() const
Returns timestamp type used to cast timestamp columns.
Definition: parquet.hpp:293
parquet_reader_options()=default
Default constructor.
void enable_allow_mismatched_pq_schemas(bool val)
Sets to enable/disable reading of matching projected and filter columns from mismatched Parquet sourc...
Definition: parquet.hpp:533
void set_skip_rows(int64_t val)
Sets number of rows to skip.
bool is_enabled_use_jit_filter() const
Returns whether to use JIT compilation for filtering.
Definition: parquet.hpp:307
size_t get_skip_bytes() const
Returns bytes to skip before starting reading row groups.
Definition: parquet.hpp:233
void enable_use_jit_filter(bool val)
Sets whether to use JIT for filtering.
Definition: parquet.hpp:611
auto const & get_column_field_ids() const
Returns Parquet field IDs of columns/fields to be read, if set.
Definition: parquet.hpp:272
bool is_enabled_ignore_missing_columns() const
Returns boolean depending on whether to ignore non-existent projected columns while reading.
Definition: parquet.hpp:200
static parquet_reader_options_builder builder(source_info src=source_info{})
Creates a parquet_reader_options_builder to build parquet_reader_options. By default,...
void enable_convert_strings_to_categories(bool val)
Sets to enable/disable conversion of strings to categories.
Definition: parquet.hpp:510
std::optional< std::vector< reader_column_schema > > get_column_schema() const
Returns optional tree of metadata.
Definition: parquet.hpp:207
void set_skip_bytes(size_t val)
Sets bytes to skip before starting reading row groups.
type_id get_decimal_width() const
Returns decimal width used to cast decimal columns.
Definition: parquet.hpp:300
void set_column_indices(std::vector< cudf::size_type > col_indices)
Sets the indices of top-level columns to be read from all input sources.
Definition: parquet.hpp:418
void set_column_field_ids(std::vector< int32_t > column_field_ids)
Sets the Parquet field IDs of columns/fields to be read from all input sources.
Definition: parquet.hpp:436
source_info const & get_source() const
Returns source info.
Definition: parquet.hpp:155
auto const & get_column_indices() const
Returns indices of top-level columns to be read, if set.
Definition: parquet.hpp:265
bool is_enabled_prepend_source_index_column() const
Returns whether to prepend a source file index column to the output.
Definition: parquet.hpp:324
auto const & get_row_groups() const
Returns list of individual row groups to be read.
Definition: parquet.hpp:279
void set_decimal_width(type_id width)
Sets decimal width used to cast decimal columns.
Definition: parquet.hpp:604
void set_row_groups(std::vector< std::vector< size_type >> row_groups)
Specifies which row groups to read from each input source.
void enable_ignore_missing_columns(bool val)
Sets to enable/disable ignoring of non-existent projected columns while reading.
Definition: parquet.hpp:547
void set_source(source_info src)
Set a new source location.
Definition: parquet.hpp:348
auto const & get_columns() const
Returns names of column to be read, if set.
Definition: parquet.hpp:248
void set_timestamp_type(data_type type)
Sets timestamp_type used to cast timestamp columns.
Definition: parquet.hpp:596
void set_column_names(std::vector< std::string > column_names)
Sets the names of columns to be read from all input sources.
Definition: parquet.hpp:398
std::optional< int64_t > const & get_num_rows() const
Returns number of rows to read.
Definition: parquet.hpp:225
bool is_enabled_convert_strings_to_categories() const
Returns boolean depending on whether strings should be converted to categories.
Definition: parquet.hpp:162
void set_columns(std::vector< std::string > column_names)
Sets the names of columns to be read from all input sources.
Definition: parquet.hpp:372
void set_num_rows(int64_t val)
Sets number of rows to read.
void enable_case_sensitive_names(bool val)
Sets whether column name matching is case sensitive.
Definition: parquet.hpp:621
void set_num_bytes(size_t val)
Sets number of bytes after skipping to end reading row groups at.
void enable_use_pandas_metadata(bool val)
Sets to enable/disable use of pandas metadata to read.
Definition: parquet.hpp:517
void enable_use_arrow_schema(bool val)
Sets to enable/disable use of arrow schema to read.
Definition: parquet.hpp:524
void enable_prepend_source_index_column(bool val)
Sets whether to prepend a source file index column to the output.
Definition: parquet.hpp:628
bool is_enabled_use_pandas_metadata() const
Returns boolean depending on whether to use pandas metadata while reading.
Definition: parquet.hpp:172
bool is_enabled_allow_mismatched_pq_schemas() const
Returns boolean depending on whether to read matching projected and filter columns from mismatched Pa...
Definition: parquet.hpp:188
void set_column_schema(std::vector< reader_column_schema > val)
Sets reader column schema.
Definition: parquet.hpp:555
bool is_enabled_prepend_row_index_column() const
Returns whether to prepend a file-local row index column to the output.
Definition: parquet.hpp:338
bool is_enabled_use_arrow_schema() const
Returns boolean depending on whether to use arrow schema while reading.
Definition: parquet.hpp:179
void set_filter(ast::expression const &filter)
Sets AST based filter for predicate pushdown.
Definition: parquet.hpp:503
auto const & get_filter() const
Returns AST based filter for predicate pushdown.
Definition: parquet.hpp:286
std::optional< size_t > const & get_num_bytes() const
Returns number of bytes after skipping to end reading row groups at.
Definition: parquet.hpp:241
auto const & get_column_names() const
Returns names of column to be read, if set.
Definition: parquet.hpp:258
void enable_prepend_row_index_column(bool val)
Sets whether to prepend a file-local row index column to the output.
Definition: parquet.hpp:635
int64_t get_skip_rows() const
Returns number of rows to skip from the start.
Definition: parquet.hpp:217
bool is_enabled_case_sensitive_names() const
Returns whether column name matching is case sensitive.
Definition: parquet.hpp:317
Base settings for write_parquet() and chunked_parquet_writer.
Definition: parquet.hpp:1175
void enable_utc_timestamps(bool val)
Sets preference for writing timestamps as UTC. Write timestamps as UTC if set to true.
void enable_write_v2_headers(bool val)
Sets preference for V2 page headers. Write V2 page headers if set to true.
auto const & get_sorting_columns() const
Returns the sorting_columns.
Definition: parquet.hpp:1397
auto get_row_group_size_bytes() const
Returns maximum row group size, in bytes.
Definition: parquet.hpp:1300
bool is_enabled_int96_timestamps() const
Returns true if timestamps will be written as INT96.
Definition: parquet.hpp:1279
void set_metadata(table_input_metadata metadata)
Sets metadata.
void set_row_group_size_rows(size_type size_rows)
Sets the maximum row group size, in rows.
parquet_writer_options_base(sink_info sink)
Constructor from sink.
Definition: parquet.hpp:1225
void set_stats_level(statistics_freq sf)
Sets the level of statistics.
auto get_row_group_size_rows() const
Returns maximum row group size, in rows.
Definition: parquet.hpp:1307
parquet_writer_options_base()=default
Default constructor.
void set_max_page_size_bytes(size_t size_bytes)
Sets the maximum uncompressed page size, in bytes.
void set_sorting_columns(std::vector< sorting_column > sorting_columns)
Sets sorting columns.
auto is_enabled_write_arrow_schema() const
Returns true if arrow schema will be written.
Definition: parquet.hpp:1293
auto is_enabled_write_v2_headers() const
Returns true if V2 page headers should be written.
Definition: parquet.hpp:1379
void set_dictionary_policy(dictionary_policy policy)
Sets the policy for dictionary use.
auto get_max_page_size_bytes() const
Returns the maximum uncompressed page size, in bytes.
Definition: parquet.hpp:1316
void set_max_dictionary_size(size_t size_bytes)
Sets the maximum dictionary size, in bytes.
compression_type get_compression() const
Returns compression format used.
Definition: parquet.hpp:1247
auto get_max_dictionary_size() const
Returns maximum dictionary size, in bytes.
Definition: parquet.hpp:1355
void set_compression(compression_type compression)
Sets compression type.
dictionary_policy get_dictionary_policy() const
Returns policy for dictionary use.
Definition: parquet.hpp:1348
void set_compression_statistics(std::shared_ptr< writer_compression_statistics > comp_stats)
Sets the pointer to the output compression statistics.
std::shared_ptr< writer_compression_statistics > get_compression_statistics() const
Returns a shared pointer to the user-provided compression statistics.
Definition: parquet.hpp:1369
void set_max_page_size_rows(size_type size_rows)
Sets the maximum page size, in rows.
void enable_page_level_compression(bool val)
Sets preference for per-page compression decision in V2 pages.
auto get_max_page_fragment_size() const
Returns maximum page fragment size, in rows.
Definition: parquet.hpp:1362
void set_key_value_metadata(std::vector< std::map< std::string, std::string >> metadata)
Sets metadata.
void set_max_page_fragment_size(size_type size_rows)
Sets the maximum page fragment size, in rows.
void enable_write_arrow_schema(bool val)
Sets preference for writing arrow schema. Write arrow schema if set to true.
auto is_enabled_utc_timestamps() const
Returns true if timestamps will be written as UTC.
Definition: parquet.hpp:1286
void set_row_group_size_bytes(size_t size_bytes)
Sets the maximum row group size, in bytes.
auto is_enabled_page_level_compression() const
Returns true if per-page compression is enabled for V2 pages.
Definition: parquet.hpp:1390
void enable_int96_timestamps(bool req)
Sets timestamp writing preferences. INT96 timestamps will be written if true and TIMESTAMP_MICROS wil...
statistics_freq get_stats_level() const
Returns level of statistics requested in output file.
Definition: parquet.hpp:1254
std::vector< std::map< std::string, std::string > > const & get_key_value_metadata() const
Returns Key-Value footer metadata information.
Definition: parquet.hpp:1268
auto const & get_metadata() const
Returns associated metadata.
Definition: parquet.hpp:1261
auto get_max_page_size_rows() const
Returns maximum page size, in rows.
Definition: parquet.hpp:1328
auto get_column_index_truncate_length() const
Returns maximum length of min or max values in column index, in bytes.
Definition: parquet.hpp:1338
void set_column_index_truncate_length(int32_t size_bytes)
Sets the maximum length of min or max values in column index, in bytes.
sink_info const & get_sink() const
Returns sink info.
Definition: parquet.hpp:1240
Base class for Parquet options builders.
Definition: parquet.hpp:1541
BuilderT & compression(compression_type compression)
Sets compression type.
BuilderT & key_value_metadata(std::vector< std::map< std::string, std::string >> metadata)
Sets Key-Value footer metadata.
OptionsT & get_options()
Return reference to the options object being built.
Definition: parquet.hpp:1550
BuilderT & utc_timestamps(bool enabled)
Set to true if timestamps are to be written as UTC.
BuilderT & max_dictionary_size(size_t val)
Sets the maximum dictionary size, in bytes.
BuilderT & max_page_size_bytes(size_t val)
Sets the maximum uncompressed page size, in bytes.
OptionsT && build()
move options member once it's built.
BuilderT & stats_level(statistics_freq sf)
Sets the level of statistics.
BuilderT & column_index_truncate_length(int32_t val)
Sets the desired maximum size in bytes for min and max values in the column index.
BuilderT & compression_statistics(std::shared_ptr< writer_compression_statistics > const &comp_stats)
Sets the pointer to the output compression statistics.
BuilderT & metadata(table_input_metadata metadata)
Sets metadata.
BuilderT & dictionary_policy(enum dictionary_policy val)
Sets the policy for dictionary use.
parquet_writer_options_builder_base(OptionsT options)
Constructor from options.
BuilderT & page_level_compression(bool enabled)
Set to true to enable per-page compression decisions for V2 pages.
BuilderT & int96_timestamps(bool enabled)
Sets whether int96 timestamps are written or not.
BuilderT & row_group_size_bytes(size_t val)
Sets the maximum row group size, in bytes.
BuilderT & sorting_columns(std::vector< sorting_column > sorting_columns)
Sets column sorting metadata.
BuilderT & write_arrow_schema(bool enabled)
Set to true if arrow schema is to be written.
parquet_writer_options_builder_base()=default
Default constructor.
BuilderT & write_v2_headers(bool enabled)
Set to true if V2 page headers are to be written.
BuilderT & max_page_fragment_size(size_type val)
Sets the maximum page fragment size, in rows.
BuilderT & row_group_size_rows(size_type val)
Sets the maximum number of rows in output row groups.
BuilderT & max_page_size_rows(size_type val)
Sets the maximum page size, in rows. Counts only top-level rows, ignoring any nesting....
Class to build parquet_writer_options.
Definition: parquet.hpp:1865
parquet_writer_options_builder(sink_info const &sink, table_view const &table)
Constructor from sink and table.
parquet_writer_options_builder()=default
Default constructor.
parquet_writer_options_builder & partitions(std::vector< partition_info > partitions)
Sets partitions in parquet_writer_options.
parquet_writer_options_builder & column_chunks_file_paths(std::vector< std::string > file_paths)
Sets column chunks file path to be set in the raw output metadata.
Settings for write_parquet().
Definition: parquet.hpp:1776
void set_partitions(std::vector< partition_info > partitions)
Sets partitions.
static parquet_writer_options_builder builder(sink_info const &sink, table_view const &table)
Create builder to create parquet_writer_options.
parquet_writer_options()=default
Default constructor.
std::vector< std::string > const & get_column_chunks_file_paths() const
Returns Column chunks file paths to be set in the raw output metadata.
Definition: parquet.hpp:1838
table_view get_table() const
Returns table_view.
Definition: parquet.hpp:1824
void set_column_chunks_file_paths(std::vector< std::string > file_paths)
Sets column chunks file path to be set in the raw output metadata.
static parquet_writer_options_builder builder()
Create builder to create parquet_writer_options.
std::vector< partition_info > const & get_partitions() const
Returns partitions.
Definition: parquet.hpp:1831
Metadata for a table.
Definition: types.hpp:915
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
A set of cudf::column's of the same size.
Definition: table.hpp:31
Class definitions for building and evaluating abstract syntax tree expressions.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
table_with_metadata read_parquet(std::vector< std::unique_ptr< cudf::io::datasource >> &&sources, std::vector< parquet::FileMetaData > &&parquet_metadatas, parquet_reader_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Reads a Parquet dataset into a set of columns using pre-existing Parquet datasources and file metadat...
constexpr size_type default_row_group_size_rows
1 million rows per row group
Definition: parquet.hpp:36
constexpr int32_t default_column_index_truncate_length
truncate to 64 bytes
Definition: parquet.hpp:39
constexpr size_t default_row_group_size_bytes
Infinite bytes per row group.
Definition: parquet.hpp:34
bool is_supported_write_parquet(compression_type compression)
Check if the compression type is supported for writing Parquet files.
constexpr size_type default_max_page_fragment_size
5000 rows per page fragment
Definition: parquet.hpp:41
constexpr size_t default_max_dictionary_size
1MB dictionary size
Definition: parquet.hpp:40
bool is_supported_read_parquet(compression_type compression)
Check if the compression type is supported for reading Parquet files.
constexpr size_t default_max_page_size_bytes
512KB per page
Definition: parquet.hpp:37
constexpr size_type default_max_page_size_rows
20k rows per page
Definition: parquet.hpp:38
statistics_freq
Column statistics granularity type for parquet/orc writers.
Definition: types.hpp:85
dictionary_policy
Control use of dictionary encoding for parquet writer.
Definition: types.hpp:214
compression_type
Compression algorithms.
Definition: types.hpp:46
@ STATISTICS_ROWGROUP
Per-Rowgroup column statistics.
Definition: types.hpp:87
@ ADAPTIVE
Use dictionary when it will not impact compression.
Definition: types.hpp:216
std::unique_ptr< std::vector< uint8_t > > merge_row_group_metadata(std::vector< std::unique_ptr< std::vector< uint8_t >>> const &metadata_list)
Merges multiple raw metadata blobs that were previously created by write_parquet into a single metada...
std::unique_ptr< std::vector< uint8_t > > write_parquet(parquet_writer_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream())
Writes a set of columns to parquet format.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
std::vector< std::unique_ptr< column > > filter(std::vector< column_view > const &predicate_columns, std::string const &predicate_udf, std::vector< column_view > const &filter_columns, bool is_ptx, std::optional< void * > user_data=std::nullopt, null_aware is_null_aware=null_aware::NO, output_nullability predicate_nullability=output_nullability::PRESERVE, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new column by applying a filter function against every element of the input columns.
#define CUDF_EXPECTS(...)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
Definition: error.hpp:182
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
type_id
Identifies a column's logical element type.
Definition: types.hpp:192
Type definitions for the cuDF-IO API.
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:26
A generic expression that can be evaluated to return a value.
Definition: expressions.hpp:69
Destination information for write interfaces.
Definition: types.hpp:493
Struct used to describe column sorting metadata.
Definition: parquet.hpp:1166
Source information for read interfaces.
Definition: types.hpp:306
Table with table metadata used by io readers to return the metadata by value.
Definition: types.hpp:271
Class definitions for (mutable)_table_view
Type declarations for libcudf.