prestodb/presto · error · BigQueryException

BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD

BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD

Error message

Error reading next Avro Record

What it means

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.

Source

Thrown at presto-bigquery/src/main/java/com/facebook/presto/plugin/bigquery/BigQueryResultPageSource.java:332

        @Override
        public boolean hasNext()
        {
            try {
                return !decode.isEnd();
            }
            catch (IOException e) {
                throw new BigQueryException(BIGQUERY_ERROR_END_OF_AVRO_BUFFER, "Error determining the end of Avro buffer", e);
            }
        }

        @Override
        public GenericRecord next()
        {
            try {
                return reader.read(null, decode);
            }
            catch (IOException e) {
                throw new BigQueryException(BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD, "Error reading next Avro Record", e);
            }
        }
    }

    static class AvroDecimalConverter
    {
        private static final Conversions.DecimalConversion AVRO_DECIMAL_CONVERSION = new Conversions.DecimalConversion();
        private static final Schema AVRO_DECIMAL_SCHEMA = new Schema.Parser().parse(format(
                "{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":%d,\"scale\":%d}",
                NUMERIC_DATA_TYPE_PRECISION, NUMERIC_DATA_TYPE_SCALE));

        BigDecimal convert(Object value)
        {
            return AVRO_DECIMAL_CONVERSION.fromBytes((ByteBuffer) value, AVRO_DECIMAL_SCHEMA, AVRO_DECIMAL_SCHEMA.getLogicalType());
        }
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Retry the scan; transient stream errors usually succeed on re-run
  2. Re-create the read session (retry the split)
  3. Verify the table's Avro schema compatibility and BigQuery Storage API health
  4. Check connectivity/proxy settings between the cluster and Google
Defensive patterns

Strategy: retry

Validate before calling

// preflight: ensure the table is readable and session streams exist
Table table = bigQueryClient.getTable(tableId);
if (table == null) throw new IllegalStateException("Table missing: " + tableId);
ReadSession session = bigQueryClient.createReadSession(request);
if (session.getStreamsCount() == 0) throw new IllegalStateException("No Avro streams");

Try / catch

try {
    return pageSource.getNextPage(...);
} catch (BigQueryException e) {
    if (BIGQUERY_ERROR_READING_NEXT_AVRO_RECORD.getCode() == e.getErrorCode().getCode()) {
        // recreate read session and retry the split once
        return retryWithNewSession();
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Unstable network to Google APIs; Avro schema incompatible with the reader; large scans timing out; backend errors mid-stream.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/c9dfa0c8b2479025. Report an issue: GitHub.