write_partitioned
The write_partitioned method writes a table to disk in Parquet format with partitioning columns written as key=value directories. For example, for a partitioning column Date, this creates a directory structure like Date=2021-01-01/<base_name>.parquet, Date=2021-01-02/<base_name>.parquet, etc.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| table | Union[Table, PartitionedTable] | The source table or partitioned table to write. |
| destination_dir | str | The path or URI to the destination root directory in which the partitioned Parquet data is stored. Non-existing directories in the provided path are created. |
| table_definition optional | TableDefinitionLike | The table definition to use for writing, instead of the definitions implied by the table. Default is |
| col_instructions optional | list[ColumnInstruction] | One or more optional |
| compression_codec_name optional | str | The compression codec to use. See the |
| max_dictionary_keys optional | int | The maximum number of unique dictionary keys the writer is allowed to add to a dictionary page before switching to non-dictionary encoding. If not specified, defaults to 2^20 (1,048,576). |
| max_dictionary_size optional | int | The maximum number of bytes the writer adds to the dictionary before switching to non-dictionary encoding. Only evaluated for String columns. If not specified, defaults to 2^20 (1,048,576). |
| target_page_size optional | int | The target page size in bytes. If not specified, defaults to 2^20 bytes (1 MiB). |
| base_name optional | str | The base name for the individual partitioned files. If not specified, defaults to
|
| generate_metadata_files optional | bool | Whether to generate Parquet |
| index_columns optional | Sequence[Sequence[str]] | Sequence of sequences containing the column names for indexes to persist. The write operation stores the index info as sidecar tables. For example, |
| row_group_info optional | RowGroupInfo | Requested |
| special_instructions optional | s3.S3Instructions | Special instructions for writing Parquet files to a non-local file system, like S3. Default is |
Returns
None. Writes partitioned Parquet files to the specified directory.
Examples
Note
All examples in this document write data to the /data directory in Deephaven. For more information on this directory and how it relates to your local file system, see Docker data volumes.
Write a partitioned table
In this example, write_partitioned writes a partitioned table with the X column as the partitioning key:
This creates:
Write with custom base name
In this example, write_partitioned uses a custom base name with an incrementing index:
This creates files like X=A/data-0.parquet, X=B/data-0.parquet, etc.
Write with metadata files
Generate metadata files to speed up reading:
This creates the partitioned files plus _metadata and _common_metadata files in the root directory.