Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions icebug_format/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
from pathlib import Path

import duckdb
import pyarrow.parquet as pq

ICEBUG_DISK_VERSION = "v1"


def _write_parquet_with_icebug_metadata(con, table_name: str, output_path: Path) -> None:
"""Export a DuckDB table to parquet with icebug_disk_version metadata."""
arrow_table = con.execute(f"SELECT * FROM {table_name}").arrow().read_all()
existing_metadata = arrow_table.schema.metadata or {}
new_metadata = {**existing_metadata, b"icebug_disk_version": ICEBUG_DISK_VERSION.encode()}
arrow_table = arrow_table.replace_schema_metadata(new_metadata)
pq.write_table(arrow_table, str(output_path))
con.execute(
f"""
COPY {table_name} TO ?
(FORMAT PARQUET, KV_METADATA {{ icebug_disk_version: '{ICEBUG_DISK_VERSION}' }})
""",
[str(output_path)],
)


def parse_schema_cypher(schema_path: Path) -> dict:
Expand Down
Loading