Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI Northstar Tech Vector io Consolidate Parquet

From Leeroopedia
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:

    1. Reads all '.parquet files in the specified directory.
    2. Collects the union of all column names across files.
    3. For each file, re-aligns columns to the unified schema (filling missing columns with None).
    4. Writes rows into a combined Parquet file using ParquetWriter.
    5. When the output file reaches max_size_gb, closes the writer and starts a new file.
    6. When schema changes between files, closes the writer and starts a new file.
    7. Deletes the original fragmented files after consolidation.
    8. 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

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

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment