Skip to main content

BLOB Storage

For Paimon's Blob storage concepts (storage modes, table options, SQL usage, Java API), see Blob Storage.

This page covers the Python API for reading and writing BLOB columns.

A descriptor keeps a BLOB payload lazy until FileIO reads its byte range.

Creating a Table​

A BLOB column maps to PyArrow large_binary(). The table must enable row-tracking.enabled and data-evolution.enabled.

from pypaimon import CatalogFactory, Schema
import pyarrow as pa

catalog = CatalogFactory.create({'warehouse': '/tmp/paimon-warehouse'})
catalog.create_database('my_db', True)

pa_schema = pa.schema([
('id', pa.int32()),
('name', pa.string()),
('image', pa.large_binary()),
])
schema = Schema.from_pyarrow_schema(
pa_schema,
options={
'row-tracking.enabled': 'true',
'data-evolution.enabled': 'true',
},
)
catalog.create_table('my_db.image_table', schema, True)

Writing Blob Data​

Pass raw bytes for the blob column in a PyArrow Table; pypaimon writes them to dedicated .blob files automatically.

table = catalog.get_table('my_db.image_table')
write_builder = table.new_batch_write_builder()
writer = write_builder.new_write()
commit = write_builder.new_commit()
try:
with open('cat.jpg', 'rb') as f1, open('dog.jpg', 'rb') as f2:
writer.write_arrow(pa.Table.from_pydict({
'id': [1, 2],
'name': ['cat', 'dog'],
'image': [f1.read(), f2.read()],
}, schema=pa_schema))
commit.commit(writer.prepare_commit())
finally:
writer.close()
commit.close()

For frame tables, configure video-frame-field. The high-level multimodal API creates VideoFrameDescriptor values, packs multiple complete videos in .video files, keeps frame ordinals out of the normal data file, and provides add_video / add_videos / replace_video for physical video writes. Ordinary frame-column updates and all reads continue to use the existing table and BLOB APIs. See Video Frame Storage.

Reading Blob Data​

Use to_arrow_batch_reader to read blob data in batches. When blob_parallelism is omitted, native reads use the Rust reader's default (currently 8 concurrent BLOB range reads per active split group) when the installed extension supports HTTP BLOB retries. Older extensions retain a default of 1, so upgrading PyPaimon alone does not introduce failures on throttled HTTP origins. Python reads, including native preparation fallback, also default to 1. Set blob_parallelism=1 explicitly to keep BLOB reads serial within each split.

Native execution that materializes BLOB payloads caps the combined range-read concurrency at 64 per read and reduces per-group concurrency when needed. BLOB reads with a LIMIT retain a single split group and check the row quota before materializing output payloads. Python parallel reads reduce per-split BLOB concurrency toward a total budget of 64, but keep at least one read per split worker: 65 split workers can therefore issue 65 concurrent reads. This is not a hard Python request limit. These rules apply to both to_arrow_batch_reader and to_arrow; row-by-row reading is unchanged.

Set a positive blob_parallelism to override the per-group default within the backend's concurrency budget:

read_builder = table.new_read_builder()
splits = read_builder.new_scan().plan().splits()
read = read_builder.new_read()

for batch in read.to_arrow_batch_reader(splits, blob_parallelism=16):
for i in range(len(batch)):
image_bytes = batch['image'][i].as_py()

Or read all data into a single Arrow Table:

arrow_table = read.to_arrow(splits, blob_parallelism=16)

For a concurrency-limited HTTP origin, explicitly reduce BLOB concurrency. The multimodal scan API also accepts this override:

arrow_table = multimodal_table.scan().to_arrow(blob_parallelism=1)

This limits reads within each split; multiple active splits or independent queries can still send requests concurrently.

Row-by-row reading​

Use row.get_blob(pos) to access blob columns one row at a time:

for row in read.to_iterator(splits):
blob = row.get_blob(2)
if blob is None:
continue
data = blob.to_data()

Streaming / partial reads​

For true on-demand streaming (large blobs like videos or model weights), set blob-as-descriptor=true so blob values are kept as lightweight references instead of being materialized into memory:

table = table.copy({'blob-as-descriptor': 'true'})

read_builder = table.new_read_builder()
splits = read_builder.new_scan().plan().splits()
read = read_builder.new_read()

for row in read.to_iterator(splits):
blob = row.get_blob(2)
if blob is None:
continue
with blob.new_input_stream() as stream:
chunk = stream.read(4096)

Without blob-as-descriptor=true, blob values are materialized before row.get_blob(...) returns; new_input_stream() then reads from in-memory bytes, not from storage.

For data-evolution reads, PyPaimon applies user filters, row-level authorization filters, and limits before materializing projected scalar BLOB payloads. A user or authorization filter that references a BLOB value keeps that field eager. Column masking is applied after payload materialization. ARRAY and MAP elements containing BLOB values are not deferred.

Lower-level: Blob.from_bytes​

When you already have raw or descriptor bytes (for example from a custom source) and want to wrap them as a Blob, use the factory:

from pypaimon.table.row.blob import Blob

# Inline bytes → BlobData (no file_io required)
blob = Blob.from_bytes(b'hello')

# Descriptor bytes → BlobRef (lazy; requires file_io to resolve the URI)
file_io = table.file_io
blob = Blob.from_bytes(descriptor_bytes, file_io)

data = blob.to_data()

The factory auto-dispatches based on the bytes content (BLOBDESC, VIDEOFRM, or blob-view magic header). This mirrors Java's Blob.fromBytes(...).

Python BLOB index cache​

Set cache.blob-index.max-size in Catalog options to limit parsed indexes per Catalog context (default: 64 mb; 0 b disables). The cache is process-local and only used by the Python BLOB reader. With caching enabled, concurrent readers of the same file share one in-flight index load. Failed loads can be retried; indexes exceeding the budget are shared only with current waiters and are not retained.

See Also​