---
sidebar:
  hidden: true
title: roboto.formats.parquet.table_transforms
---
## Module Contents

### compute_time_filter_mask()

```python
def roboto.formats.parquet.table_transforms.compute_time_filter_mask(
    timestamps: pyarrow.Array,
    start_time: Optional[int] = None,
    end_time: Optional[int] = None,
) -> Optional[pyarrow.BooleanArray]
```

`from roboto.formats.parquet import compute_time_filter_mask`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L23-L59)

Build a mask that selects the rows whose timestamps fall in a time range.

Methods such as [`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) read a topic's data from Parquet files through it, so most code never calls it.

**Parameters**

- **timestamps** (`pyarrow.Array`): Each row's timestamp, in nanoseconds since the Unix epoch, as `extract_timestamps` returns them.
- **start_time** (`Optional[int]`): Inclusive start of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded below.
- **end_time** (`Optional[int]`): Exclusive end of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded above.

**Returns**

- `Optional[pyarrow.BooleanArray]`: One entry per row: true when its timestamp is in the range, and null when its timestamp is null, which `pyarrow.compute.filter` drops by default. `None` when both `start_time` and `end_time` are `None`.

### extract_timestamp_field()

```python
def roboto.formats.parquet.table_transforms.extract_timestamp_field(
    schema: pyarrow.Schema,
    timestamp_field: roboto.formats.fields.FieldSelection,
    unit_hint: Optional[str],
) -> roboto.formats.parquet.timestamp.Timestamp
```

`from roboto.formats.parquet import extract_timestamp_field`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L132-L176)

Find a Parquet file's timestamp field and describe it as a [`Timestamp`](/docs/reference/python-sdk/roboto/formats/parquet/timestamp#roboto.formats.parquet.timestamp.Timestamp).

Methods such as [`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) read a topic's data from Parquet files through it, so most code never calls it.

The field is found by walking its path one component at a time, first among the schema's top-level fields and then through struct children, so a field nested in a struct and a top-level column whose name contains dots are never confused.

**Parameters**

- **schema** (`pyarrow.Schema`): The file's `ParquetFile.schema_arrow`. The timestamp's column index is counted over this schema's leaves, which match the file's leaf columns one for one.
- **timestamp_field** (`roboto.formats.fields.FieldSelection`): Path of the timestamp field.
- **unit_hint** (`Optional[str]`): Unit of the stored values, for a field whose Arrow type carries none; see [`unit_hint`](/docs/reference/python-sdk/roboto/formats/parquet/timestamp#roboto.formats.parquet.timestamp.Timestamp.unit_hint).

**Raises**

- `KeyError`: A path component is not in the schema, or names a child of a field that is not a struct.

**Returns**

- `roboto.formats.parquet.timestamp.Timestamp`

### extract_timestamps()

```python
def roboto.formats.parquet.table_transforms.extract_timestamps(
    table: pyarrow.Table,
    timestamp: roboto.formats.parquet.timestamp.Timestamp,
) -> pyarrow.Int64Array
```

`from roboto.formats.parquet import extract_timestamps`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L62-L129)

Return each row's timestamp from `table`, converted to nanoseconds since the Unix epoch.

Methods such as [`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) read a topic's data from Parquet files through it, so most code never calls it.

The field is found by walking `timestamp.path` through the table's struct columns, and a row whose enclosing struct is null has a null timestamp. Integer, floating-point and decimal values are multiplied by the number of nanoseconds in their unit, and floating-point results are truncated toward zero.

**Parameters**

- **table** (`pyarrow.Table`): Table read from the Parquet file, holding the timestamp field's column.
- **timestamp** (`roboto.formats.parquet.timestamp.Timestamp`): The file's timestamp field, as `extract_timestamp_field` returns it.

**Raises**

- `TypeError`: The timestamp field is not a timestamp, integer, floating-point or decimal field.
- `Exception`: The timestamp field is an integer, floating-point or decimal field and `timestamp.unit_hint` is `None`.
- `NotImplementedError`: `timestamp.unit_hint` names a unit this SDK version does not support.
- `pyarrow.ArrowInvalid`: A timestamp, converted to nanoseconds, does not fit in a 64-bit integer.

**Returns**

- `pyarrow.Int64Array`

### narrow_list_nested_fields()

```python
def roboto.formats.parquet.table_transforms.narrow_list_nested_fields(
    table: pyarrow.Table,
    schema: pyarrow.Schema,
    fields: collections.abc.Iterable[roboto.formats.fields.FieldSelection],
) -> pyarrow.Table
```

`from roboto.formats.parquet import narrow_list_nested_fields`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L448-L507)

Narrow the structs inside list columns to the fields requested within them.

Methods such as `roboto.experimental.topics.Topic.get_data` read a topic's data from Parquet files through it, so most code never calls it.

PyArrow cannot read part of a list's elements, so `resolve_columns` reads a field inside a list by the list's column, and every element keeps all its struct fields. Each top-level column that some field's path reaches through a list is rebuilt without the struct fields, inside the list or not, that no requested path runs through; every struct keeps its remaining fields in the order the file stores them. Other columns, and a column the table lacks, are left as read.

**Parameters**

- **table** (`pyarrow.Table`): Table read with the columns `resolve_columns` returns for `fields`. It must not be sliced: a list is rebuilt from its offsets and its whole child array, which assumes the offsets start at zero.
- **schema** (`pyarrow.Schema`): Arrow schema of the Parquet file, `ParquetFile.schema_arrow`.
- **fields** (`collections.abc.Iterable[roboto.formats.fields.FieldSelection]`): Fields that were requested. No field may lie inside another: the outer one would be narrowed to the inner one rather than kept whole.

**Returns**

- `pyarrow.Table`: `table` itself when no field's path passes through a list, otherwise a new table with those columns narrowed.

**Raises**

- `KeyError`: A field's path has more than one component and names a field `schema` lacks, before the path reaches a list or a field that is not a struct.

### resolve_columns()

```python
def roboto.formats.parquet.table_transforms.resolve_columns(
    schema: pyarrow.Schema,
    fields: collections.abc.Iterable[roboto.formats.fields.FieldSelection],
) -> list[str]
```

`from roboto.formats.parquet import resolve_columns`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L320-L357)

Build the column names to pass to `ParquetFile.read_row_group` to read `fields`, without duplicates.

Methods such as [`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) read a topic's data from Parquet files through it, so most code never calls it.

Each name is a field's path components joined with dots. PyArrow matches it as a prefix through structs, so `"position.x"` reads only the `x` child of a `position` struct. It cannot match through a list, so a field inside a list is read by the name of the first list its path passes through, which reads each element whole: for `points: list<struct<x, y>>`, the field `("points", "x")` becomes `"points"`.

A name can match more than one field: `"header.stamp"` reads both a `stamp` field nested in a `header` struct and a top-level column named `header.stamp`. `select_fields` removes from the table read the fields that were not requested, and `narrow_list_nested_fields` narrows each list's elements to the requested fields.

**Parameters**

- **schema** (`pyarrow.Schema`): Arrow schema of the Parquet file, `ParquetFile.schema_arrow`.
- **fields** (`collections.abc.Iterable[roboto.formats.fields.FieldSelection]`): Fields to read.

**Returns**

- `list[str]`: Column names, in the order of the first field that needs each.

**Raises**

- `KeyError`: A field's path has more than one component and names a field `schema` lacks, before the path reaches a list or a field that is not a struct.

### select_fields()

```python
def roboto.formats.parquet.table_transforms.select_fields(
    table: pyarrow.Table,
    fields: collections.abc.Iterable[roboto.formats.fields.FieldSelection],
) -> pyarrow.Table
```

`from roboto.formats.parquet import select_fields`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L604-L664)

Keep only the fields `fields` names, found by walking their path components, in the table's order.

Methods such as [`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) read a topic's data from Parquet files through it, so most code never calls it.

Reading columns by their dot-joined names (`resolve_columns`) can bring in more than was requested, such as a top-level column named `header.stamp` read along with a `header` struct's `stamp` field, or a timestamp field read only to filter rows. This removes them:

- A top-level column that no field's path starts with is dropped.
- A field that names a column or struct keeps it whole, even when other fields name some of its children.
- Otherwise a struct keeps only the children that some field's path runs through, with its own null rows.
- Lists and maps, and everything below them, are kept as read (`narrow_list_nested_fields` narrows the structs inside a list).
- A field whose path the table lacks is skipped.

A column from which nothing is removed is returned as read. With no fields at all, the result has no columns and keeps the table's row count.

**Parameters**

- **table** (`pyarrow.Table`): Table read from the Parquet file.
- **fields** (`collections.abc.Iterable[roboto.formats.fields.FieldSelection]`): Fields to keep.

**Returns**

- `pyarrow.Table`

### should_narrow_list_nested_fields()

```python
def roboto.formats.parquet.table_transforms.should_narrow_list_nested_fields(
    schema: pyarrow.Schema,
    fields: collections.abc.Iterable[roboto.formats.fields.FieldSelection],
) -> bool
```

`from roboto.formats.parquet import should_narrow_list_nested_fields`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L424-L445)

Return whether `narrow_list_nested_fields` would change a table read for `fields`.

Methods such as `roboto.experimental.topics.Topic.get_data` read a topic's data from Parquet files through it, so most code never calls it.

It is `True` when some field's path passes through a list. Otherwise `narrow_list_nested_fields` returns the table unchanged, so a reader can skip it. It reads only the schema, so a reader evaluates it once per file rather than once per row group.

**Parameters**

- **schema** (`pyarrow.Schema`): Arrow schema of the Parquet file, `ParquetFile.schema_arrow`.
- **fields** (`collections.abc.Iterable[roboto.formats.fields.FieldSelection]`): Fields that were requested.

**Raises**

- `KeyError`: A field's path has more than one component and names a field `schema` lacks, before the path reaches a list or a field that is not a struct.

**Returns**

- `bool`

### should_read_row_group()

```python
def roboto.formats.parquet.table_transforms.should_read_row_group(
    row_group_metadata: pyarrow.parquet.RowGroupMetaData,
    timestamp: roboto.formats.parquet.timestamp.Timestamp,
    start_time: Optional[int] = None,
    end_time: Optional[int] = None,
) -> bool
```

`from roboto.formats.parquet import should_read_row_group`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L231-L284)

Return whether a Parquet row group may hold rows in a time range, so a reader can skip one that cannot.

Methods such as [`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) read a topic's data from Parquet files through it, so most code never calls it.

It returns `False` only when the statistics of the row group's timestamp column show that every row is before `start_time` or after `end_time`. Without statistics it returns `True`, and a row group it returns `True` for may still hold no rows in the range.

**Parameters**

- **row_group_metadata** (`pyarrow.parquet.RowGroupMetaData`): Metadata of the row group, from `ParquetFile.metadata.row_group`.
- **timestamp** (`roboto.formats.parquet.timestamp.Timestamp`): The file's timestamp field, as `extract_timestamp_field` returns it.
- **start_time** (`Optional[int]`): Inclusive start of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded below.
- **end_time** (`Optional[int]`): Exclusive end of the time range, in nanoseconds since the Unix epoch. `None` leaves the range unbounded above.

**Raises**

- `Exception`: The row group has timestamp statistics, the timestamp field's Arrow type is not a timestamp type, and `timestamp.unit_hint` is `None`.
- `NotImplementedError`: The timestamp field's Arrow type is not a timestamp type and `timestamp.unit_hint` names a unit this SDK version does not support.

**Returns**

- `bool`

### timestamp_statistics()

```python
def roboto.formats.parquet.table_transforms.timestamp_statistics(
    row_group_metadata: pyarrow.parquet.RowGroupMetaData,
    timestamp: roboto.formats.parquet.timestamp.Timestamp,
) -> Optional[pyarrow.parquet.Statistics]
```

`from roboto.formats.parquet import timestamp_statistics`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/parquet/table_transforms.py#L199-L228)

Return the statistics of the timestamp's column chunk in a row group, or `None` when there are none to use.

Methods such as [`get_data()`](/docs/reference/python-sdk/roboto/domain/topics/topic#roboto.domain.topics.topic.Topic.get_data) read a topic's data from Parquet files through it, so most code never calls it.

The chunk is found by its position, `timestamp.column_index`, because a field nested in a struct and a top-level column whose name contains dots can share a `path_in_schema`: `header.stamp` names both a `header` struct's `stamp` field and a column of that name. The result is `None` when:

- The row group has no chunk at that position.
- That chunk's `path_in_schema` is not the timestamp's path joined with dots, because `timestamp` was found in another file's schema.
- The chunk has no statistics.

**Parameters**

- **row_group_metadata** (`pyarrow.parquet.RowGroupMetaData`): Metadata of the row group, from `ParquetFile.metadata.row_group`.
- **timestamp** (`roboto.formats.parquet.timestamp.Timestamp`): The file's timestamp field, as `extract_timestamp_field` returns it.

**Returns**

- `Optional[pyarrow.parquet.Statistics]`
