{"record":{"id":"384e0beeeb37af00","repo":"apache/beam","slug":"both-a-query-and-an-output-type-of-beam-row-were-specified","errorCode":null,"errorMessage":"Both a query and an output type of 'BEAM_ROW' were specified without a query_output_schema. When using a query, you must provide query_output_schema so the output schema can be determined without reading an existing table. The schema should be a BigQuery schema dict, e.g. {'fields': [{'name': 'col', 'type': 'STRING', 'mode': 'NULLABLE'}, ...]}, or a TableSchema object.","messagePattern":"Both a query and an output type of 'BEAM_ROW' were specified without a query_output_schema\\. When using a query, you must provide query_output_schema so the output schema can be determined without reading an existing table\\. The schema should be a BigQuery schema dict, e\\.g\\. (.+?), \\.\\.\\.\\]\\}, or a TableSchema object\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery.py","lineNumber":3079,"sourceCode":"        and self.use_native_datetime is True:\n      raise TypeError(\n          'The \"use_native_datetime\" parameter cannot be True for EXPORT.'\n          ' Please set the \"use_native_datetime\" parameter to False *OR*'\n          ' set the \"method\" parameter to ReadFromBigQuery.Method.DIRECT_READ.')\n\n    if gcs_location and self.method == ReadFromBigQuery.Method.EXPORT:\n      if not isinstance(gcs_location, (str, ValueProvider)):\n        raise TypeError(\n            '%s: gcs_location must be of type string'\n            ' or ValueProvider; got %r instead' %\n            (self.__class__.__name__, type(gcs_location)))\n      if isinstance(gcs_location, str):\n        gcs_location = StaticValueProvider(str, gcs_location)\n\n    if self.output_type == 'BEAM_ROW' and self._kwargs.get('query',\n                                                           None) is not None:\n      if self.query_output_schema is None:\n        raise ValueError(\n            \"Both a query and an output type of 'BEAM_ROW' were specified \"\n            \"without a query_output_schema. When using a query, you must \"\n            \"provide query_output_schema so the output schema can be \"\n            \"determined without reading an existing table. The schema should \"\n            \"be a BigQuery schema dict, e.g. \"\n            \"{'fields': [{'name': 'col', 'type': 'STRING', 'mode': 'NULLABLE'}\"\n            \", ...]}, or a TableSchema object.\")\n\n    self.gcs_location = gcs_location\n    self.bigquery_dataset_labels = {\n        'type': 'bq_direct_read_' + str(uuid.uuid4())[0:10]\n    }\n\n  def expand(self, pcoll):\n    if self.method == ReadFromBigQuery.Method.EXPORT:\n      output_pcollection = self._expand_export(pcoll)\n    elif self.method == ReadFromBigQuery.Method.DIRECT_READ:\n      output_pcollection = self._expand_direct_read(pcoll)","sourceCodeStart":3061,"sourceCodeEnd":3097,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery.py#L3061-L3097","documentation":"With output_type='BEAM_ROW', ReadFromBigQuery must produce a Beam schema for the output PCollection. When the input is a query, the schema cannot be inferred from an existing table, so query_output_schema is mandatory; ValueError is raised in __init__ (bigquery.py:3079) when it is missing.","triggerScenarios":"ReadFromBigQuery(query='SELECT ...', output_type='BEAM_ROW') without passing query_output_schema; using the default BEAM_ROW-ish output path with a query and only specifying selected_fields but no schema.","commonSituations":"Switching from a table input to a query while keeping output_type='BEAM_ROW'; building typed pipelines where users assume the schema is inferred from the SQL; copy-pasted examples that only set query.","solutions":["Pass query_output_schema as a BigQuery schema dict, e.g. {'fields': [{'name': 'col', 'type': 'STRING', 'mode': 'NULLABLE'}]}","Or pass a TableSchema object matching the query's output columns","Or use output_type='PYTHON_DICT' if typed rows are not needed"],"exampleFix":"// before\nReadFromBigQuery(query='SELECT name FROM ds.tbl', output_type='BEAM_ROW')\n// after\nReadFromBigQuery(query='SELECT name FROM ds.tbl', output_type='BEAM_ROW', query_output_schema={'fields': [{'name': 'name', 'type': 'STRING', 'mode': 'NULLABLE'}]})","handlingStrategy":"validation","validationCode":"if query and output_type == 'BEAM_ROW' and query_output_schema is None:\n    raise ValueError('query_output_schema is required with query + BEAM_ROW')","typeGuard":null,"tryCatchPattern":"try:\n    beam.io.ReadFromBigQuery(query=q, output_type='BEAM_ROW', ...)\nexcept ValueError as e:\n    if 'query_output_schema' in str(e):\n        # supply schema and retry\n        ...","preventionTips":["Keep query_output_schema next to query in your pipeline builder","Validate schema dict shape {'fields': [...]} before constructing","Use PYTHON_DICT when schema is unknown"],"tags":["python","apache-beam","bigquery","schema"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}