libcudf  23.12.00
parquet.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2023, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cudf/ast/expressions.hpp>
20 #include <cudf/io/detail/parquet.hpp>
21 #include <cudf/io/types.hpp>
23 #include <cudf/types.hpp>
24 
26 
27 #include <iostream>
28 #include <memory>
29 #include <optional>
30 #include <string>
31 #include <vector>
32 
33 namespace cudf::io {
40 constexpr size_t default_row_group_size_bytes = 128 * 1024 * 1024;
42 constexpr size_t default_max_page_size_bytes = 512 * 1024;
44 constexpr int32_t default_column_index_truncate_length = 64;
45 constexpr size_t default_max_dictionary_size = 1024 * 1024;
47 
49 
54  source_info _source;
55 
56  // Path in schema of column to read; `nullopt` is all
57  std::optional<std::vector<std::string>> _columns;
58 
59  // List of individual row groups to read (ignored if empty)
60  std::vector<std::vector<size_type>> _row_groups;
61  // Number of rows to skip from the start; Parquet stores the number of rows as int64_t
62  int64_t _skip_rows = 0;
63  // Number of rows to read; `nullopt` is all
64  std::optional<size_type> _num_rows;
65 
66  // Predicate filter as AST to filter output rows.
67  std::optional<std::reference_wrapper<ast::expression const>> _filter;
68 
69  // Whether to store string data as categorical type
70  bool _convert_strings_to_categories = false;
71  // Whether to use PANDAS metadata to load columns
72  bool _use_pandas_metadata = true;
73  // Cast timestamp columns to a specific type
74  data_type _timestamp_type{type_id::EMPTY};
75 
76  std::optional<std::vector<reader_column_schema>> _reader_column_schema;
77 
83  explicit parquet_reader_options(source_info src) : _source{std::move(src)} {}
84 
86 
87  public:
93  explicit parquet_reader_options() = default;
94 
102 
108  [[nodiscard]] source_info const& get_source() const { return _source; }
109 
116  [[nodiscard]] bool is_enabled_convert_strings_to_categories() const
117  {
118  return _convert_strings_to_categories;
119  }
120 
126  [[nodiscard]] bool is_enabled_use_pandas_metadata() const { return _use_pandas_metadata; }
127 
133  [[nodiscard]] std::optional<std::vector<reader_column_schema>> get_column_schema() const
134  {
135  return _reader_column_schema;
136  }
137 
143  [[nodiscard]] int64_t get_skip_rows() const { return _skip_rows; }
144 
151  [[nodiscard]] std::optional<size_type> const& get_num_rows() const { return _num_rows; }
152 
158  [[nodiscard]] auto const& get_columns() const { return _columns; }
159 
165  [[nodiscard]] auto const& get_row_groups() const { return _row_groups; }
166 
172  [[nodiscard]] auto const& get_filter() const { return _filter; }
173 
179  data_type get_timestamp_type() const { return _timestamp_type; }
180 
186  void set_columns(std::vector<std::string> col_names) { _columns = std::move(col_names); }
187 
193  void set_row_groups(std::vector<std::vector<size_type>> row_groups);
194 
200  void set_filter(ast::expression const& filter) { _filter = filter; }
201 
207  void enable_convert_strings_to_categories(bool val) { _convert_strings_to_categories = val; }
208 
214  void enable_use_pandas_metadata(bool val) { _use_pandas_metadata = val; }
215 
222  void set_column_schema(std::vector<reader_column_schema> val)
223  {
224  _reader_column_schema = std::move(val);
225  }
226 
232  void set_skip_rows(int64_t val);
233 
240 
246  void set_timestamp_type(data_type type) { _timestamp_type = type; }
247 };
248 
253  parquet_reader_options options;
254 
255  public:
262 
268  explicit parquet_reader_options_builder(source_info src) : options{std::move(src)} {}
269 
276  parquet_reader_options_builder& columns(std::vector<std::string> col_names)
277  {
278  options._columns = std::move(col_names);
279  return *this;
280  }
281 
288  parquet_reader_options_builder& row_groups(std::vector<std::vector<size_type>> row_groups)
289  {
290  options.set_row_groups(std::move(row_groups));
291  return *this;
292  }
293 
301  {
302  options.set_filter(filter);
303  return *this;
304  }
305 
313  {
314  options._convert_strings_to_categories = val;
315  return *this;
316  }
317 
325  {
326  options._use_pandas_metadata = val;
327  return *this;
328  }
329 
336  parquet_reader_options_builder& set_column_schema(std::vector<reader_column_schema> val)
337  {
338  options._reader_column_schema = std::move(val);
339  return *this;
340  }
341 
349  {
350  options.set_skip_rows(val);
351  return *this;
352  }
353 
361  {
362  options.set_num_rows(val);
363  return *this;
364  }
365 
373  {
374  options._timestamp_type = type;
375  return *this;
376  }
377 
381  operator parquet_reader_options&&() { return std::move(options); }
382 
390  parquet_reader_options&& build() { return std::move(options); }
391 };
392 
410  parquet_reader_options const& options,
412 
423  public:
430 
444  std::size_t chunk_read_limit,
445  parquet_reader_options const& options,
447 
467  std::size_t chunk_read_limit,
468  std::size_t pass_read_limit,
469  parquet_reader_options const& options,
471 
480 
486  [[nodiscard]] bool has_next() const;
487 
499  [[nodiscard]] table_with_metadata read_chunk() const;
500 
501  private:
502  std::unique_ptr<cudf::io::parquet::detail::chunked_reader> reader;
503 };
504  // end of group
513 
518  // Specify the sink to use for writer output
519  sink_info _sink;
520  // Specify the compression format to use
522  // Specify the level of statistics in the output file
524  // Sets of columns to output
525  table_view _table;
526  // Partitions described as {start_row, num_rows} pairs
527  std::vector<partition_info> _partitions;
528  // Optional associated metadata
529  std::optional<table_input_metadata> _metadata;
530  // Optional footer key_value_metadata
531  std::vector<std::map<std::string, std::string>> _user_data;
532  // Parquet writer can write INT96 or TIMESTAMP_MICROS. Defaults to TIMESTAMP_MICROS.
533  // If true then overrides any per-column setting in _metadata.
534  bool _write_timestamps_as_int96 = false;
535  // Parquet writer can write timestamps as UTC
536  // Defaults to true because libcudf timestamps are implicitly UTC
537  bool _write_timestamps_as_UTC = true;
538  // Column chunks file paths to be set in the raw output metadata. One per output file
539  std::vector<std::string> _column_chunks_file_paths;
540  // Maximum size of each row group (unless smaller than a single page)
541  size_t _row_group_size_bytes = default_row_group_size_bytes;
542  // Maximum number of rows in row group (unless smaller than a single page)
543  size_type _row_group_size_rows = default_row_group_size_rows;
544  // Maximum size of each page (uncompressed)
545  size_t _max_page_size_bytes = default_max_page_size_bytes;
546  // Maximum number of rows in a page
547  size_type _max_page_size_rows = default_max_page_size_rows;
548  // Maximum size of min or max values in column index
549  int32_t _column_index_truncate_length = default_column_index_truncate_length;
550  // When to use dictionary encoding for data
551  dictionary_policy _dictionary_policy = dictionary_policy::ALWAYS;
552  // Maximum size of column chunk dictionary (in bytes)
553  size_t _max_dictionary_size = default_max_dictionary_size;
554  // Maximum number of rows in a page fragment
555  std::optional<size_type> _max_page_fragment_size;
556  // Optional compression statistics
557  std::shared_ptr<writer_compression_statistics> _compression_stats;
558  // write V2 page headers?
559  bool _v2_page_headers = false;
560 
567  explicit parquet_writer_options(sink_info const& sink, table_view const& table)
568  : _sink(sink), _table(table)
569  {
570  }
571 
573 
574  public:
581 
591 
598 
604  [[nodiscard]] sink_info const& get_sink() const { return _sink; }
605 
611  [[nodiscard]] compression_type get_compression() const { return _compression; }
612 
618  [[nodiscard]] statistics_freq get_stats_level() const { return _stats_level; }
619 
625  [[nodiscard]] table_view get_table() const { return _table; }
626 
632  [[nodiscard]] std::vector<partition_info> const& get_partitions() const { return _partitions; }
633 
639  [[nodiscard]] auto const& get_metadata() const { return _metadata; }
640 
646  std::vector<std::map<std::string, std::string>> const& get_key_value_metadata() const
647  {
648  return _user_data;
649  }
650 
656  bool is_enabled_int96_timestamps() const { return _write_timestamps_as_int96; }
657 
663  [[nodiscard]] auto is_enabled_utc_timestamps() const { return _write_timestamps_as_UTC; }
664 
670  std::vector<std::string> const& get_column_chunks_file_paths() const
671  {
672  return _column_chunks_file_paths;
673  }
674 
680  auto get_row_group_size_bytes() const { return _row_group_size_bytes; }
681 
687  auto get_row_group_size_rows() const { return _row_group_size_rows; }
688 
697  {
698  return std::min(_max_page_size_bytes, get_row_group_size_bytes());
699  }
700 
709  {
710  return std::min(_max_page_size_rows, get_row_group_size_rows());
711  }
712 
718  auto get_column_index_truncate_length() const { return _column_index_truncate_length; }
719 
725  [[nodiscard]] dictionary_policy get_dictionary_policy() const { return _dictionary_policy; }
726 
732  [[nodiscard]] auto get_max_dictionary_size() const { return _max_dictionary_size; }
733 
739  [[nodiscard]] auto get_max_page_fragment_size() const { return _max_page_fragment_size; }
740 
746  [[nodiscard]] std::shared_ptr<writer_compression_statistics> get_compression_statistics() const
747  {
748  return _compression_stats;
749  }
750 
756  [[nodiscard]] auto is_enabled_write_v2_headers() const { return _v2_page_headers; }
757 
764  void set_partitions(std::vector<partition_info> partitions);
765 
771  void set_metadata(table_input_metadata metadata) { _metadata = std::move(metadata); }
772 
778  void set_key_value_metadata(std::vector<std::map<std::string, std::string>> metadata);
779 
785  void set_stats_level(statistics_freq sf) { _stats_level = sf; }
786 
792  void set_compression(compression_type compression) { _compression = compression; }
793 
800  void enable_int96_timestamps(bool req) { _write_timestamps_as_int96 = req; }
801 
807  void enable_utc_timestamps(bool val) { _write_timestamps_as_UTC = val; }
808 
815  void set_column_chunks_file_paths(std::vector<std::string> file_paths);
816 
822  void set_row_group_size_bytes(size_t size_bytes);
823 
830 
836  void set_max_page_size_bytes(size_t size_bytes);
837 
844 
850  void set_column_index_truncate_length(int32_t size_bytes);
851 
858 
864  void set_max_dictionary_size(size_t size_bytes);
865 
872 
878  void set_compression_statistics(std::shared_ptr<writer_compression_statistics> comp_stats)
879  {
880  _compression_stats = std::move(comp_stats);
881  }
882 
888  void enable_write_v2_headers(bool val) { _v2_page_headers = val; }
889 };
890 
895  parquet_writer_options options;
896 
897  public:
903  explicit parquet_writer_options_builder() = default;
904 
912  : options(sink, table)
913  {
914  }
915 
923  parquet_writer_options_builder& partitions(std::vector<partition_info> partitions);
924 
932  {
933  options._metadata = std::move(metadata);
934  return *this;
935  }
936 
944  std::vector<std::map<std::string, std::string>> metadata);
945 
953  {
954  options._stats_level = sf;
955  return *this;
956  }
957 
965  {
966  options._compression = compression;
967  return *this;
968  }
969 
977  parquet_writer_options_builder& column_chunks_file_paths(std::vector<std::string> file_paths);
978 
986  {
987  options.set_row_group_size_bytes(val);
988  return *this;
989  }
990 
998  {
999  options.set_row_group_size_rows(val);
1000  return *this;
1001  }
1002 
1014  {
1015  options.set_max_page_size_bytes(val);
1016  return *this;
1017  }
1018 
1027  {
1028  options.set_max_page_size_rows(val);
1029  return *this;
1030  }
1031 
1046  {
1047  options.set_column_index_truncate_length(val);
1048  return *this;
1049  }
1050 
1069 
1082 
1094 
1102  std::shared_ptr<writer_compression_statistics> const& comp_stats)
1103  {
1104  options._compression_stats = comp_stats;
1105  return *this;
1106  }
1107 
1115  {
1116  options._write_timestamps_as_int96 = enabled;
1117  return *this;
1118  }
1119 
1127  {
1128  options._write_timestamps_as_UTC = enabled;
1129  return *this;
1130  }
1131 
1139 
1143  operator parquet_writer_options&&() { return std::move(options); }
1144 
1152  parquet_writer_options&& build() { return std::move(options); }
1153 };
1154 
1170 std::unique_ptr<std::vector<uint8_t>> write_parquet(parquet_writer_options const& options);
1171 
1181 std::unique_ptr<std::vector<uint8_t>> merge_row_group_metadata(
1182  std::vector<std::unique_ptr<std::vector<uint8_t>>> const& metadata_list);
1183 
1185 
1190  // Specify the sink to use for writer output
1191  sink_info _sink;
1192  // Specify the compression format to use
1194  // Specify the level of statistics in the output file
1196  // Optional associated metadata.
1197  std::optional<table_input_metadata> _metadata;
1198  // Optional footer key_value_metadata
1199  std::vector<std::map<std::string, std::string>> _user_data;
1200  // Parquet writer can write INT96 or TIMESTAMP_MICROS. Defaults to TIMESTAMP_MICROS.
1201  // If true then overrides any per-column setting in _metadata.
1202  bool _write_timestamps_as_int96 = false;
1203  // Parquet writer can write timestamps as UTC. Defaults to true.
1204  bool _write_timestamps_as_UTC = true;
1205  // Maximum size of each row group (unless smaller than a single page)
1206  size_t _row_group_size_bytes = default_row_group_size_bytes;
1207  // Maximum number of rows in row group (unless smaller than a single page)
1208  size_type _row_group_size_rows = default_row_group_size_rows;
1209  // Maximum size of each page (uncompressed)
1210  size_t _max_page_size_bytes = default_max_page_size_bytes;
1211  // Maximum number of rows in a page
1212  size_type _max_page_size_rows = default_max_page_size_rows;
1213  // Maximum size of min or max values in column index
1214  int32_t _column_index_truncate_length = default_column_index_truncate_length;
1215  // When to use dictionary encoding for data
1216  dictionary_policy _dictionary_policy = dictionary_policy::ALWAYS;
1217  // Maximum size of column chunk dictionary (in bytes)
1218  size_t _max_dictionary_size = default_max_dictionary_size;
1219  // Maximum number of rows in a page fragment
1220  std::optional<size_type> _max_page_fragment_size;
1221  // Optional compression statistics
1222  std::shared_ptr<writer_compression_statistics> _compression_stats;
1223  // write V2 page headers?
1224  bool _v2_page_headers = false;
1225 
1231  explicit chunked_parquet_writer_options(sink_info const& sink) : _sink(sink) {}
1232 
1234 
1235  public:
1242 
1248  [[nodiscard]] sink_info const& get_sink() const { return _sink; }
1249 
1255  [[nodiscard]] compression_type get_compression() const { return _compression; }
1256 
1262  [[nodiscard]] statistics_freq get_stats_level() const { return _stats_level; }
1263 
1269  [[nodiscard]] auto const& get_metadata() const { return _metadata; }
1270 
1276  std::vector<std::map<std::string, std::string>> const& get_key_value_metadata() const
1277  {
1278  return _user_data;
1279  }
1280 
1286  bool is_enabled_int96_timestamps() const { return _write_timestamps_as_int96; }
1287 
1293  [[nodiscard]] auto is_enabled_utc_timestamps() const { return _write_timestamps_as_UTC; }
1294 
1300  auto get_row_group_size_bytes() const { return _row_group_size_bytes; }
1301 
1307  auto get_row_group_size_rows() const { return _row_group_size_rows; }
1308 
1318  {
1319  return std::min(_max_page_size_bytes, get_row_group_size_bytes());
1320  }
1321 
1330  {
1331  return std::min(_max_page_size_rows, get_row_group_size_rows());
1332  }
1333 
1339  auto get_column_index_truncate_length() const { return _column_index_truncate_length; }
1340 
1346  [[nodiscard]] dictionary_policy get_dictionary_policy() const { return _dictionary_policy; }
1347 
1353  [[nodiscard]] auto get_max_dictionary_size() const { return _max_dictionary_size; }
1354 
1360  [[nodiscard]] auto get_max_page_fragment_size() const { return _max_page_fragment_size; }
1361 
1367  [[nodiscard]] std::shared_ptr<writer_compression_statistics> get_compression_statistics() const
1368  {
1369  return _compression_stats;
1370  }
1371 
1377  [[nodiscard]] auto is_enabled_write_v2_headers() const { return _v2_page_headers; }
1378 
1384  void set_metadata(table_input_metadata metadata) { _metadata = std::move(metadata); }
1385 
1391  void set_key_value_metadata(std::vector<std::map<std::string, std::string>> metadata);
1392 
1398  void set_stats_level(statistics_freq sf) { _stats_level = sf; }
1399 
1405  void set_compression(compression_type compression) { _compression = compression; }
1406 
1414  void enable_int96_timestamps(bool req) { _write_timestamps_as_int96 = req; }
1415 
1421  void enable_utc_timestamps(bool val) { _write_timestamps_as_UTC = val; }
1422 
1428  void set_row_group_size_bytes(size_t size_bytes);
1429 
1436 
1442  void set_max_page_size_bytes(size_t size_bytes);
1443 
1450 
1456  void set_column_index_truncate_length(int32_t size_bytes);
1457 
1464 
1470  void set_max_dictionary_size(size_t size_bytes);
1471 
1478 
1484  void set_compression_statistics(std::shared_ptr<writer_compression_statistics> comp_stats)
1485  {
1486  _compression_stats = std::move(comp_stats);
1487  }
1488 
1494  void enable_write_v2_headers(bool val) { _v2_page_headers = val; }
1495 
1504 };
1505 
1511 
1512  public:
1519 
1525  chunked_parquet_writer_options_builder(sink_info const& sink) : options(sink){};
1526 
1534  {
1535  options._metadata = std::move(metadata);
1536  return *this;
1537  }
1538 
1546  std::vector<std::map<std::string, std::string>> metadata);
1547 
1555  {
1556  options._stats_level = sf;
1557  return *this;
1558  }
1559 
1567  {
1568  options._compression = compression;
1569  return *this;
1570  }
1571 
1582  {
1583  options._write_timestamps_as_int96 = enabled;
1584  return *this;
1585  }
1586 
1594  {
1595  options._write_timestamps_as_UTC = enabled;
1596  return *this;
1597  }
1598 
1606 
1614  {
1615  options.set_row_group_size_bytes(val);
1616  return *this;
1617  }
1618 
1626  {
1627  options.set_row_group_size_rows(val);
1628  return *this;
1629  }
1630 
1641  {
1642  options.set_max_page_size_bytes(val);
1643  return *this;
1644  }
1645 
1654  {
1655  options.set_max_page_size_rows(val);
1656  return *this;
1657  }
1658 
1673  {
1674  options.set_column_index_truncate_length(val);
1675  return *this;
1676  }
1677 
1696 
1709 
1721 
1729  std::shared_ptr<writer_compression_statistics> const& comp_stats)
1730  {
1731  options._compression_stats = comp_stats;
1732  return *this;
1733  }
1734 
1738  operator chunked_parquet_writer_options&&() { return std::move(options); }
1739 
1747  chunked_parquet_writer_options&& build() { return std::move(options); }
1748 };
1749 
1770  public:
1776 
1783 
1796  std::vector<partition_info> const& partitions = {});
1797 
1806  std::unique_ptr<std::vector<uint8_t>> close(
1807  std::vector<std::string> const& column_chunks_file_paths = {});
1808 
1810  std::unique_ptr<parquet::detail::writer> writer;
1811 };
1812  // end of group
1814 
1815 } // namespace cudf::io
Indicator for the logical data type of an element in a column.
Definition: types.hpp:227
The chunked parquet reader class to read Parquet file iteratively in to a series of tables,...
Definition: parquet.hpp:422
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()=default
Default constructor, this should never be used.
chunked_parquet_reader(std::size_t chunk_read_limit, parquet_reader_options const &options, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Constructor for chunked reader.
chunked_parquet_reader(std::size_t chunk_read_limit, std::size_t pass_read_limit, parquet_reader_options const &options, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Constructor for chunked reader.
~chunked_parquet_reader()
Destructor, destroying the internal reader instance.
Builds options for chunked_parquet_writer_options.
Definition: parquet.hpp:1509
chunked_parquet_writer_options_builder & max_dictionary_size(size_t val)
Sets the maximum dictionary size, in bytes.
chunked_parquet_writer_options_builder & stats_level(statistics_freq sf)
Sets the level of statistics in chunked_parquet_writer_options.
Definition: parquet.hpp:1554
chunked_parquet_writer_options_builder & max_page_fragment_size(size_type val)
Sets the maximum page fragment size, in rows.
chunked_parquet_writer_options && build()
move chunked_parquet_writer_options member once it's is built.
Definition: parquet.hpp:1747
chunked_parquet_writer_options_builder & max_page_size_rows(size_type val)
Sets the maximum page size, in rows. Counts only top-level rows, ignoring any nesting....
Definition: parquet.hpp:1653
chunked_parquet_writer_options_builder & int96_timestamps(bool enabled)
Set to true if timestamps should be written as int96 types instead of int64 types....
Definition: parquet.hpp:1581
chunked_parquet_writer_options_builder()=default
Default constructor.
chunked_parquet_writer_options_builder & row_group_size_bytes(size_t val)
Sets the maximum row group size, in bytes.
Definition: parquet.hpp:1613
chunked_parquet_writer_options_builder & row_group_size_rows(size_type val)
Sets the maximum number of rows in output row groups.
Definition: parquet.hpp:1625
chunked_parquet_writer_options_builder & dictionary_policy(enum dictionary_policy val)
Sets the policy for dictionary use.
chunked_parquet_writer_options_builder & utc_timestamps(bool enabled)
Set to true if timestamps are to be written as UTC.
Definition: parquet.hpp:1593
chunked_parquet_writer_options_builder & key_value_metadata(std::vector< std::map< std::string, std::string >> metadata)
Sets Key-Value footer metadata in parquet_writer_options.
chunked_parquet_writer_options_builder & metadata(table_input_metadata metadata)
Sets metadata to chunked_parquet_writer_options.
Definition: parquet.hpp:1533
chunked_parquet_writer_options_builder & compression(compression_type compression)
Sets compression type to chunked_parquet_writer_options.
Definition: parquet.hpp:1566
chunked_parquet_writer_options_builder & compression_statistics(std::shared_ptr< writer_compression_statistics > const &comp_stats)
Sets the pointer to the output compression statistics.
Definition: parquet.hpp:1728
chunked_parquet_writer_options_builder & column_index_truncate_length(int32_t val)
Sets the desired maximum size in bytes for min and max values in the column index.
Definition: parquet.hpp:1672
chunked_parquet_writer_options_builder & write_v2_headers(bool enabled)
Set to true if V2 page headers are to be written.
chunked_parquet_writer_options_builder & max_page_size_bytes(size_t val)
Sets the maximum uncompressed page size, in bytes.
Definition: parquet.hpp:1640
chunked_parquet_writer_options_builder(sink_info const &sink)
Constructor from sink.
Definition: parquet.hpp:1525
Settings for write_parquet_chunked().
Definition: parquet.hpp:1189
std::vector< std::map< std::string, std::string > > const & get_key_value_metadata() const
Returns Key-Value footer metadata information.
Definition: parquet.hpp:1276
auto const & get_metadata() const
Returns metadata information.
Definition: parquet.hpp:1269
void set_compression_statistics(std::shared_ptr< writer_compression_statistics > comp_stats)
Sets the pointer to the output compression statistics.
Definition: parquet.hpp:1484
auto get_column_index_truncate_length() const
Returns maximum length of min or max values in column index, in bytes.
Definition: parquet.hpp:1339
auto get_max_page_fragment_size() const
Returns maximum page fragment size, in rows.
Definition: parquet.hpp:1360
void set_metadata(table_input_metadata metadata)
Sets metadata.
Definition: parquet.hpp:1384
void enable_int96_timestamps(bool req)
Sets timestamp writing preferences.
Definition: parquet.hpp:1414
static chunked_parquet_writer_options_builder builder(sink_info const &sink)
creates builder to build chunked_parquet_writer_options.
std::shared_ptr< writer_compression_statistics > get_compression_statistics() const
Returns a shared pointer to the user-provided compression statistics.
Definition: parquet.hpp:1367
void set_key_value_metadata(std::vector< std::map< std::string, std::string >> metadata)
Sets Key-Value footer metadata.
auto get_row_group_size_rows() const
Returns maximum row group size, in rows.
Definition: parquet.hpp:1307
void set_stats_level(statistics_freq sf)
Sets the level of statistics in parquet_writer_options.
Definition: parquet.hpp:1398
void set_max_page_size_rows(size_type size_rows)
Sets the maximum page size, in rows.
auto get_row_group_size_bytes() const
Returns maximum row group size, in bytes.
Definition: parquet.hpp:1300
void set_row_group_size_rows(size_type size_rows)
Sets the maximum row group size, in rows.
void enable_utc_timestamps(bool val)
Sets preference for writing timestamps as UTC. Write timestamps as UTC if set to true.
Definition: parquet.hpp:1421
auto get_max_dictionary_size() const
Returns maximum dictionary size, in bytes.
Definition: parquet.hpp:1353
void set_max_page_fragment_size(size_type size_rows)
Sets the maximum page fragment size, in rows.
auto get_max_page_size_rows() const
Returns maximum page size, in rows.
Definition: parquet.hpp:1329
dictionary_policy get_dictionary_policy() const
Returns policy for dictionary use.
Definition: parquet.hpp:1346
void set_max_page_size_bytes(size_t size_bytes)
Sets the maximum uncompressed page size, in bytes.
statistics_freq get_stats_level() const
Returns level of statistics requested in output file.
Definition: parquet.hpp:1262
auto get_max_page_size_bytes() const
Returns maximum uncompressed page size, in bytes.
Definition: parquet.hpp:1317
auto is_enabled_write_v2_headers() const
Returns true if V2 page headers should be written.
Definition: parquet.hpp:1377
bool is_enabled_int96_timestamps() const
Returns true if timestamps will be written as INT96.
Definition: parquet.hpp:1286
chunked_parquet_writer_options()=default
Default constructor.
compression_type get_compression() const
Returns compression format used.
Definition: parquet.hpp:1255
void set_column_index_truncate_length(int32_t size_bytes)
Sets the maximum length of min or max values in column index, in bytes.
void set_row_group_size_bytes(size_t size_bytes)
Sets the maximum row group size, in bytes.
void set_dictionary_policy(dictionary_policy policy)
Sets the policy for dictionary use.
void enable_write_v2_headers(bool val)
Sets preference for V2 page headers. Write V2 page headers if set to true.
Definition: parquet.hpp:1494
void set_compression(compression_type compression)
Sets compression type.
Definition: parquet.hpp:1405
void set_max_dictionary_size(size_t size_bytes)
Sets the maximum dictionary size, in bytes.
sink_info const & get_sink() const
Returns sink info.
Definition: parquet.hpp:1248
auto is_enabled_utc_timestamps() const
Returns true if timestamps will be written as UTC.
Definition: parquet.hpp:1293
chunked parquet writer class to handle options and write tables in chunks.
Definition: parquet.hpp:1769
parquet_chunked_writer()=default
Default constructor, this should never be used. This is added just to satisfy cython.
std::unique_ptr< std::vector< uint8_t > > close(std::vector< std::string > const &column_chunks_file_paths={})
Finishes the chunked/streamed write process.
std::unique_ptr< parquet::detail::writer > writer
Unique pointer to impl writer class.
Definition: parquet.hpp:1810
parquet_chunked_writer & write(table_view const &table, std::vector< partition_info > const &partitions={})
Writes table to output.
parquet_chunked_writer(chunked_parquet_writer_options const &options)
Constructor with chunked writer options.
Builds parquet_reader_options to use for read_parquet().
Definition: parquet.hpp:252
parquet_reader_options_builder(source_info src)
Constructor from source info.
Definition: parquet.hpp:268
parquet_reader_options_builder & skip_rows(int64_t val)
Sets number of rows to skip.
Definition: parquet.hpp:348
parquet_reader_options_builder & columns(std::vector< std::string > col_names)
Sets names of the columns to be read.
Definition: parquet.hpp:276
parquet_reader_options_builder & timestamp_type(data_type type)
timestamp_type used to cast timestamp columns.
Definition: parquet.hpp:372
parquet_reader_options_builder & use_pandas_metadata(bool val)
Sets to enable/disable use of pandas metadata to read.
Definition: parquet.hpp:324
parquet_reader_options_builder()=default
Default constructor.
parquet_reader_options_builder & row_groups(std::vector< std::vector< size_type >> row_groups)
Sets vector of individual row groups to read.
Definition: parquet.hpp:288
parquet_reader_options_builder & set_column_schema(std::vector< reader_column_schema > val)
Sets reader metadata.
Definition: parquet.hpp:336
parquet_reader_options && build()
move parquet_reader_options member once it's built.
Definition: parquet.hpp:390
parquet_reader_options_builder & filter(ast::expression const &filter)
Sets vector of individual row groups to read.
Definition: parquet.hpp:300
parquet_reader_options_builder & num_rows(size_type val)
Sets number of rows to read.
Definition: parquet.hpp:360
parquet_reader_options_builder & convert_strings_to_categories(bool val)
Sets enable/disable conversion of strings to categories.
Definition: parquet.hpp:312
Settings for read_parquet().
Definition: parquet.hpp:53
data_type get_timestamp_type() const
Returns timestamp type used to cast timestamp columns.
Definition: parquet.hpp:179
parquet_reader_options()=default
Default constructor.
static parquet_reader_options_builder builder(source_info src)
Creates a parquet_reader_options_builder which will build parquet_reader_options.
void set_skip_rows(int64_t val)
Sets number of rows to skip.
void set_columns(std::vector< std::string > col_names)
Sets names of the columns to be read.
Definition: parquet.hpp:186
void enable_convert_strings_to_categories(bool val)
Sets to enable/disable conversion of strings to categories.
Definition: parquet.hpp:207
std::optional< std::vector< reader_column_schema > > get_column_schema() const
Returns optional tree of metadata.
Definition: parquet.hpp:133
source_info const & get_source() const
Returns source info.
Definition: parquet.hpp:108
auto const & get_row_groups() const
Returns list of individual row groups to be read.
Definition: parquet.hpp:165
std::optional< size_type > const & get_num_rows() const
Returns number of rows to read.
Definition: parquet.hpp:151
void set_row_groups(std::vector< std::vector< size_type >> row_groups)
Sets vector of individual row groups to read.
void set_num_rows(size_type val)
Sets number of rows to read.
auto const & get_columns() const
Returns names of column to be read, if set.
Definition: parquet.hpp:158
void set_timestamp_type(data_type type)
Sets timestamp_type used to cast timestamp columns.
Definition: parquet.hpp:246
bool is_enabled_convert_strings_to_categories() const
Returns true/false depending on whether strings should be converted to categories or not.
Definition: parquet.hpp:116
void enable_use_pandas_metadata(bool val)
Sets to enable/disable use of pandas metadata to read.
Definition: parquet.hpp:214
bool is_enabled_use_pandas_metadata() const
Returns true/false depending whether to use pandas metadata or not while reading.
Definition: parquet.hpp:126
void set_column_schema(std::vector< reader_column_schema > val)
Sets reader column schema.
Definition: parquet.hpp:222
void set_filter(ast::expression const &filter)
Sets AST based filter for predicate pushdown.
Definition: parquet.hpp:200
auto const & get_filter() const
Returns AST based filter for predicate pushdown.
Definition: parquet.hpp:172
int64_t get_skip_rows() const
Returns number of rows to skip from the start.
Definition: parquet.hpp:143
Class to build parquet_writer_options.
Definition: parquet.hpp:894
parquet_writer_options_builder(sink_info const &sink, table_view const &table)
Constructor from sink and table.
Definition: parquet.hpp:911
parquet_writer_options_builder & metadata(table_input_metadata metadata)
Sets metadata in parquet_writer_options.
Definition: parquet.hpp:931
parquet_writer_options_builder & dictionary_policy(enum dictionary_policy val)
Sets the policy for dictionary use.
parquet_writer_options_builder & max_page_size_bytes(size_t val)
Sets the maximum uncompressed page size, in bytes.
Definition: parquet.hpp:1013
parquet_writer_options_builder & stats_level(statistics_freq sf)
Sets the level of statistics in parquet_writer_options.
Definition: parquet.hpp:952
parquet_writer_options_builder & row_group_size_rows(size_type val)
Sets the maximum number of rows in output row groups.
Definition: parquet.hpp:997
parquet_writer_options_builder & key_value_metadata(std::vector< std::map< std::string, std::string >> metadata)
Sets Key-Value footer metadata in parquet_writer_options.
parquet_writer_options_builder()=default
Default constructor.
parquet_writer_options && build()
move parquet_writer_options member once it's built.
Definition: parquet.hpp:1152
parquet_writer_options_builder & row_group_size_bytes(size_t val)
Sets the maximum row group size, in bytes.
Definition: parquet.hpp:985
parquet_writer_options_builder & max_page_size_rows(size_type val)
Sets the maximum page size, in rows. Counts only top-level rows, ignoring any nesting....
Definition: parquet.hpp:1026
parquet_writer_options_builder & utc_timestamps(bool enabled)
Set to true if timestamps are to be written as UTC.
Definition: parquet.hpp:1126
parquet_writer_options_builder & max_page_fragment_size(size_type val)
Sets the maximum page fragment size, in rows.
parquet_writer_options_builder & compression(compression_type compression)
Sets compression type in parquet_writer_options.
Definition: parquet.hpp:964
parquet_writer_options_builder & write_v2_headers(bool enabled)
Set to true if V2 page headers are to be written.
parquet_writer_options_builder & partitions(std::vector< partition_info > partitions)
Sets partitions in parquet_writer_options.
parquet_writer_options_builder & max_dictionary_size(size_t val)
Sets the maximum dictionary size, in bytes.
parquet_writer_options_builder & compression_statistics(std::shared_ptr< writer_compression_statistics > const &comp_stats)
Sets the pointer to the output compression statistics.
Definition: parquet.hpp:1101
parquet_writer_options_builder & int96_timestamps(bool enabled)
Sets whether int96 timestamps are written or not in parquet_writer_options.
Definition: parquet.hpp:1114
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.
parquet_writer_options_builder & column_index_truncate_length(int32_t val)
Sets the desired maximum size in bytes for min and max values in the column index.
Definition: parquet.hpp:1045
Settings for write_parquet().
Definition: parquet.hpp:517
void enable_write_v2_headers(bool val)
Sets preference for V2 page headers. Write V2 page headers if set to true.
Definition: parquet.hpp:888
void set_partitions(std::vector< partition_info > partitions)
Sets partitions.
statistics_freq get_stats_level() const
Returns level of statistics requested in output file.
Definition: parquet.hpp:618
static parquet_writer_options_builder builder(sink_info const &sink, table_view const &table)
Create builder to create parquet_writer_options.
void set_dictionary_policy(dictionary_policy policy)
Sets the policy for dictionary use.
parquet_writer_options()=default
Default constructor.
auto const & get_metadata() const
Returns associated metadata.
Definition: parquet.hpp:639
std::vector< std::map< std::string, std::string > > const & get_key_value_metadata() const
Returns Key-Value footer metadata information.
Definition: parquet.hpp:646
void set_max_dictionary_size(size_t size_bytes)
Sets the maximum dictionary size, in bytes.
auto get_row_group_size_bytes() const
Returns maximum row group size, in bytes.
Definition: parquet.hpp:680
void set_max_page_fragment_size(size_type size_rows)
Sets the maximum page fragment size, in rows.
compression_type get_compression() const
Returns compression format used.
Definition: parquet.hpp:611
auto get_max_dictionary_size() const
Returns maximum dictionary size, in bytes.
Definition: parquet.hpp:732
void set_compression_statistics(std::shared_ptr< writer_compression_statistics > comp_stats)
Sets the pointer to the output compression statistics.
Definition: parquet.hpp:878
auto get_max_page_size_bytes() const
Returns the maximum uncompressed page size, in bytes.
Definition: parquet.hpp:696
bool is_enabled_int96_timestamps() const
Returns true if timestamps will be written as INT96.
Definition: parquet.hpp:656
sink_info const & get_sink() const
Returns sink info.
Definition: parquet.hpp:604
void set_compression(compression_type compression)
Sets compression type.
Definition: parquet.hpp:792
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:670
auto get_column_index_truncate_length() const
Returns maximum length of min or max values in column index, in bytes.
Definition: parquet.hpp:718
void set_max_page_size_rows(size_type size_rows)
Sets the maximum page size, in rows.
auto is_enabled_utc_timestamps() const
Returns true if timestamps will be written as UTC.
Definition: parquet.hpp:663
auto get_max_page_fragment_size() const
Returns maximum page fragment size, in rows.
Definition: parquet.hpp:739
void set_row_group_size_bytes(size_t size_bytes)
Sets the maximum row group size, in bytes.
void enable_utc_timestamps(bool val)
Sets preference for writing timestamps as UTC. Write timestamps as UTC if set to true.
Definition: parquet.hpp:807
void set_max_page_size_bytes(size_t size_bytes)
Sets the maximum uncompressed page size, in bytes.
std::shared_ptr< writer_compression_statistics > get_compression_statistics() const
Returns a shared pointer to the user-provided compression statistics.
Definition: parquet.hpp:746
void set_stats_level(statistics_freq sf)
Sets the level of statistics.
Definition: parquet.hpp:785
dictionary_policy get_dictionary_policy() const
Returns policy for dictionary use.
Definition: parquet.hpp:725
auto get_row_group_size_rows() const
Returns maximum row group size, in rows.
Definition: parquet.hpp:687
table_view get_table() const
Returns table_view.
Definition: parquet.hpp:625
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.
void enable_int96_timestamps(bool req)
Sets timestamp writing preferences. INT96 timestamps will be written if true and TIMESTAMP_MICROS wil...
Definition: parquet.hpp:800
auto is_enabled_write_v2_headers() const
Returns true if V2 page headers should be written.
Definition: parquet.hpp:756
void set_row_group_size_rows(size_type size_rows)
Sets the maximum row group size, in rows.
void set_key_value_metadata(std::vector< std::map< std::string, std::string >> metadata)
Sets metadata.
auto get_max_page_size_rows() const
Returns maximum page size, in rows.
Definition: parquet.hpp:708
void set_metadata(table_input_metadata metadata)
Sets metadata.
Definition: parquet.hpp:771
void set_column_index_truncate_length(int32_t size_bytes)
Sets the maximum length of min or max values in column index, in bytes.
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:632
Metadata for a table.
Definition: io/types.hpp:803
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:187
A set of cudf::column's of the same size.
Definition: table.hpp:40
constexpr size_type default_row_group_size_rows
1 million rows per row group
Definition: parquet.hpp:41
constexpr int32_t default_column_index_truncate_length
truncate to 64 bytes
Definition: parquet.hpp:44
constexpr size_t default_row_group_size_bytes
128MB per row group
Definition: parquet.hpp:40
table_with_metadata read_parquet(parquet_reader_options const &options, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Reads a Parquet dataset into a set of columns.
constexpr size_type default_max_page_fragment_size
5000 rows per page fragment
Definition: parquet.hpp:46
constexpr size_t default_max_dictionary_size
1MB dictionary size
Definition: parquet.hpp:45
constexpr size_t default_max_page_size_bytes
512KB per page
Definition: parquet.hpp:42
constexpr size_type default_max_page_size_rows
20k rows per page
Definition: parquet.hpp:43
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)
Writes a set of columns to parquet format.
device_memory_resource * get_current_device_resource()
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:80
@ EMPTY
Always null with no underlying data.
cuDF-IO API type definitions
IO interfaces.
compression_type
Compression algorithms.
Definition: io/types.hpp:50
@ SNAPPY
Snappy format, using byte-oriented LZ77.
@ AUTO
Automatically detect or select compression format.
statistics_freq
Column statistics granularity type for parquet/orc writers.
Definition: io/types.hpp:89
@ STATISTICS_ROWGROUP
Per-Rowgroup column statistics.
Definition: io/types.hpp:91
dictionary_policy
Control use of dictionary encoding for parquet writer.
Definition: io/types.hpp:197
@ ALWAYS
Use dictionary regardless of impact on compression.
Definition: io/types.hpp:200
A generic expression that can be evaluated to return a value.
Definition: expressions.hpp:41
Destination information for write interfaces.
Definition: io/types.hpp:463
Source information for read interfaces.
Definition: io/types.hpp:288
Table with table metadata used by io readers to return the metadata by value.
Definition: io/types.hpp:243
Class definitions for (mutable)_table_view
Type declarations for libcudf.