{"record":{"id":"b1c8bef2dc3928f7","repo":"apache/iceberg","slug":"s-doesn-t-implement-copywithstats","errorCode":null,"errorMessage":"%s doesn't implement copyWithStats","messagePattern":"(.+?) doesn't implement copyWithStats","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/ContentFile.java","lineNumber":215,"sourceCode":"   * Copies this file without file stats. Manifest readers can reuse file instances; use this method\n   * to copy data without stats when collecting files.\n   *\n   * @return a copy of this data file, without lower bounds, upper bounds, value counts, null value\n   *     counts, nan value counts, or average value sizes\n   */\n  F copyWithoutStats();\n\n  /**\n   * Copies this file with column stats only for specific columns. Manifest readers can reuse file\n   * instances; use this method to copy data with stats only for specific columns when collecting\n   * files.\n   *\n   * @param requestedColumnIds column IDs for which to keep stats.\n   * @return a copy of data file, with lower bounds, upper bounds, value counts, null value counts,\n   *     nan value counts, and average value sizes for only specific columns.\n   */\n  default F copyWithStats(Set<Integer> requestedColumnIds) {\n    throw new UnsupportedOperationException(\n        this.getClass().getName() + \" doesn't implement copyWithStats\");\n  }\n\n  /**\n   * Copies this file (potentially without file stats). Manifest readers can reuse file instances;\n   * use this method to copy data when collecting files from tasks.\n   *\n   * @param withStats Will copy this file without file stats if set to <code>false</code>.\n   * @return a copy of this data file. If <code>withStats</code> is set to <code>false</code> the\n   *     file will not contain lower bounds, upper bounds, value counts, null value counts, nan\n   *     value counts, or average value sizes\n   */\n  default F copy(boolean withStats) {\n    return withStats ? copy() : copyWithoutStats();\n  }\n}\n","sourceCodeStart":197,"sourceCodeEnd":232,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/ContentFile.java#L197-L232","documentation":"ContentFile.copyWithStats(Set<Integer>) is a default interface method that concrete File implementations must override to produce a copy filtered to the requested column stats. The default body throws UnsupportedOperationException naming the class that failed to implement it.","triggerScenarios":"Calling copyWithStats on a ContentFile implementation (custom, mock, or older library version) that has not overridden copyWithStats; using a DataFile built by hand rather than from a manifest reader.","commonSituations":"Custom FileIO/engine integrations subclassing a base file class that predates copyWithStats; test mocks returning plain DataFile instances; version skew between iceberg-api and iceberg-core jars.","solutions":["Upgrade iceberg-core/parquet modules so a full implementation (e.g. GenericDataFile) is used and consistent with iceberg-api.","If you wrote a custom ContentFile implementation, implement copyWithStats to copy the file while filtering lower/upper bounds, value counts, null/nan counts, and avg sizes to requestedColumnIds.","In tests, use real implementations (GenericDataFile.copy) rather than partial stubs."],"exampleFix":"// before\nclass MyDataFile implements DataFile { /* no copyWithStats */ }\n\n// after\n@Override\npublic MyDataFile copyWithStats(Set<Integer> requestedColumnIds) {\n  MyDataFile copy = copy();\n  copy.setColumnStats filtered to requestedColumnIds;\n  return copy;\n}","handlingStrategy":"type-guard","validationCode":"if (!(file instanceof GenericDataFile)) {\n  // may not implement copyWithStats — use file.copy() or upgrade\n}","typeGuard":null,"tryCatchPattern":"DataFile copy;\ntry {\n  copy = file.copyWithStats(colIds);\n} catch (UnsupportedOperationException e) {\n  copy = file.copy(); // degrade: full copy without stat filtering\n}","preventionTips":["Keep iceberg-api and implementation jars at the same version.","Use real implementations (GenericDataFile) not stubs in tests.","Implement copyWithStats in any custom ContentFile class.","Prefer files produced by manifest readers, which support stat copies."],"tags":["unsupported-operation","api","content-file","statistics"],"backgroundTag":"method-not-implemented","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"}