Table Writes¶
write_table
¶
write_table(
data: DataFrame | LazyFrame,
location: str | Path,
metadata: dict[str, str] | None = None,
row_group_size: int | None = None,
) -> None
Write one parquet table and fail if the output already exists.
Parameters:
-
data(DataFrame | LazyFrame) –Polars dataframe or lazy frame to write.
-
location(str | Path) –Relative or absolute output table location.
-
metadata(dict[str, str] | None, default:None) –Optional parquet key-value footer metadata.
-
row_group_size(int | None, default:None) –Optional parquet row-group size.
Raises:
-
FileExistsError–If
locationalready exists.
Examples:
Write a prepared scratch table during ingestion:
Write a manifest with parquet footer metadata:
Source code in batgrad/storage/local.py
open_table_writer
¶
open_table_writer(
location: str | Path,
schema: Schema,
compression: str,
*,
use_content_defined_chunking: bool = False,
) -> TableWriter
Open a parquet writer for incrementally writing one table.
Parameters:
-
location(str | Path) –Relative or absolute output table location.
-
schema(Schema) –Arrow schema for all chunks written through the returned writer.
-
compression(str) –Parquet compression codec passed to PyArrow.
-
use_content_defined_chunking(bool, default:False) –Whether PyArrow should use content-defined chunking when writing parquet data.
Returns:
-
TableWriter–Table writer that keeps the parquet file open until closed.
Raises:
-
FileExistsError–If
locationalready exists.
Examples:
Write bounded normalization output as chunks become available:
>>> writer = store.open_table_writer(temp_path, chunk.to_arrow().schema, "zstd")
>>> writer.write_table(chunk, row_group_size=config.row_group_size)
>>> writer.close()
Source code in batgrad/storage/local.py
table_size_bytes
¶
Return the table file size in bytes.
This is used by sharding to decide when an open shard should roll over to a new file.
Parameters:
Returns:
-
int | None–File size in bytes, or
Noneif the file does not exist.