{"record":{"id":"10e09afb0182dba9","repo":"prestodb/presto","slug":"can-not-read-sql-type-s-from-orc-stream-s-of-typ","errorCode":null,"errorMessage":"Can not read SQL type %s from ORC stream %s of type %s","messagePattern":"Can not read SQL type (.+?) from ORC stream (.+?) of type (.+?)","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/reader/ReaderUtils.java","lineNumber":35,"sourceCode":"import com.facebook.presto.orc.OrcCorruptionException;\nimport com.facebook.presto.orc.StreamDescriptor;\n\nimport java.util.function.Predicate;\n\nimport static java.lang.Math.max;\n\nfinal class ReaderUtils\n{\n    private ReaderUtils() {}\n\n    public static void verifyStreamType(StreamDescriptor streamDescriptor, Type actual, Predicate<Type> validTypes)\n            throws OrcCorruptionException\n    {\n        if (validTypes.test(actual)) {\n            return;\n        }\n\n        throw new OrcCorruptionException(\n                streamDescriptor.getOrcDataSourceId(),\n                \"Can not read SQL type %s from ORC stream %s of type %s\",\n                actual,\n                streamDescriptor.getStreamName(),\n                streamDescriptor.getOrcTypeKind());\n    }\n\n    public static int minNonNullValueSize(int nonNullCount)\n    {\n        return max(nonNullCount + 1, 1025);\n    }\n\n    public static byte[] unpackByteNulls(byte[] values, boolean[] isNull)\n    {\n        byte[] result = new byte[isNull.length];\n\n        int position = 0;\n        for (int i = 0; i < isNull.length; i++) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/reader/ReaderUtils.java#L17-L53","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Align the table schema with the actual ORC file column types","Regenerate the file with the expected types","Use the correct reader for the stream's ORC type kind","Run a schema/footighter validation (e.g., ORC metadata dump) before querying"],"exampleFix":"// before: mismatch at read time\nReaderUtils.verifyStreamType(descriptor, Optional.of(BIGINT), type -> type.equals(BIGINT));\n// after: confirm schema first\ncheckState(actualOrcType == INT_OR_LONG, \"Column %s must be an integer type in the file\", columnName);","handlingStrategy":"validation","validationCode":"Type actual = fileColumnTypes.get(columnName); if (outputType.isPresent() && !Objects.equals(actual, outputType.get())) { throw new SchemaMismatchException(columnName, actual, outputType.get()); }","typeGuard":"boolean schemaMatches(Type file, Type expected) { return expected.equals(file); }","tryCatchPattern":"try { verifyStreamType(descriptor, outputType, predicate); } catch (OrcCorruptionException e) { throw new SchemaMismatchException(\"File type does not match declared schema: \" + e.getMessage(), e); }","preventionTips":["Refresh table schema after any writer-side type changes","Diff file footer types against metastore schema during ingestion","Avoid ALTER COLUMN changes without rewriting underlying ORC files","Use ORC metadata tools to dump per-column types before querying"],"tags":["orc","schema-mismatch","type-validation","corruption"],"backgroundTag":"schema-mismatch","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"}