Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion src/arc_client/ingestion/async_buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ async def _flush_all_unlocked(self) -> None:
await self._flush_measurement_unlocked(measurement)

def _merge_columnar(self, batches: list[dict[str, list[Any]]]) -> dict[str, list[Any]]:
"""Merge multiple columnar batches into one."""
"""Merge multiple columnar batches into one.

When batches have different column sets (sparse columns), missing
positions are filled with None so all columns have equal length.
"""
if not batches:
return {}

Expand All @@ -133,12 +137,17 @@ def _merge_columnar(self, batches: list[dict[str, list[Any]]]) -> dict[str, list
for batch in batches:
all_columns.update(batch.keys())

# Merge each column, padding missing columns with None
merged: dict[str, list[Any]] = {}
for col_name in all_columns:
merged[col_name] = []
for batch in batches:
if col_name in batch:
merged[col_name].extend(batch[col_name])
else:
# Column missing from this batch — pad with None
batch_len = len(batch.get("time", next(iter(batch.values()))))
merged[col_name].extend([None] * batch_len)

return merged

Expand Down
12 changes: 10 additions & 2 deletions src/arc_client/ingestion/buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ def _flush_all(self) -> None:
self._flush_measurement(measurement)

def _merge_columnar(self, batches: list[dict[str, list[Any]]]) -> dict[str, list[Any]]:
"""Merge multiple columnar batches into one."""
"""Merge multiple columnar batches into one.

When batches have different column sets (sparse columns), missing
positions are filled with None so all columns have equal length.
"""
if not batches:
return {}

Expand All @@ -179,13 +183,17 @@ def _merge_columnar(self, batches: list[dict[str, list[Any]]]) -> dict[str, list
for batch in batches:
all_columns.update(batch.keys())

# Merge each column
# Merge each column, padding missing columns with None
merged: dict[str, list[Any]] = {}
for col_name in all_columns:
merged[col_name] = []
for batch in batches:
if col_name in batch:
merged[col_name].extend(batch[col_name])
else:
# Column missing from this batch — pad with None
batch_len = len(batch.get("time", next(iter(batch.values()))))
merged[col_name].extend([None] * batch_len)

return merged

Expand Down