{"record":{"id":"c9dfa0c8b2479025","repo":"prestodb/presto","slug":"bigquery-error-reading-next-avro-record","errorCode":"BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD","errorMessage":"Error reading next Avro Record","messagePattern":"Error reading next Avro Record","errorType":"error_code","errorClass":"BigQueryException","httpStatus":null,"severity":"error","filePath":"presto-bigquery/src/main/java/com/facebook/presto/plugin/bigquery/BigQueryResultPageSource.java","lineNumber":332,"sourceCode":"        @Override\n        public boolean hasNext()\n        {\n            try {\n                return !decode.isEnd();\n            }\n            catch (IOException e) {\n                throw new BigQueryException(BIGQUERY_ERROR_END_OF_AVRO_BUFFER, \"Error determining the end of Avro buffer\", e);\n            }\n        }\n\n        @Override\n        public GenericRecord next()\n        {\n            try {\n                return reader.read(null, decode);\n            }\n            catch (IOException e) {\n                throw new BigQueryException(BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD, \"Error reading next Avro Record\", e);\n            }\n        }\n    }\n\n    static class AvroDecimalConverter\n    {\n        private static final Conversions.DecimalConversion AVRO_DECIMAL_CONVERSION = new Conversions.DecimalConversion();\n        private static final Schema AVRO_DECIMAL_SCHEMA = new Schema.Parser().parse(format(\n                \"{\\\"type\\\":\\\"bytes\\\",\\\"logicalType\\\":\\\"decimal\\\",\\\"precision\\\":%d,\\\"scale\\\":%d}\",\n                NUMERIC_DATA_TYPE_PRECISION, NUMERIC_DATA_TYPE_SCALE));\n\n        BigDecimal convert(Object value)\n        {\n            return AVRO_DECIMAL_CONVERSION.fromBytes((ByteBuffer) value, AVRO_DECIMAL_SCHEMA, AVRO_DECIMAL_SCHEMA.getLogicalType());\n        }\n    }\n}\n","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-bigquery/src/main/java/com/facebook/presto/plugin/bigquery/BigQueryResultPageSource.java#L314-L350","documentation":"next() calls Avro reader.read(null, decode) to get the next GenericRecord from the BigQuery Storage Avro stream; any IOException is wrapped as BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD. It indicates the Avro payload could not be read or deserialized, usually due to a broken stream or corrupt data.","triggerScenarios":"An IOException thrown while deserializing the next Avro record from a BigQuery read session stream — connection drop, truncated buffer, or schema mismatch causing decode failure.","commonSituations":"Unstable network to Google APIs; Avro schema incompatible with the reader; large scans timing out; backend errors mid-stream.","solutions":["Retry the scan; transient stream errors usually succeed on re-run","Re-create the read session (retry the split)","Verify the table's Avro schema compatibility and BigQuery Storage API health","Check connectivity/proxy settings between the cluster and Google"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// preflight: ensure the table is readable and session streams exist\nTable table = bigQueryClient.getTable(tableId);\nif (table == null) throw new IllegalStateException(\"Table missing: \" + tableId);\nReadSession session = bigQueryClient.createReadSession(request);\nif (session.getStreamsCount() == 0) throw new IllegalStateException(\"No Avro streams\");","typeGuard":null,"tryCatchPattern":"try {\n    return pageSource.getNextPage(...);\n} catch (BigQueryException e) {\n    if (BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD.getCode() == e.getErrorCode().getCode()) {\n        // recreate read session and retry the split once\n        return retryWithNewSession();\n    }\n    throw e;\n}","preventionTips":["Retry failed splits with a fresh read session","Verify table schema compatibility before large scans","Increase timeouts for large scans over unstable networks","Alert on repeated Avro decode failures (indicates corrupt data or schema drift)"],"tags":["bigquery","avro","deserialization","io"],"backgroundTag":"avro-stream-read-failure","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}