{"record":{"id":"935cc4d6bf763262","repo":"prestodb/presto","slug":"value-is-not-null-but-scale-stream-is-not-present","errorCode":null,"errorMessage":"Value is not null but scale stream is not present","messagePattern":"Value is not null but scale stream is not present","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/reader/DecimalBatchStreamReader.java","lineNumber":116,"sourceCode":"\n        seekToOffset();\n\n        if (decimalStream == null && scaleStream == null && presentStream != null) {\n            presentStream.skip(nextBatchSize);\n            Block nullValueBlock = RunLengthEncodedBlock.create(type, null, nextBatchSize);\n            readOffset = 0;\n            nextBatchSize = 0;\n            return nullValueBlock;\n        }\n\n        BlockBuilder builder = type.createBlockBuilder(null, nextBatchSize);\n\n        if (presentStream == null) {\n            if (decimalStream == null) {\n                throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), \"Value is not null but decimal stream is not present\");\n            }\n            if (scaleStream == null) {\n                throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), \"Value is not null but scale stream is not present\");\n            }\n\n            for (int i = 0; i < nextBatchSize; i++) {\n                long sourceScale = scaleStream.next();\n                if (type.isShort()) {\n                    long rescaledDecimal = Decimals.rescale(decimalStream.nextLong(), (int) sourceScale, type.getScale());\n                    type.writeLong(builder, rescaledDecimal);\n                }\n                else {\n                    Slice decimal = UnscaledDecimal128Arithmetic.unscaledDecimal();\n                    Slice rescaledDecimal = UnscaledDecimal128Arithmetic.unscaledDecimal();\n\n                    decimalStream.nextLongDecimal(decimal);\n                    rescale(decimal, (int) (type.getScale() - sourceScale), rescaledDecimal);\n                    type.writeSlice(builder, rescaledDecimal);\n                }\n            }\n        }","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/reader/DecimalBatchStreamReader.java#L98-L134","documentation":"DecimalBatchStreamReader.readBlock throws OrcCorruptionException when the present stream is null (all rows non-null) but the SECONDARY scale stream for the DECIMAL column is missing. ORC decimal encoding requires both a data stream for unscaled values and a secondary stream for scales, so a missing scale stream makes decoding impossible.","triggerScenarios":"readBlock on a DECIMAL column where presentStream == null and scaleStream == null — the stripe lacks the scale (secondary) stream though decimal values are expected.","commonSituations":"Files written by writers that omit secondary streams (non-conformant or buggy versions); truncated uploads; stripe metadata corruption mislabeling streams.","solutions":["Regenerate the ORC file with a spec-compliant writer that emits both decimal and scale streams.","Diagnose with orc-tools meta/scan and upgrade the producing writer if buggy.","Verify complete file transfer/replication (no partial copies).","Catch OrcCorruptionException and handle per policy (skip split, surface table error)."],"exampleFix":"// before\nBigDecimal v = readDecimalColumn(); // throws on missing scale stream\n// after\ntry { v = readDecimalColumn(); } catch (OrcCorruptionException e) { v = null; /* regenerate file */ }","handlingStrategy":"try-catch","validationCode":"// check for SECONDARY scale stream on decimal columns: orc-tools meta file.orc","typeGuard":null,"tryCatchPattern":"try { block = streamReader.readBlock(); } catch (OrcCorruptionException e) { handleCorruptSplit(e); }","preventionTips":["Ensure writers emit both decimal and scale streams (use maintained libraries)","Verify complete file replication before query","Add ORC validation to ingestion pipelines"],"tags":["orc","corruption","decimal","missing-stream","presto"],"backgroundTag":"orc-corruption-missing-stream","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"}