{"record":{"id":"19bf9fcf02930b10","repo":"apache/iceberg","slug":"updating-statistics-is-not-supported-by-getclass-19bf9f","errorCode":null,"errorMessage":"Updating statistics is not supported by + getClass().getName()","messagePattern":"Updating statistics is not supported by \\+ getClass\\(\\)\\.getName\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/Transaction.java","lineNumber":147,"sourceCode":"   * @return a new {@link ReplacePartitions}\n   */\n  ReplacePartitions newReplacePartitions();\n\n  /**\n   * Create a new {@link DeleteFiles delete API} to delete files in this table.\n   *\n   * @return a new {@link DeleteFiles}\n   */\n  DeleteFiles newDelete();\n\n  /**\n   * Create a new {@link UpdateStatistics update table statistics API} to add or remove statistics\n   * files in this table.\n   *\n   * @return a new {@link UpdateStatistics}\n   */\n  default UpdateStatistics updateStatistics() {\n    throw new UnsupportedOperationException(\n        \"Updating statistics is not supported by \" + getClass().getName());\n  }\n\n  /**\n   * Create a new {@link UpdatePartitionStatistics update partition statistics API} to add or remove\n   * partition statistics files in this table.\n   *\n   * @return a new {@link UpdatePartitionStatistics}\n   */\n  default UpdatePartitionStatistics updatePartitionStatistics() {\n    throw new UnsupportedOperationException(\n        \"Updating partition statistics is not supported by \" + getClass().getName());\n  }\n\n  /**\n   * Create a new {@link ExpireSnapshots expire API} to expire snapshots in this table.\n   *\n   * @return a new {@link ExpireSnapshots}","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/Transaction.java#L129-L165","documentation":"The default Transaction.updateStatistics() throws UnsupportedOperationException because transactions created by some implementations cannot stage table-statistics file changes. Only transaction implementations tied to tables supporting statistics updates override this method; the message names the concrete Transaction class lacking support.","triggerScenarios":"Calling transaction.updateStatistics() (e.g. in testEmptyTransactionalUpdateStatistics or orphan-file cleanup paths that remove statistics files transactionally) on a Transaction implementation that does not override it — commonly transactions created outside a full BaseTransaction context.","commonSituations":"Wrapping statistics updates inside a multi-operation transaction for atomicity; running ExpireSnapshots/statistics cleanup through a transaction on tables or wrappers that don't support transactional statistics updates.","solutions":["Apply the statistics update directly on the table (table.updateStatistics()...commit()) rather than inside the transaction.","Use the table's underlying transaction (BaseTable's transaction) which supports updateStatistics.","Catch UnsupportedOperationException and perform the statistics update as a separate commit.","Override updateStatistics() in custom Transaction implementations."],"exampleFix":"// before\nTransaction txn = table.newTransaction();\ntxn.updateStatistics().addStatisticsFile(stats).commit();\ntxn.commitTransaction();\n\n// after\ntable.updateStatistics().addStatisticsFile(stats).commit(); // direct, supported path","handlingStrategy":"fallback","validationCode":"// probe transaction support before staging statistics\ntry {\n  txn.updateStatistics();\n} catch (UnsupportedOperationException e) {\n  useDirectTableUpdate(table);\n}","typeGuard":"boolean txnSupportsStats(Transaction txn) {\n  try { txn.updateStatistics(); return true; }\n  catch (UnsupportedOperationException e) { return false; }\n}","tryCatchPattern":"try {\n  txn.updateStatistics().addStatisticsFile(f).commit();\n} catch (UnsupportedOperationException e) {\n  table.updateStatistics().addStatisticsFile(f).commit(); // standalone commit\n}","preventionTips":["Don't assume transactional statistics updates are universally supported; prefer direct table.updateStatistics()","Only stage statistics inside transactions obtained from full BaseTable implementations","Cover transaction statistics paths in tests for custom Transaction implementations"],"tags":["unsupported-operation","statistics","transaction"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}