{"record":{"id":"4cf6a96739dd8874","repo":"apache/beam","slug":"read-session-does-not-have-avro-arrow-schema-set","errorCode":null,"errorMessage":"Read session does not have Avro/Arrow schema set.","messagePattern":"Read session does not have Avro/Arrow schema set\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryStorageReaderFactory.java","lineNumber":33,"sourceCode":" * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.beam.sdk.io.gcp.bigquery;\n\nimport com.google.cloud.bigquery.storage.v1.ReadSession;\nimport java.io.IOException;\n\nclass BigQueryStorageReaderFactory {\n\n  private BigQueryStorageReaderFactory() {}\n\n  public static BigQueryStorageReader getReader(ReadSession readSession) throws IOException {\n    if (readSession.hasAvroSchema()) {\n      return new BigQueryStorageAvroReader(readSession);\n    } else if (readSession.hasArrowSchema()) {\n      return new BigQueryStorageArrowReader(readSession);\n    }\n    throw new IllegalStateException(\"Read session does not have Avro/Arrow schema set.\");\n  }\n}\n","sourceCodeStart":15,"sourceCodeEnd":36,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryStorageReaderFactory.java#L15-L36","documentation":"BigQueryStorageReaderFactory.getReader chooses an Avro or Arrow reader based on which schema the Storage Read API ReadSession carries. If the session has neither an Avro nor Arrow schema set, no reader implementation is applicable, so an IllegalStateException is thrown. This indicates the ReadSession was created without the expected serialization options.","triggerScenarios":"Calling BigQueryStorageReaderFactory.getReader(readSession) with a ReadSession whose readOptions/serialization options did not set an avro_schema or arrow_schema — typically a session created with DataFormat unset, or a server response that omitted both schemas.","commonSituations":"Building a custom Storage Read API source and forgetting to set the format (AVRO/ARROW) in TableReadOptions; a BigQuery backend returning a session without the requested schema after a silent fallback; mixing Beam versions where DataFormat defaults changed.","solutions":["Set an explicit data format when creating the source/session, e.g. .withMethod(DIRECT_READ).withFormat(DataFormat.AVRO) (or ARROW)","Log/inspect the ReadSession (readSession.hasAvroSchema()/hasArrowSchema()) immediately after creation to catch empty sessions early","Retry session creation — a transient backend issue can omit schema; recreate the ReadSession","Upgrade the google-cloud-bigquery-storage client and Beam GCP SDK to a version matching your DataFormat support"],"exampleFix":"// before\nReadSession session = createSession(request); // DataFormat not set\nBigQueryStorageReader reader = BigQueryStorageReaderFactory.getReader(session);\n// after\nReadSession session = createSession(request.toBuilder()\n    .setReadOptions(ReadSession.TableReadOptions.newBuilder()\n        .setArrowSerializationOptions(...)) // or set data format AVRO/ARROW\n    .build());\nif (!session.hasAvroSchema() && !session.hasArrowSchema()) {\n  session = recreateSessionWithFormat(DataFormat.AVRO);\n}\nBigQueryStorageReader reader = BigQueryStorageReaderFactory.getReader(session);","handlingStrategy":"validation","validationCode":"if (readSession == null || (!readSession.hasAvroSchema() && !readSession.hasArrowSchema())) {\n  throw new IllegalArgumentException(\"ReadSession must be created with AVRO or ARROW format\");\n}","typeGuard":"boolean hasSerializableSchema(ReadSession s) {\n  return s != null && (s.hasAvroSchema() || s.hasArrowSchema());\n}","tryCatchPattern":"try {\n  return BigQueryStorageReaderFactory.getReader(session);\n} catch (IllegalStateException e) {\n  // recreate the session with explicit DataFormat before failing\n  session = recreateSessionWithFormat(DataFormat.AVRO);\n  return BigQueryStorageReaderFactory.getReader(session);\n}","preventionTips":["Always set an explicit DataFormat (AVRO or ARROW) when creating Storage Read API sources","Validate the ReadSession right after creation, before distributing to workers","Keep Beam and google-cloud-bigquery-storage client versions aligned"],"tags":["bigquery","storage-read-api","read-session","state"],"backgroundTag":"invalid-state-transition","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}