pub trait ParquetHandler: AsAny {
// Required methods
fn read_parquet_files(
&self,
files: &[FileMeta],
physical_schema: SchemaRef,
predicate: Option<PredicateRef>,
) -> DeltaResult<FileDataReadResultIterator>;
fn write_parquet_file(
&self,
location: Url,
data: DeltaResultIteratorStatic<Box<dyn EngineData>>,
) -> DeltaResult<()>;
fn read_parquet_footer(&self, file: &FileMeta) -> DeltaResult<ParquetFooter>;
// Provided methods
fn read_parquet_files_with_cancellation(
&self,
files: &[FileMeta],
physical_schema: SchemaRef,
predicate: Option<PredicateRef>,
cancellation_token: Option<CancellationTokenRef>,
) -> DeltaResult<FileDataReadResultIterator> { ... }
fn read_parquet_footer_with_cancellation(
&self,
file: &FileMeta,
cancellation_token: Option<CancellationTokenRef>,
) -> DeltaResult<ParquetFooter> { ... }
}Expand description
Provides Parquet file related functionalities to Delta Kernel.
Connectors can leverage this trait to provide their own custom implementation of Parquet data file functionalities to Delta Kernel.
Required Methods§
Sourcefn read_parquet_files(
&self,
files: &[FileMeta],
physical_schema: SchemaRef,
predicate: Option<PredicateRef>,
) -> DeltaResult<FileDataReadResultIterator>
fn read_parquet_files( &self, files: &[FileMeta], physical_schema: SchemaRef, predicate: Option<PredicateRef>, ) -> DeltaResult<FileDataReadResultIterator>
Read and parse the Parquet file at given locations and return the data as EngineData with
the columns requested by physical schema. The ParquetHandler must return exactly the
columns specified in physical_schema, and they must be in schema order.
§Resolving Parquet schema to the physical schema
When reading the Parquet file, the columns are resolved from the Parquet schema to the
kernel’s physical_schema. To do so, the parquet reader must match each Parquet column
to a StructField in the physical_schema. All columns in the returned EngineData
must be in the same order as specified in physical_schema.
Parquet columns are matched to physical_schema StructFields using the following rules:
- Field ID: If a
StructFieldinphysical_schemacontains a field ID (specified inColumnMetadataKey::ParquetFieldIdmetadata), use the ID to match the Parquet column’s field id - Field Name: If no field ID is present in the
physical_schema’sStructFieldor no matching parquet field ID is found, fall back to matching by column name
§Type coercion
A matched Parquet column whose physical type differs from the physical_schema
StructField must be coerced to the requested type. In particular, timestamp columns MUST
be normalized to the protocol specified microsecond precision: a TIMESTAMP(MILLIS) (or
any other non-microsecond unit) column read into a TIMESTAMP / TIMESTAMP_NTZ field
must be rescaled to microseconds (a finer unit such as nanosecond is truncated). The
default engine does this via arrow::compute::cast while reordering columns to the
requested schema.
§Metadata Columns
The ParquetHandler must support virtual metadata columns that provide additional information about each row. These columns are not stored in the Parquet file but are generated at read time.
§Row Index Column
When a column in physical_schema is marked as a row index metadata column (via
StructField::create_metadata_column with schema::MetadataColumnSpec::RowIndex), the
ParquetHandler must populate it with the 0-based row position within the Parquet file:
- Column name: User-specified (commonly
"row_index"or"_metadata.row_index") - Type:
LONG(non-nullable) - Values: Sequential integers starting at 0 for each file
- Use case: Track row positions for downstream processing, or internally used to compute Row IDs
Example: A file with 5 rows would have row_index values [0, 1, 2, 3, 4].
§File Name Column (Reserved Field ID)
When a column in physical_schema has the reserved field ID
reserved_field_ids::FILE_NAME (2147483646), the ParquetHandler must populate it
with the file path/name:
- Column name:
"_file" - Type:
STRING(non-nullable) - Field ID: 2147483646 (reserved)
- Values: The file path/URL (e.g.,
"s3://bucket/path/file.parquet") - Use case: Track which file each row came from in multi-file reads
Example: All rows from the same file would have the same _file value.
§Metadata Column Examples
use delta_kernel::schema::{StructType, StructField, DataType, MetadataColumnSpec};
// Example 1: Schema with row_index metadata column
let schema_with_row_index = StructType::try_new([
StructField::nullable("id", DataType::INTEGER),
StructField::create_metadata_column("row_index", MetadataColumnSpec::RowIndex),
StructField::nullable("value", DataType::STRING),
])?;
// Example 2: Schema with _file metadata column (using reserved field ID)
let schema_with_file_path = StructType::try_new([
StructField::nullable("id", DataType::INTEGER),
StructField::create_metadata_column("_file", MetadataColumnSpec::FilePath),
StructField::nullable("value", DataType::STRING),
])?;If no matching Parquet column is found, NULL values are returned
for nullable columns in physical_schema. For non-nullable columns, an error is returned.
§Column Matching Examples
Consider a physical_schema with the following fields:
- Column 0:
"i_logical"(integer, non-null) with field ID 1 (viaColumnMetadataKey::ParquetFieldId) - Column 1:
"s"(string, nullable) with no field ID metadata - Column 2:
"i2"(integer, nullable) with no field ID metadata
And a Parquet file containing these columns:
- Column 0:
"i2"(integer, nullable) with field ID 3 - Column 1:
"i"(integer, non-null) with field ID 1 - No
"s"column present
The column matching would work as follows:
"i_logical"matches"i"by field ID (both have ID 1)"i2"matches"i2"by column name (no field ID to match on)"s"has no matching Parquet column, so NULL values are returned
The returned data will contain exactly 3 columns in physical schema order:
{i_logical: parquet[1], s: NULL.., i2: parquet[0]}
§Parameters
files- File metadata for files to be read.physical_schema- Select list and order of columns to read from the Parquet file.predicate- Optional conservative push-down predicate. Implementations may ignore it. A file, row group, or row may be omitted only when the predicate cannot evaluate to true for any row in that unit. CAST and NULL semantics must agree with the eventual query filter. An evaluator using exact row values may apply the CAST directly. Footer min/max may be cast only when the cast preserves those bounds; otherwise footer evaluation of the CAST must remain unknown and must not fail the read. Other unsupported subexpressions and references with no matching physical or generated value must also remain unknown without failing the read. A missing reference remains unknown for pruning even if schema reconciliation synthesizes a NULL output column. Returned data is not guaranteed to satisfy the predicate.
§Returns
A DeltaResult containing a FileDataReadResultIterator.
Each element of the iterator is a DeltaResult of EngineData. The EngineData
contains rows from files after any predicate push-down and must match the provided
physical_schema.
Note: The FileDataReadResultIterator must emit data from files in the order that files
is given. For example if files [“a”, “b”] is provided, then the engine data iterator must
first return all the engine data from file “a”, then all the engine data from file “b”.
Moreover, for a given file, all of its EngineData and constituent rows must be in order
that they occur in the file. Consider a file with rows
(1, 2, 3). The following are legal iterator batches:
iter: [EngineData(1, 2), EngineData(3)]
iter: [EngineData(1), EngineData(2, 3)]
iter: [EngineData(1, 2, 3)]
The following are illegal batches:
iter: [EngineData(3), EngineData(1, 2)]
iter: [EngineData(1), EngineData(3, 2)]
iter: [EngineData(2, 1, 3)]
Additionally, engines must not merge engine data across file boundaries.
Sourcefn write_parquet_file(
&self,
location: Url,
data: DeltaResultIteratorStatic<Box<dyn EngineData>>,
) -> DeltaResult<()>
fn write_parquet_file( &self, location: Url, data: DeltaResultIteratorStatic<Box<dyn EngineData>>, ) -> DeltaResult<()>
Write data to a Parquet file at the specified URL.
This method writes the provided data to a Parquet file at the given url.
This will overwrite the file if it already exists. For filesystem-backed implementations, the parent directories must be created if they do not exist.
§Parquet field IDs
The engine must write a Parquet field_id correctly when the kernel
StructField carries a field-id related annotation, including:
ColumnMetadataKey::ColumnMappingId/ColumnMetadataKey::ParquetFieldIdColumnMetadataKey::ColumnMappingNestedIds
For how to use these keys, refer to the Delta protocol’s Column Mapping and IcebergCompatV2 sections.
Non-compliance produces files with incorrect field_ids, which may lead to
read failures when column mapping mode is id and to failures when converting
the table to Iceberg.
§Parameters
url- The full URL path where the Parquet file should be written (e.g.,s3://bucket/path/file.parquet).data- An iterator of engine data to be written to the Parquet file.
§Returns
A DeltaResult indicating success or failure.
Read the footer metadata from a Parquet file without reading the data.
This method reads only the Parquet file footer (metadata section), which is useful for schema inspection, compatibility checking, and determining whether parsed statistics columns are present and compatible with the current table schema.
§Parameters
file- File metadata for the Parquet file whose footer should be read. Thesizefield should contain the actual file size to enable efficient footer reads without additional I/O operations.
§Returns
A DeltaResult containing a ParquetFooter with the Parquet file’s metadata, including
the schema converted to Delta Kernel’s format.
§Field IDs
If the Parquet file contains field IDs (written when column mapping is enabled), they are
preserved in each StructField’s metadata. Callers can access field IDs via
StructField::get_config_value with ColumnMetadataKey::ParquetFieldId.
§Errors
Returns an error if:
- The file cannot be accessed or does not exist
- The file is not a valid Parquet file
- The footer cannot be read or parsed
- The schema cannot be converted to Delta Kernel’s format
Provided Methods§
Sourcefn read_parquet_files_with_cancellation(
&self,
files: &[FileMeta],
physical_schema: SchemaRef,
predicate: Option<PredicateRef>,
cancellation_token: Option<CancellationTokenRef>,
) -> DeltaResult<FileDataReadResultIterator>
fn read_parquet_files_with_cancellation( &self, files: &[FileMeta], physical_schema: SchemaRef, predicate: Option<PredicateRef>, cancellation_token: Option<CancellationTokenRef>, ) -> DeltaResult<FileDataReadResultIterator>
Cancellation-aware variant of read_parquet_files.
When cancellation_token is Some, an engine may race its I/O against the token and
terminate the returned iterator with Error::Cancelled once cancellation is observed,
rather than reading every file to completion.
The default implementation returns Error::Cancelled if the token is already cancelled
and otherwise delegates to read_parquet_files, ignoring the
token for the rest of the read. So an engine that does not override this stays
source-compatible while still honoring an up-front cancellation; kernel additionally polls
the token at action-batch boundaries. An engine that overrides this takes over the up-front
check and should also fast-path an already-cancelled token before starting I/O.
Cancellation-aware variant of read_parquet_footer.
When cancellation_token is Some, an engine may race the footer read against the token
and return Error::Cancelled once cancellation is observed.
The default implementation returns Error::Cancelled if the token is already cancelled
and otherwise delegates to read_parquet_footer, ignoring the
token for the rest of the read. So an engine that does not override this stays
source-compatible while still honoring an up-front cancellation. An engine that overrides
this takes over the up-front check and should also fast-path an already-cancelled token
before starting I/O.