pathwaycom/pathway · error · ValueError
Unexpected number of columns in table: {len(table._columns)}
Error message
Unexpected number of columns in table: {len(table._columns)} What it means
Raised by pw.io.pubsub.write at graph-construction time when the input table does not have exactly one column. The connector maps each row to one Pub/Sub message whose payload is that single column's bytes value, so there is no defined mapping for zero, two, or more columns.
Source
Thrown at python/pathway/io/pubsub/__init__.py:127
... "./credentials.json"
... )
If you don't have the topic created yet, you may want to create it first:
>>> topic_path = publisher.topic_path(project_id, topic_id) # doctest: +SKIP
>>> topic = publisher.create_topic(request={"name": topic_path}) # doctest: +SKIP
After that you can configure the table output with the following code:
>>> import pathway as pw
>>> pw.io.pubsub.write(table, publisher, project_id, topic_id) # doctest: +SKIP
At last, don't forget to add ``pw.run()`` to run your pipeline.
"""
columns = list(table._columns.values())
if len(columns) != 1:
raise ValueError(
f"Unexpected number of columns in table: {len(table._columns)}"
)
allowed_column_types = (dt.BYTES, dt.ANY)
if columns[0].dtype not in allowed_column_types:
raise ValueError("The column should be of the type 'bytes'")
output_buffer = _OutputBuffer(publisher, project_id, topic_id)
subscribe(
table,
on_change=output_buffer.on_change,
on_time_end=output_buffer.on_time_end,
name=name,
sort_by=sort_by,
)
View on GitHub (pinned to fa2f74a464)
Solutions
- Project to a single payload column before writing: pw.io.pubsub.write(t.select(data=t.data), ...).
- To publish whole rows, serialize each row to bytes in that one column first (e.g. an apply that returns json-encoded bytes).
- Check the table's column count in tests to catch schema drift.
Example fix
# before pw.io.pubsub.write(events, publisher, project_id, topic_id) # events: id, value, ts # after payload = events.select(data=events.value) pw.io.pubsub.write(payload, publisher, project_id, topic_id)
Defensive patterns
Strategy: validation
Validate before calling
assert len(t.columns) == 1, f"expected 1 payload column, got {len(t.columns)}"
pw.io.pubsub.write(t, publisher, project_id, topic_id) Type guard
def single_column_table(t) -> bool:
return len(t._columns) == 1 Prevention
- Make projection the last step before the writer: pw.io.pubsub.write(t.select(data=t.data), ...).
- Serialize whole-row JSON into one bytes column instead of passing multi-column tables.
- Assert the column count in a unit test over the table handed to the sink.
When it happens
Trigger: Calling pw.io.pubsub.write(table, publisher, project_id, topic_id) where table has 0 or >=2 columns, e.g. a full input schema (id, value, ...) instead of a projected single-column table.
Common situations: Passing a raw ingested table straight to the writer without a select(); intending to publish JSON of the whole row but not serializing it first; evolving a schema and forgetting to update the projection.
Related errors
- Unexpected number of columns: {len(row)}
- Failed to detect the region of S3 bucket {bucket!r} (HTTP st
- Schema.with_types() argument name has to be an existing colu
- Schema.without() argument {name!r} has to refer to an existi
- schema does not have columns {missing_columns}
AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15).
Data as JSON: /api/errors/749b775532514a49.
Report an issue: GitHub.