prestodb/presto · error · OrcCorruptionException

Can not read SQL type %s from ORC stream %s of type %s

Error message

Can not read SQL type %s from ORC stream %s of type %s

What it means

ReaderUtils.verifyStreamType validates that an ORC stream's actual SQL type is acceptable for the reader being constructed. If the predicate fails it throws OrcCorruptionException describing the SQL type, stream name, and ORC type kind. It guards against schema mismatches between the declared table schema and the file's stored types.

Source

Thrown at presto-orc/src/main/java/com/facebook/presto/orc/reader/ReaderUtils.java:35

import com.facebook.presto.orc.OrcCorruptionException;
import com.facebook.presto.orc.StreamDescriptor;

import java.util.function.Predicate;

import static java.lang.Math.max;

final class ReaderUtils
{
    private ReaderUtils() {}

    public static void verifyStreamType(StreamDescriptor streamDescriptor, Type actual, Predicate<Type> validTypes)
            throws OrcCorruptionException
    {
        if (validTypes.test(actual)) {
            return;
        }

        throw new OrcCorruptionException(
                streamDescriptor.getOrcDataSourceId(),
                "Can not read SQL type %s from ORC stream %s of type %s",
                actual,
                streamDescriptor.getStreamName(),
                streamDescriptor.getOrcTypeKind());
    }

    public static int minNonNullValueSize(int nonNullCount)
    {
        return max(nonNullCount + 1, 1025);
    }

    public static byte[] unpackByteNulls(byte[] values, boolean[] isNull)
    {
        byte[] result = new byte[isNull.length];

        int position = 0;
        for (int i = 0; i < isNull.length; i++) {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Align the table schema with the actual ORC file column types
  2. Regenerate the file with the expected types
  3. Use the correct reader for the stream's ORC type kind
  4. Run a schema/footighter validation (e.g., ORC metadata dump) before querying

Example fix

// before: mismatch at read time
ReaderUtils.verifyStreamType(descriptor, Optional.of(BIGINT), type -> type.equals(BIGINT));
// after: confirm schema first
checkState(actualOrcType == INT_OR_LONG, "Column %s must be an integer type in the file", columnName);
Defensive patterns

Strategy: validation

Validate before calling

Type actual = fileColumnTypes.get(columnName); if (outputType.isPresent() && !Objects.equals(actual, outputType.get())) { throw new SchemaMismatchException(columnName, actual, outputType.get()); }

Type guard

boolean schemaMatches(Type file, Type expected) { return expected.equals(file); }

Try / catch

try { verifyStreamType(descriptor, outputType, predicate); } catch (OrcCorruptionException e) { throw new SchemaMismatchException("File type does not match declared schema: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: Constructing a stream reader with an outputType whose SQL type doesn't match the ORC stream's type (e.g., reading a VARCHAR column as BIGINT, or a map column where a scalar is expected).

Common situations: Stale table schema after the underlying file format changed; Hive Metastore schema mismatch with file contents; reading files written with different column types than declared.

Related errors


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