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 to output flat string columns as DICT32 encoded columns
114  bool _output_dict_columns = false;
115  // Whether column name matching is case sensitive. In case of multiple
116  // case-insensitive matches, the first matched column is selected
117  bool _case_sensitive_names = true;
118  // Whether to prepend a source file index column to the output
119  bool _prepend_source_index_column = false;
120  // Whether to prepend a file-local row index column to the output
121  bool _prepend_row_index_column = false;
122 
123  std::optional<std::vector<reader_column_schema>> _reader_column_schema;
124 
130  explicit parquet_reader_options(source_info src) : _source{std::move(src)} {}
131 
133 
134  public:
141  explicit parquet_reader_options() = default;
142 
151 
157  [[nodiscard]] source_info const& get_source() const { return _source; }
158 
164  [[nodiscard]] bool is_enabled_convert_strings_to_categories() const
165  {
166  return _convert_strings_to_categories;
167  }
168 
174  [[nodiscard]] bool is_enabled_use_pandas_metadata() const { return _use_pandas_metadata; }
175 
181  [[nodiscard]] bool is_enabled_use_arrow_schema() const { return _use_arrow_schema; }
182 
190  [[nodiscard]] bool is_enabled_allow_mismatched_pq_schemas() const
191  {
192  return _allow_mismatched_pq_schemas;
193  }
194 
202  [[nodiscard]] bool is_enabled_ignore_missing_columns() const { return _ignore_missing_columns; }
203 
209  [[nodiscard]] std::optional<std::vector<reader_column_schema>> get_column_schema() const
210  {
211  return _reader_column_schema;
212  }
213 
219  [[nodiscard]] int64_t get_skip_rows() const { return _skip_rows; }
220 
227  [[nodiscard]] std::optional<int64_t> const& get_num_rows() const { return _num_rows; }
228 
235  [[nodiscard]] size_t get_skip_bytes() const { return _skip_bytes; }
236 
243  [[nodiscard]] std::optional<size_t> const& get_num_bytes() const { return _num_bytes; }
244 
250  [[nodiscard]] [[deprecated("Use `get_column_names` instead.")]] auto const& get_columns() const
251  {
252  return _column_names;
253  }
254 
260  [[nodiscard]] auto const& get_column_names() const { return _column_names; }
261 
267  [[nodiscard]] auto const& get_column_indices() const { return _column_indices; }
268 
274  [[nodiscard]] auto const& get_column_field_ids() const { return _column_field_ids; }
275 
281  [[nodiscard]] auto const& get_row_groups() const { return _row_groups; }
282 
288  [[nodiscard]] auto const& get_filter() const { return _filter; }
289 
295  [[nodiscard]] data_type get_timestamp_type() const { return _timestamp_type; }
296 
302  [[nodiscard]] type_id get_decimal_width() const { return _decimal_width; }
303 
309  [[nodiscard]] bool is_enabled_use_jit_filter() const { return _use_jit_filter; }
310 
319  [[nodiscard]] bool is_enabled_case_sensitive_names() const { return _case_sensitive_names; }
320 
326  [[nodiscard]] bool is_enabled_prepend_source_index_column() const
327  {
328  return _prepend_source_index_column;
329  }
330 
340  [[nodiscard]] bool is_enabled_prepend_row_index_column() const
341  {
342  return _prepend_row_index_column;
343  }
344 
357  [[nodiscard]] bool is_enabled_output_dict_columns() const { return _output_dict_columns; }
358 
364  void set_source(source_info src) { _source = std::move(src); }
365 
388  [[deprecated("Use `set_column_names` instead.")]] void set_columns(
389  std::vector<std::string> column_names)
390  {
391  set_column_names(std::move(column_names));
392  }
393 
414  void set_column_names(std::vector<std::string> column_names)
415  {
416  CUDF_EXPECTS(not _column_indices.has_value(),
417  "Cannot select columns by names and indices simultaneously");
418  CUDF_EXPECTS(not _column_field_ids.has_value(),
419  "Cannot select columns by names and field IDs simultaneously");
420  _column_names = std::move(column_names);
421  }
422 
434  void set_column_indices(std::vector<cudf::size_type> col_indices)
435  {
436  CUDF_EXPECTS(not _column_names.has_value(),
437  "Cannot select columns by indices and names simultaneously");
438  CUDF_EXPECTS(not _column_field_ids.has_value(),
439  "Cannot select columns by indices and field IDs simultaneously");
440  CUDF_EXPECTS(
441  not _allow_mismatched_pq_schemas,
442  "Cannot select columns by indices and allow mismatched Parquet schemas simultaneously");
443  _column_indices = std::move(col_indices);
444  }
445 
452  void set_column_field_ids(std::vector<int32_t> column_field_ids)
453  {
454  CUDF_EXPECTS(not _column_names.has_value(),
455  "Cannot select columns by field IDs and names simultaneously");
456  CUDF_EXPECTS(not _column_indices.has_value(),
457  "Cannot select columns by field IDs and indices simultaneously");
458  _column_field_ids = std::move(column_field_ids);
459  }
460 
487  void set_row_groups(std::vector<std::vector<size_type>> row_groups);
488 
519  void set_filter(ast::expression const& filter) { _filter = filter; }
520 
526  void enable_convert_strings_to_categories(bool val) { _convert_strings_to_categories = val; }
527 
533  void enable_use_pandas_metadata(bool val) { _use_pandas_metadata = val; }
534 
540  void enable_use_arrow_schema(bool val) { _use_arrow_schema = val; }
541 
550  {
551  CUDF_EXPECTS(
552  not val or not _column_indices.has_value(),
553  "Cannot enable reading mismatched Parquet schemas when selecting columns by index");
554  _allow_mismatched_pq_schemas = val;
555  }
556 
563  void enable_ignore_missing_columns(bool val) { _ignore_missing_columns = val; }
564 
571  void set_column_schema(std::vector<reader_column_schema> val)
572  {
573  _reader_column_schema = std::move(val);
574  }
575 
581  void set_skip_rows(int64_t val);
582 
591  void set_num_rows(int64_t val);
592 
598  void set_skip_bytes(size_t val);
599 
605  void set_num_bytes(size_t val);
606 
612  void set_timestamp_type(data_type type) { _timestamp_type = type; }
613 
620  void set_decimal_width(type_id width) { _decimal_width = width; }
621 
627  void enable_use_jit_filter(bool val) { _use_jit_filter = val; }
628 
637  void enable_case_sensitive_names(bool val) { _case_sensitive_names = val; }
638 
644  void enable_prepend_source_index_column(bool val) { _prepend_source_index_column = val; }
645 
651  void enable_prepend_row_index_column(bool val) { _prepend_row_index_column = val; }
652 
658  void enable_output_dict_columns(bool val) { _output_dict_columns = val; }
659 };
660 
665  parquet_reader_options options;
666 
667  public:
675 
681  explicit parquet_reader_options_builder(source_info src) : options{std::move(src)} {}
682 
691  [[deprecated("Use `column_names` instead.")]] parquet_reader_options_builder& columns(
692  std::vector<std::string> column_names)
693  {
694  return this->column_names(std::move(column_names));
695  }
696 
703  parquet_reader_options_builder& column_names(std::vector<std::string> column_names)
704  {
705  options.set_column_names(std::move(column_names));
706  return *this;
707  }
708 
715  parquet_reader_options_builder& column_indices(std::vector<cudf::size_type> col_indices)
716  {
717  options.set_column_indices(std::move(col_indices));
718  return *this;
719  }
720 
728  parquet_reader_options_builder& column_field_ids(std::vector<int32_t> column_field_ids)
729  {
730  options.set_column_field_ids(std::move(column_field_ids));
731  return *this;
732  }
733 
738  parquet_reader_options_builder& row_groups(std::vector<std::vector<size_type>> row_groups)
739  {
740  options.set_row_groups(std::move(row_groups));
741  return *this;
742  }
743 
749  {
750  options.set_filter(filter);
751  return *this;
752  }
753 
761  {
763  return *this;
764  }
765 
773  {
774  options.enable_use_pandas_metadata(val);
775  return *this;
776  }
777 
785  {
786  options.enable_use_arrow_schema(val);
787  return *this;
788  }
789 
800  {
802  return *this;
803  }
804 
813  {
814  options.enable_ignore_missing_columns(val);
815  return *this;
816  }
817 
824  parquet_reader_options_builder& set_column_schema(std::vector<reader_column_schema> val)
825  {
826  options.set_column_schema(std::move(val));
827  return *this;
828  }
829 
837  {
838  options.set_skip_rows(val);
839  return *this;
840  }
841 
852  {
853  options.set_num_rows(val);
854  return *this;
855  }
856 
864  {
865  options.set_skip_bytes(val);
866  return *this;
867  }
868 
876  {
877  options.set_num_bytes(val);
878  return *this;
879  }
880 
888  {
889  options.set_timestamp_type(type);
890  return *this;
891  }
892 
901  {
902  options.set_decimal_width(width);
903  return *this;
904  }
905 
913  {
914  options.enable_use_jit_filter(val);
915  return *this;
916  }
917 
928  {
929  options.enable_case_sensitive_names(val);
930  return *this;
931  }
932 
940  {
942  return *this;
943  }
944 
952  {
953  options.enable_prepend_row_index_column(val);
954  return *this;
955  }
956 
969  {
970  options.enable_output_dict_columns(val);
971  return *this;
972  }
973 
977  operator parquet_reader_options&&() { return std::move(options); }
978 
986  parquet_reader_options&& build() { return std::move(options); }
987 };
988 
1010  parquet_reader_options const& options,
1013 
1039  std::vector<std::unique_ptr<cudf::io::datasource>>&& sources,
1040  std::vector<parquet::FileMetaData>&& parquet_metadatas,
1041  parquet_reader_options const& options,
1044 
1055  public:
1063 
1078  std::size_t chunk_read_limit,
1079  parquet_reader_options const& options,
1082 
1100  std::size_t chunk_read_limit,
1101  std::vector<std::unique_ptr<cudf::io::datasource>>&& sources,
1102  std::vector<parquet::FileMetaData>&& parquet_metadatas,
1103  parquet_reader_options const& options,
1106 
1127  std::size_t chunk_read_limit,
1128  std::size_t pass_read_limit,
1129  parquet_reader_options const& options,
1132 
1156  std::size_t chunk_read_limit,
1157  std::size_t pass_read_limit,
1158  std::vector<std::unique_ptr<cudf::io::datasource>>&& sources,
1159  std::vector<parquet::FileMetaData>&& parquet_metadatas,
1160  parquet_reader_options const& options,
1163 
1172 
1178  [[nodiscard]] bool has_next() const;
1179 
1191  [[nodiscard]] table_with_metadata read_chunk() const;
1192 
1193  private:
1194  std::unique_ptr<cudf::io::parquet::detail::chunked_reader> reader;
1195 };
1196  // end of group
1207  int column_idx{};
1208  bool is_descending{false};
1209  bool is_nulls_first{true};
1210 };
1211 
1216  // Specify the sink to use for writer output
1217  sink_info _sink;
1218  // Specify the compression format to use
1219  compression_type _compression = compression_type::SNAPPY;
1220  // Specify the level of statistics in the output file
1222  // Optional associated metadata
1223  std::optional<table_input_metadata> _metadata;
1224  // Optional footer key_value_metadata
1225  std::vector<std::map<std::string, std::string>> _user_data;
1226  // Parquet writer can write INT96 or TIMESTAMP_MICROS. Defaults to TIMESTAMP_MICROS.
1227  // If true then overrides any per-column setting in _metadata.
1228  bool _write_timestamps_as_int96 = false;
1229  // Parquet writer can write timestamps as UTC
1230  // Defaults to true because libcudf timestamps are implicitly UTC
1231  bool _write_timestamps_as_UTC = true;
1232  // Whether to write ARROW schema
1233  bool _write_arrow_schema = false;
1234  // Maximum size of each row group (unless smaller than a single page)
1235  size_t _row_group_size_bytes = default_row_group_size_bytes;
1236  // Maximum number of rows in row group (unless smaller than a single page)
1237  size_type _row_group_size_rows = default_row_group_size_rows;
1238  // Maximum size of each page (uncompressed)
1239  size_t _max_page_size_bytes = default_max_page_size_bytes;
1240  // Maximum number of rows in a page
1241  size_type _max_page_size_rows = default_max_page_size_rows;
1242  // Maximum size of min or max values in column index
1243  int32_t _column_index_truncate_length = default_column_index_truncate_length;
1244  // When to use dictionary encoding for data
1245  dictionary_policy _dictionary_policy = dictionary_policy::ADAPTIVE;
1246  // Maximum size of column chunk dictionary (in bytes)
1247  size_t _max_dictionary_size = default_max_dictionary_size;
1248  // Maximum number of rows in a page fragment
1249  std::optional<size_type> _max_page_fragment_size;
1250  // Optional compression statistics
1251  std::shared_ptr<writer_compression_statistics> _compression_stats;
1252  // write V2 page headers?
1253  bool _v2_page_headers = false;
1254  // enable per-page compression decision for V2?
1255  bool _page_level_compression = false;
1256  // Which columns in _table are used for sorting
1257  std::optional<std::vector<sorting_column>> _sorting_columns;
1258 
1259  protected:
1265  explicit parquet_writer_options_base(sink_info sink) : _sink(std::move(sink)) {}
1266 
1267  public:
1274 
1280  [[nodiscard]] sink_info const& get_sink() const { return _sink; }
1281 
1287  [[nodiscard]] compression_type get_compression() const { return _compression; }
1288 
1294  [[nodiscard]] statistics_freq get_stats_level() const { return _stats_level; }
1295 
1301  [[nodiscard]] auto const& get_metadata() const { return _metadata; }
1302 
1308  [[nodiscard]] std::vector<std::map<std::string, std::string>> const& get_key_value_metadata()
1309  const
1310  {
1311  return _user_data;
1312  }
1313 
1319  [[nodiscard]] bool is_enabled_int96_timestamps() const { return _write_timestamps_as_int96; }
1320 
1326  [[nodiscard]] auto is_enabled_utc_timestamps() const { return _write_timestamps_as_UTC; }
1327 
1333  [[nodiscard]] auto is_enabled_write_arrow_schema() const { return _write_arrow_schema; }
1334 
1340  [[nodiscard]] auto get_row_group_size_bytes() const { return _row_group_size_bytes; }
1341 
1347  [[nodiscard]] auto get_row_group_size_rows() const { return _row_group_size_rows; }
1348 
1356  [[nodiscard]] auto get_max_page_size_bytes() const
1357  {
1358  return std::min(_max_page_size_bytes, get_row_group_size_bytes());
1359  }
1360 
1368  [[nodiscard]] auto get_max_page_size_rows() const
1369  {
1370  return std::min(_max_page_size_rows, get_row_group_size_rows());
1371  }
1372 
1378  [[nodiscard]] auto get_column_index_truncate_length() const
1379  {
1380  return _column_index_truncate_length;
1381  }
1382 
1388  [[nodiscard]] dictionary_policy get_dictionary_policy() const { return _dictionary_policy; }
1389 
1395  [[nodiscard]] auto get_max_dictionary_size() const { return _max_dictionary_size; }
1396 
1402  [[nodiscard]] auto get_max_page_fragment_size() const { return _max_page_fragment_size; }
1403 
1409  [[nodiscard]] std::shared_ptr<writer_compression_statistics> get_compression_statistics() const
1410  {
1411  return _compression_stats;
1412  }
1413 
1419  [[nodiscard]] auto is_enabled_write_v2_headers() const { return _v2_page_headers; }
1420 
1430  [[nodiscard]] auto is_enabled_page_level_compression() const { return _page_level_compression; }
1431 
1437  [[nodiscard]] auto const& get_sorting_columns() const { return _sorting_columns; }
1438 
1445 
1451  void set_key_value_metadata(std::vector<std::map<std::string, std::string>> metadata);
1452 
1465 
1472  void enable_int96_timestamps(bool req);
1473 
1479  void enable_utc_timestamps(bool val);
1480 
1487 
1493  void set_row_group_size_bytes(size_t size_bytes);
1494 
1501 
1507  void set_max_page_size_bytes(size_t size_bytes);
1508 
1515 
1521  void set_column_index_truncate_length(int32_t size_bytes);
1522 
1529 
1535  void set_max_dictionary_size(size_t size_bytes);
1536 
1543 
1549  void set_compression_statistics(std::shared_ptr<writer_compression_statistics> comp_stats);
1550 
1556  void enable_write_v2_headers(bool val);
1557 
1568 
1574  void set_sorting_columns(std::vector<sorting_column> sorting_columns);
1575 };
1576 
1580 template <class BuilderT, class OptionsT>
1582  OptionsT _options;
1583 
1584  protected:
1590  inline OptionsT& get_options() { return _options; }
1591 
1597  explicit parquet_writer_options_builder_base(OptionsT options);
1598 
1599  public:
1606 
1613  BuilderT& metadata(table_input_metadata metadata);
1614 
1621  BuilderT& key_value_metadata(std::vector<std::map<std::string, std::string>> metadata);
1622 
1630 
1637  BuilderT& compression(compression_type compression);
1638 
1645  BuilderT& row_group_size_bytes(size_t val);
1646 
1654 
1665  BuilderT& max_page_size_bytes(size_t val);
1666 
1675 
1689  BuilderT& column_index_truncate_length(int32_t val);
1690 
1709 
1721  BuilderT& max_dictionary_size(size_t val);
1722 
1734 
1742  std::shared_ptr<writer_compression_statistics> const& comp_stats);
1743 
1750  BuilderT& int96_timestamps(bool enabled);
1751 
1758  BuilderT& utc_timestamps(bool enabled);
1759 
1766  BuilderT& write_arrow_schema(bool enabled);
1767 
1774  BuilderT& write_v2_headers(bool enabled);
1775 
1786  BuilderT& page_level_compression(bool enabled);
1787 
1794  BuilderT& sorting_columns(std::vector<sorting_column> sorting_columns);
1795 
1799  operator OptionsT&&();
1800 
1808  OptionsT&& build();
1809 };
1810 
1812 
1817  // Sets of columns to output
1818  table_view _table;
1819  // Partitions described as {start_row, num_rows} pairs
1820  std::vector<partition_info> _partitions;
1821  // Column chunks file paths to be set in the raw output metadata. One per output file
1822  std::vector<std::string> _column_chunks_file_paths;
1823 
1825 
1832  explicit parquet_writer_options(sink_info const& sink, table_view table);
1833 
1834  public:
1841 
1851 
1858 
1864  [[nodiscard]] table_view get_table() const { return _table; }
1865 
1871  [[nodiscard]] std::vector<partition_info> const& get_partitions() const { return _partitions; }
1872 
1878  [[nodiscard]] std::vector<std::string> const& get_column_chunks_file_paths() const
1879  {
1880  return _column_chunks_file_paths;
1881  }
1882 
1889  void set_partitions(std::vector<partition_info> partitions);
1890 
1897  void set_column_chunks_file_paths(std::vector<std::string> file_paths);
1898 };
1899 
1904  : public parquet_writer_options_builder_base<parquet_writer_options_builder,
1905  parquet_writer_options> {
1906  public:
1912  explicit parquet_writer_options_builder() = default;
1913 
1921 
1929  parquet_writer_options_builder& partitions(std::vector<partition_info> partitions);
1930 
1938  parquet_writer_options_builder& column_chunks_file_paths(std::vector<std::string> file_paths);
1939 };
1940 
1959 std::unique_ptr<std::vector<uint8_t>> write_parquet(
1961 
1971 std::unique_ptr<std::vector<uint8_t>> merge_row_group_metadata(
1972  std::vector<std::unique_ptr<std::vector<uint8_t>>> const& metadata_list);
1973 
1975 
1986 
1988 
1989  public:
1996 
2005 };
2006 
2011  : public parquet_writer_options_builder_base<chunked_parquet_writer_options_builder,
2012  chunked_parquet_writer_options> {
2013  public:
2020 
2027 };
2028 
2049  public:
2056 
2070 
2086  std::vector<partition_info> const& partitions = {});
2087 
2097  std::unique_ptr<std::vector<uint8_t>> close(
2098  std::vector<std::string> const& column_chunks_file_path = {});
2099 
2101  std::unique_ptr<parquet::detail::writer> writer;
2102 };
2103  // end of group
2105 
2106 } // namespace io
2107 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:278
The chunked parquet reader class to read Parquet file iteratively in to a series of tables,...
Definition: parquet.hpp:1054
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:2012
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:1979
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:2048
~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:2101
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:664
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:939
parquet_reader_options_builder & num_bytes(size_t val)
Sets number of bytes after skipping to end reading row groups at.
Definition: parquet.hpp:875
parquet_reader_options_builder & use_arrow_schema(bool val)
Sets to enable/disable use of arrow schema to read.
Definition: parquet.hpp:784
parquet_reader_options_builder(source_info src)
Constructor from source info.
Definition: parquet.hpp:681
parquet_reader_options_builder & decimal_width(type_id width)
Sets the decimal width used to cast decimal columns.
Definition: parquet.hpp:900
parquet_reader_options_builder & use_jit_filter(bool val)
Sets whether to use JIT for filtering.
Definition: parquet.hpp:912
parquet_reader_options_builder & skip_rows(int64_t val)
Sets number of rows to skip.
Definition: parquet.hpp:836
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:728
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:799
parquet_reader_options_builder & column_names(std::vector< std::string > column_names)
Sets names of the columns to be read.
Definition: parquet.hpp:703
parquet_reader_options_builder & ignore_missing_columns(bool val)
Sets to enable/disable ignoring of non-existent projected columns while reading.
Definition: parquet.hpp:812
parquet_reader_options_builder & skip_bytes(size_t val)
Sets bytes to skip before starting reading row groups.
Definition: parquet.hpp:863
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:951
parquet_reader_options_builder & output_dict_columns(bool val)
Sets options for enabling/disabling output of DICTIONARY32 columns for flat string columns.
Definition: parquet.hpp:968
parquet_reader_options_builder & timestamp_type(data_type type)
timestamp_type used to cast timestamp columns.
Definition: parquet.hpp:887
parquet_reader_options_builder & use_pandas_metadata(bool val)
Sets to enable/disable use of pandas metadata to read.
Definition: parquet.hpp:772
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:851
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:738
parquet_reader_options_builder & set_column_schema(std::vector< reader_column_schema > val)
Sets reader metadata.
Definition: parquet.hpp:824
parquet_reader_options_builder & columns(std::vector< std::string > column_names)
Sets names of the columns to be read.
Definition: parquet.hpp:691
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:715
parquet_reader_options && build()
move parquet_reader_options member once it's built.
Definition: parquet.hpp:986
parquet_reader_options_builder & filter(ast::expression const &filter)
Sets AST based filter for predicate pushdown.
Definition: parquet.hpp:748
parquet_reader_options_builder & case_sensitive_names(bool val)
Sets whether column name matching is case sensitive.
Definition: parquet.hpp:927
parquet_reader_options_builder & convert_strings_to_categories(bool val)
Sets enable/disable conversion of strings to categories.
Definition: parquet.hpp:760
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:295
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:549
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:309
size_t get_skip_bytes() const
Returns bytes to skip before starting reading row groups.
Definition: parquet.hpp:235
void enable_use_jit_filter(bool val)
Sets whether to use JIT for filtering.
Definition: parquet.hpp:627
auto const & get_column_field_ids() const
Returns Parquet field IDs of columns/fields to be read, if set.
Definition: parquet.hpp:274
bool is_enabled_ignore_missing_columns() const
Returns boolean depending on whether to ignore non-existent projected columns while reading.
Definition: parquet.hpp:202
void enable_output_dict_columns(bool val)
Sets to enable/disable trying to output DICTIONARY32 columns for flat string columns.
Definition: parquet.hpp:658
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:526
std::optional< std::vector< reader_column_schema > > get_column_schema() const
Returns optional tree of metadata.
Definition: parquet.hpp:209
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:302
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:434
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:452
source_info const & get_source() const
Returns source info.
Definition: parquet.hpp:157
auto const & get_column_indices() const
Returns indices of top-level columns to be read, if set.
Definition: parquet.hpp:267
bool is_enabled_prepend_source_index_column() const
Returns whether to prepend a source file index column to the output.
Definition: parquet.hpp:326
auto const & get_row_groups() const
Returns list of individual row groups to be read.
Definition: parquet.hpp:281
void set_decimal_width(type_id width)
Sets decimal width used to cast decimal columns.
Definition: parquet.hpp:620
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:563
void set_source(source_info src)
Set a new source location.
Definition: parquet.hpp:364
auto const & get_columns() const
Returns names of column to be read, if set.
Definition: parquet.hpp:250
void set_timestamp_type(data_type type)
Sets timestamp_type used to cast timestamp columns.
Definition: parquet.hpp:612
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:414
std::optional< int64_t > const & get_num_rows() const
Returns number of rows to read.
Definition: parquet.hpp:227
bool is_enabled_convert_strings_to_categories() const
Returns boolean depending on whether strings should be converted to categories.
Definition: parquet.hpp:164
void set_columns(std::vector< std::string > column_names)
Sets the names of columns to be read from all input sources.
Definition: parquet.hpp:388
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:637
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:533
void enable_use_arrow_schema(bool val)
Sets to enable/disable use of arrow schema to read.
Definition: parquet.hpp:540
void enable_prepend_source_index_column(bool val)
Sets whether to prepend a source file index column to the output.
Definition: parquet.hpp:644
bool is_enabled_output_dict_columns() const
Returns whether the reader returns flat string columns as DICTIONARY32 encoded columns.
Definition: parquet.hpp:357
bool is_enabled_use_pandas_metadata() const
Returns boolean depending on whether to use pandas metadata while reading.
Definition: parquet.hpp:174
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:190
void set_column_schema(std::vector< reader_column_schema > val)
Sets reader column schema.
Definition: parquet.hpp:571
bool is_enabled_prepend_row_index_column() const
Returns whether to prepend a file-local row index column to the output.
Definition: parquet.hpp:340
bool is_enabled_use_arrow_schema() const
Returns boolean depending on whether to use arrow schema while reading.
Definition: parquet.hpp:181
void set_filter(ast::expression const &filter)
Sets AST based filter for predicate pushdown.
Definition: parquet.hpp:519
auto const & get_filter() const
Returns AST based filter for predicate pushdown.
Definition: parquet.hpp:288
std::optional< size_t > const & get_num_bytes() const
Returns number of bytes after skipping to end reading row groups at.
Definition: parquet.hpp:243
auto const & get_column_names() const
Returns names of column to be read, if set.
Definition: parquet.hpp:260
void enable_prepend_row_index_column(bool val)
Sets whether to prepend a file-local row index column to the output.
Definition: parquet.hpp:651
int64_t get_skip_rows() const
Returns number of rows to skip from the start.
Definition: parquet.hpp:219
bool is_enabled_case_sensitive_names() const
Returns whether column name matching is case sensitive.
Definition: parquet.hpp:319
Base settings for write_parquet() and chunked_parquet_writer.
Definition: parquet.hpp:1215
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:1437
auto get_row_group_size_bytes() const
Returns maximum row group size, in bytes.
Definition: parquet.hpp:1340
bool is_enabled_int96_timestamps() const
Returns true if timestamps will be written as INT96.
Definition: parquet.hpp:1319
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:1265
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:1347
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:1333
auto is_enabled_write_v2_headers() const
Returns true if V2 page headers should be written.
Definition: parquet.hpp:1419
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:1356
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:1287
auto get_max_dictionary_size() const
Returns maximum dictionary size, in bytes.
Definition: parquet.hpp:1395
void set_compression(compression_type compression)
Sets compression type.
dictionary_policy get_dictionary_policy() const
Returns policy for dictionary use.
Definition: parquet.hpp:1388
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:1409
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:1402
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:1326
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:1430
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:1294
std::vector< std::map< std::string, std::string > > const & get_key_value_metadata() const
Returns Key-Value footer metadata information.
Definition: parquet.hpp:1308
auto const & get_metadata() const
Returns associated metadata.
Definition: parquet.hpp:1301
auto get_max_page_size_rows() const
Returns maximum page size, in rows.
Definition: parquet.hpp:1368
auto get_column_index_truncate_length() const
Returns maximum length of min or max values in column index, in bytes.
Definition: parquet.hpp:1378
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:1280
Base class for Parquet options builders.
Definition: parquet.hpp:1581
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:1590
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:1905
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:1816
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:1878
table_view get_table() const
Returns table_view.
Definition: parquet.hpp:1864
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:1871
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:76
type_id
Identifies a column's logical element type.
Definition: types.hpp:184
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:1206
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.