{"record":{"id":"0be69cf3358459fa","repo":"apache/iceberg","slug":"orc-cannot-read-default-value-for-field-s-s","errorCode":null,"errorMessage":"ORC cannot read default value for field %s (%s): %s","messagePattern":"ORC cannot read default value for field (.+?) \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"orc/src/main/java/org/apache/iceberg/orc/ORCSchemaUtil.java","lineNumber":408,"sourceCode":"            Preconditions.checkArgument(\n                isSameType(originalType, type),\n                \"Can not promote %s type to %s\",\n                originalType.getCategory(),\n                type.typeId().name());\n            orcType = originalType.clone();\n          }\n        } else {\n          Types.NestedField field = root.findField(fieldId);\n          if (isRequired) {\n            Preconditions.checkArgument(\n                field.initialDefault() != null,\n                \"Missing required field: %s (%s)\",\n                root.findColumnName(fieldId),\n                type);\n          }\n\n          if (field.initialDefault() != null) {\n            throw new UnsupportedOperationException(\n                String.format(\n                    \"ORC cannot read default value for field %s (%s): %s\",\n                    root.findColumnName(fieldId), type, field.initialDefault()));\n          }\n\n          orcType = convert(fieldId, type, false);\n        }\n    }\n\n    if (orcType != null) {\n      orcType.setAttribute(ICEBERG_ID_ATTRIBUTE, fieldId.toString());\n    }\n\n    return orcType;\n  }\n\n  private static Map<Integer, OrcField> icebergToOrcMapping(String name, TypeDescription orcType) {\n    Map<Integer, OrcField> icebergToOrc = Maps.newHashMap();","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/orc/src/main/java/org/apache/iceberg/orc/ORCSchemaUtil.java#L390-L426","documentation":"During buildOrcProjection, an Iceberg field missing from the ORC file is handled by writing a column filled with the field's default value. ORC's VectorizedRowBatch machinery cannot materialize Iceberg initial-default values, so if the field declares a non-null initialDefault an UnsupportedOperationException with the field name, type, and default is thrown. The error occurs at read planning time, not mid-scan of data.","triggerScenarios":"Reading (projection building for) an ORC data file whose schema predates an Iceberg schema evolution that ADDED a required field with an initialDefault; the missing field must be back-filled and its initialDefault() is non-null.","commonSituations":"Schema evolution: ALTER TABLE ADD COLUMN with a default value on an ORC table, then scanning old ORC files written before the column existed; ORC format does not support default-value materialization the way Parquet readers do.","solutions":["Add the column without an initialDefault (or use write-default only), then rewrite data files so old files contain the column.","Rewrite old ORC data files (e.g. rewrite_data_files / Spark rewrite) so the added column physically exists and no default back-fill is needed.","Drop the requirement/default for the field, or use a file format whose reader supports initial-default materialization (Parquet)."],"exampleFix":"// before\nALTER TABLE t ADD COLUMN status STRING NOT NULL WITH default 'new';\n// old ORC files: UnsupportedOperationException\n\n// after\nALTER TABLE t ADD COLUMN status STRING; -- nullable, no initialDefault\n-- then backfill data via rewrite/update instead of relying on reader-side defaults","handlingStrategy":"try-catch","validationCode":"// detect problematic evolved fields before scanning\nTypes.NestedField f = schema.findField(fieldId);\nif (f != null && f.isOptional() == false && f.initialDefault() != null && !fileContainsColumn) {\n  throw new UnsupportedOperationException(\"Rewrite files before scan: \" + f.name());\n}","typeGuard":null,"tryCatchPattern":"try {\n  CloseableIterable<Record> rows = read.build();\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().startsWith(\"ORC cannot read default value\")) {\n    // trigger rewrite_data_files or fall back to Parquet path\n  }\n}","preventionTips":["Avoid adding required columns with initialDefault on ORC tables; use nullable columns plus backfill","Run rewrite_data_files after schema evolution so old files contain new columns","Parquet handles reader-side defaults; prefer it when default-value evolution is required"],"tags":["java","orc","schema-evolution","default-value"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}