Multi-Key API¶
fsspeckit supports multi-column (composite) keys for merge and deduplication operations. This page explains how to use composite keys and how to interpret the results. For exact signatures, see fsspeckit.datasets.pyarrow.
The PyArrow backend requires the datasets extra. See the
extras matrix.
Multi-column keys in merge¶
Both DuckDBDatasetIO and PyarrowDatasetIO accept a list of column names for
key_columns in merge(). A single string is equivalent to a one-column list.
All strategies (insert, update, upsert) support composite keys. When
duplicates are found, use dedup_order_by to control which record survives.
Multi-column key deduplication¶
deduplicate_parquet_dataset_pyarrow() removes duplicate rows from an existing
dataset, supporting both single-column and multi-column keys.
Pass key_columns=None to remove exact duplicate rows across all columns.
Interpreting results¶
deduplicate_parquet_dataset_pyarrow() returns a dictionary with deduplication
statistics and performance metrics. Inspect the deduplicated_rows count and
file-level metrics to audit the operation.
Memory-aware deduplication¶
For datasets larger than memory, control chunking and peak memory with
chunk_size_rows and max_memory_mb:
How composite keys work internally¶
Multi-column key matching uses vectorized PyArrow operations:
- Composite keys are built as StructArrays for efficient comparison.
- Key membership is resolved with semi-join and anti-join operations on PyArrow tables.
- When native joins fail due to heterogeneous type combinations, the engine falls back to string-based key serialization.
These mechanisms are internal to the merge and deduplication engines. You do not
need to call them directly; they activate automatically when you pass a list to
key_columns.
Optimization with composite keys¶
optimize_parquet_dataset_pyarrow() combines deduplication with compaction. Pass
deduplicate_key_columns to deduplicate before compacting:
Related documentation¶
- Dataset Handlers - shared merge and write interface.
- Adaptive Key Tracking - memory-bounded key tracking for streaming merges.
- Multi-Key Performance - benchmarking composite-key operations.
- Generated API - signatures.