Implementation:AI Northstar Tech Vector io Consolidate Parquet
| Knowledge Sources | |
|---|---|
| Domains | Parquet, Data_Optimization, VDF_Format |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Concrete tool for consolidating fragmented Parquet files into larger combined files with size-based splitting and schema unification, provided by the vector-io library.
Description
The Consolidate_Parquet script (registered as the consolidate_parquet_vdf console script) merges many small Parquet files in a VDF export directory into fewer, larger combined files. This optimizes storage and read performance by reducing file count.
The consolidation algorithm:
- Reads all '.parquet files in the specified directory.
- Collects the union of all column names across files.
- For each file, re-aligns columns to the unified schema (filling missing columns with None).
- Writes rows into a combined Parquet file using ParquetWriter.
- When the output file reaches max_size_gb, closes the writer and starts a new file.
- When schema changes between files, closes the writer and starts a new file.
- Deletes the original fragmented files after consolidation.
- Updates VDF_META.json to reflect the new file structure.
The script reads VDF_META.json from the parent directory of the input directory to track and update the file structure metadata.
Usage
Run this script when you have a VDF export with many small Parquet files and want to consolidate them into fewer, larger files for better read performance. Available as the consolidate_parquet_vdf CLI command.
Code Reference
Source Location
- Repository: vector-io
- File: src/vdf_io/scripts/consolidate_parquet.py
- Lines: 1-137
Signature
def get_file_size_in_gb(file_path: str) -> float:
"""Calculate the size of a file in gigabytes."""
def main():
"""
Consolidate multiple Parquet files into combined files based on a maximum size.
Args (via argparse):
--directory: Directory containing parquet files (default: None)
--max_size_gb: Maximum size in GB for each combined file (default: 0.5)
"""
Import
from vdf_io.scripts.consolidate_parquet import main, get_file_size_in_gb
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --directory | str (CLI arg) | Yes | Directory containing parquet files to consolidate |
| --max_size_gb | float (CLI arg) | No | Maximum size in GB per combined file (default: 0.5) |
| VDF_META.json | JSON file | Yes | Located in parent of --directory; contains file_structure |
Outputs
| Name | Type | Description |
|---|---|---|
| combined_file_N.parquet | Parquet files | Consolidated parquet files in the directory |
| VDF_META.json | JSON file | Updated with new file_structure (old paths removed) |
| Old parquet files | Deleted | Original fragmented files removed after consolidation |
Usage Examples
CLI Usage
# Consolidate parquet files in a VDF export directory
# Maximum 2 GB per combined file
consolidate_parquet_vdf --directory /path/to/vdf_export/data --max_size_gb 2
Programmatic Usage
import sys
from vdf_io.scripts.consolidate_parquet import main
# Simulate CLI invocation
sys.argv = [
"consolidate_parquet.py",
"--directory", "/path/to/vdf_export/data",
"--max_size_gb", "1",
]
# Run consolidation
main()
# Result: small parquet files merged into combined_file_1.parquet, combined_file_2.parquet, etc.
# VDF_META.json updated, old files deleted
Related Pages
Implements Principle
- Principle:AI_Northstar_Tech_Vector_io_Parquet_Serialization
- Principle:AI_Northstar_Tech_Vector_io_VDF_Metadata_Schema