{"record":{"id":"749b775532514a49","repo":"pathwaycom/pathway","slug":"unexpected-number-of-columns-in-table-len-table","errorCode":null,"errorMessage":"Unexpected number of columns in table: {len(table._columns)}","messagePattern":"Unexpected number of columns in table: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/pubsub/__init__.py","lineNumber":127,"sourceCode":"    ...     \"./credentials.json\"\n    ... )\n\n    If you don't have the topic created yet, you may want to create it first:\n\n    >>> topic_path = publisher.topic_path(project_id, topic_id)  # doctest: +SKIP\n    >>> topic = publisher.create_topic(request={\"name\": topic_path})  # doctest: +SKIP\n\n    After that you can configure the table output with the following code:\n\n    >>> import pathway as pw\n    >>> pw.io.pubsub.write(table, publisher, project_id, topic_id)  # doctest: +SKIP\n\n    At last, don't forget to add ``pw.run()`` to run your pipeline.\n    \"\"\"\n\n    columns = list(table._columns.values())\n    if len(columns) != 1:\n        raise ValueError(\n            f\"Unexpected number of columns in table: {len(table._columns)}\"\n        )\n\n    allowed_column_types = (dt.BYTES, dt.ANY)\n    if columns[0].dtype not in allowed_column_types:\n        raise ValueError(\"The column should be of the type 'bytes'\")\n\n    output_buffer = _OutputBuffer(publisher, project_id, topic_id)\n    subscribe(\n        table,\n        on_change=output_buffer.on_change,\n        on_time_end=output_buffer.on_time_end,\n        name=name,\n        sort_by=sort_by,\n    )\n","sourceCodeStart":109,"sourceCodeEnd":143,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/pubsub/__init__.py#L109-L143","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\npw.io.pubsub.write(events, publisher, project_id, topic_id)  # events: id, value, ts\n\n# after\npayload = events.select(data=events.value)\npw.io.pubsub.write(payload, publisher, project_id, topic_id)","handlingStrategy":"validation","validationCode":"assert len(t.columns) == 1, f\"expected 1 payload column, got {len(t.columns)}\"\npw.io.pubsub.write(t, publisher, project_id, topic_id)","typeGuard":"def single_column_table(t) -> bool:\n    return len(t._columns) == 1","tryCatchPattern":null,"preventionTips":["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."],"tags":["pathway","gcp","pubsub","schema","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}