Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions docs/source/cpp/compute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1984,27 +1984,31 @@ Structural transforms
The output type is an Array of items for the ``FIRST``/``LAST`` options
and an Array of List of items for the ``ALL`` option.

* \(6) Extract a child value based on a sequence of indices passed in
the options. The validity bitmap of the result will be the
intersection of all intermediate validity bitmaps. For example, for
an array with type ``struct<a: int32, b: struct<c: int64, d:
float64>>``:
* \(6) Extract a child value based on a field reference passed in the
options. The reference can be a sequence of child indices (a
:class:`FieldPath`), a child field name, or a nested sequence of
these (see :class:`FieldRef`; note that a dot path such as ``"b.d"``
must first be parsed with ``FieldRef::FromDotPath``). The validity
bitmap of the result will be the intersection of all intermediate
validity bitmaps. For example, for an array with type
``struct<a: int32, b: struct<c: int64, d: float64>>``:

* An empty sequence of indices yields the original value unchanged.
* The index ``0`` yields an array of type ``int32`` whose validity
bitmap is the intersection of the bitmap for the outermost struct
and the bitmap for the child ``a``.
* The index ``1, 1`` yields an array of type ``float64`` whose
validity bitmap is the intersection of the bitmaps for the
outermost struct, for struct ``b``, and for the child ``d``.
* The index ``0`` or the field name ``"a"`` yields an array of type
``int32`` whose validity bitmap is the intersection of the bitmap
for the outermost struct and the bitmap for the child ``a``.
* The indices ``1, 1`` or the field names ``"b", "d"`` yield an
array of type ``float64`` whose validity bitmap is the
intersection of the bitmaps for the outermost struct, for struct
``b``, and for the child ``d``.

For unions, a validity bitmap is synthesized based on the type
codes. Also, the index is always the child index and not a type code.
Hence for array with type ``sparse_union<2: int32, 7: utf8>``:

* The index ``0`` yields an array of type ``int32``, which is valid
at an index *n* if and only if the child array ``a`` is valid at
index *n* and the type code at index *n* is 2.
at an index *n* if and only if the child array of type ``int32``
is valid at index *n* and the type code at index *n* is 2.
* The indices ``2`` and ``7`` are invalid.

* \(7) Output is true for each list containing a value equal to the second
Expand Down
31 changes: 31 additions & 0 deletions docs/source/python/parquet/parquet_datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ combine and write them manually:
... metadata_collector=metadata_collector
... )

If writing a partitioned dataset (i.e. with ``partition_cols``), the partition
columns are not stored in the data files themselves, but are encoded in the
directory names. The collected file metadata therefore has a schema without
the partition columns, and the schema passed to
:func:`~pyarrow.parquet.write_metadata` for the ``_metadata`` file needs to
match that:

.. code-block:: python

>>> # Write a partitioned dataset and collect metadata information of all written files
>>> metadata_collector = []
>>> root_path = "dataset_name_2"
>>> partition_cols = ["one", "two"]
>>> pq.write_to_dataset(table, root_path, partition_cols=partition_cols,
... metadata_collector=metadata_collector)

>>> # Write the ``_common_metadata`` parquet file with the schema of the
>>> # full dataset, including the partition columns
>>> pq.write_metadata(table.schema, root_path + '/_common_metadata')

>>> # Write the ``_metadata`` parquet file with row groups statistics of all
>>> # files. The data files do not include the partition columns, so those
>>> # need to be removed from the schema
>>> file_schema = table.schema
>>> for col in partition_cols:
... file_schema = file_schema.remove(file_schema.get_field_index(col))
>>> pq.write_metadata(
... file_schema, root_path + '/_metadata',
... metadata_collector=metadata_collector
... )

When not using the :func:`~pyarrow.parquet.write_to_dataset` function, but
writing the individual files of the partitioned dataset using
:func:`~pyarrow.parquet.write_table` or :class:`~pyarrow.parquet.ParquetWriter`,
Expand Down