{"record":{"id":"3f2567e40b1b79b2","repo":"apache/iceberg","slug":"failed-to-get-statistics-from-writer","errorCode":null,"errorMessage":"Failed to get statistics from writer","messagePattern":"Failed to get statistics from writer","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"orc/src/main/java/org/apache/iceberg/orc/OrcMetrics.java","lineNumber":119,"sourceCode":"          metricsConfig,\n          mapping);\n    } catch (IOException ioe) {\n      throw new RuntimeIOException(ioe, \"Failed to open file: %s\", file.location());\n    }\n  }\n\n  static Metrics fromWriter(\n      Writer writer, Stream<FieldMetrics<?>> fieldMetricsStream, MetricsConfig metricsConfig) {\n    try {\n      return buildOrcMetrics(\n          writer.getNumberOfRows(),\n          writer.getSchema(),\n          writer.getStatistics(),\n          fieldMetricsStream,\n          metricsConfig,\n          null);\n    } catch (IOException ioe) {\n      throw new RuntimeIOException(ioe, \"Failed to get statistics from writer\");\n    }\n  }\n\n  private static Metrics buildOrcMetrics(\n      final long numOfRows,\n      final TypeDescription orcSchema,\n      final ColumnStatistics[] colStats,\n      final Stream<FieldMetrics<?>> fieldMetricsStream,\n      final MetricsConfig metricsConfig,\n      final NameMapping mapping) {\n    TypeDescription orcSchemaWithIds;\n    if (ORCSchemaUtil.hasIds(orcSchema)) {\n      orcSchemaWithIds = orcSchema;\n    } else if (mapping != null) {\n      orcSchemaWithIds = ORCSchemaUtil.applyNameMapping(orcSchema, mapping);\n    } else {\n      return new Metrics(numOfRows);\n    }","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/orc/src/main/java/org/apache/iceberg/orc/OrcMetrics.java#L101-L137","documentation":"OrcMetrics.fromWriter computes metrics from an in-progress ORC Writer by asking it for its schema and accumulated statistics. Any IOException from writer.getStatistics() is wrapped in RuntimeIOException without a file path (the message does not include one because metrics may be gathered before/without a file location). This reflects a failure reading live writer state, not the data file.","triggerScenarios":"Calling OrcMetrics.fromWriter(writer, fieldMetricsStream, metricsConfig) during appender close/commit when the ORC Writer's internal statistics retrieval throws IOException (writer already failed/closed, backend error while reading buffered stripe stats).","commonSituations":"Commit path computing metrics after an earlier write failure left the writer in a bad state; storage-backend errors (S3/HDFS) while the ORC Writer materializes statistics during finalization.","solutions":["Inspect the underlying IOException cause; treat it as a symptom of the failed write — retry the whole write task so a healthy writer produces metrics.","Ensure fromWriter is only called while the Writer is open and healthy (typically inside the appender's close/commit flow).","Check storage backend health/permissions; if the writer already failed on an earlier I/O error, fix that root cause first."],"exampleFix":"// before (writer in failed state)\nMetrics metrics = OrcMetrics.fromWriter(writer, metricsStream, config); // RuntimeIOException\n\n// after: only extract metrics from a successfully-written writer\ntry (FileAppender<Record> app = ORC.write(out).schema(schema).metricsConfig(config).build()) {\n  app.addAll(records);\n  // metrics are computed internally on close from the healthy writer\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  Metrics m = OrcMetrics.fromWriter(writer, metricsStream, config);\n} catch (RuntimeIOException e) {\n  LOG.error(\"Writer statistics unavailable: {}\", e.getCause());\n  throw e; // retry the entire write task\n}","preventionTips":["Only extract metrics from a writer that has not failed on a prior I/O operation","Treat statistics failures as write-task failures and retry the whole task","Check storage backend health when finalizing ORC files"],"tags":["java","orc","metrics","io"],"backgroundTag":"file-read-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}