{"record":{"id":"905de2a7d78a1e27","repo":"apache/iceberg","slug":"unsupported-data-statistics-type-statisticstype","errorCode":null,"errorMessage":"Unsupported data statistics type: ${statisticsType}","messagePattern":"Unsupported data statistics type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/shuffle/DataStatisticsSerializer.java","lineNumber":91,"sourceCode":"  public DataStatistics copy(DataStatistics obj) {\n    StatisticsType statisticsType = obj.type();\n    if (statisticsType == StatisticsType.Map) {\n      MapDataStatistics from = (MapDataStatistics) obj;\n      Map<SortKey, Long> fromStats = (Map<SortKey, Long>) from.result();\n      Map<SortKey, Long> toStats = Maps.newHashMap(fromStats);\n      return new MapDataStatistics(toStats);\n    } else if (statisticsType == StatisticsType.Sketch) {\n      // because ReservoirItemsSketch doesn't expose enough public methods for cloning,\n      // this implementation adopted the less efficient serialization and deserialization.\n      SketchDataStatistics from = (SketchDataStatistics) obj;\n      ReservoirItemsSketch<SortKey> fromStats = (ReservoirItemsSketch<SortKey>) from.result();\n      byte[] bytes = fromStats.toByteArray(sketchSerializer);\n      Memory memory = Memory.wrap(bytes);\n      ReservoirItemsSketch<SortKey> toStats =\n          ReservoirItemsSketch.heapify(memory, sketchSerializer);\n      return new SketchDataStatistics(toStats);\n    } else {\n      throw new IllegalArgumentException(\"Unsupported data statistics type: \" + statisticsType);\n    }\n  }\n\n  @Override\n  public DataStatistics copy(DataStatistics from, DataStatistics reuse) {\n    // not much benefit to reuse\n    return copy(from);\n  }\n\n  @Override\n  public int getLength() {\n    return -1;\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  @Override\n  public void serialize(DataStatistics obj, DataOutputView target) throws IOException {\n    StatisticsType statisticsType = obj.type();","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/sink/shuffle/DataStatisticsSerializer.java#L73-L109","documentation":"DataStatisticsSerializer.copy delegates to serialize/deserialize after determining the StatisticsType. If the type is neither Map nor Sketch, copy throws IllegalArgumentException('Unsupported data statistics type: ...'). This indicates a DataStatistics implementation or type value the serializer does not know how to deep-copy.","triggerScenarios":"copy(from, reuse) is invoked by Flink on a DataStatistics whose type() returns a value outside {Map, Sketch} — e.g. a custom DataStatistics implementation passed into the statistics-based sink, or a type added in a newer connector version processed by an older serializer.","commonSituations":"Custom DataStatistics implementations registered into the shuffle sink; forward/backward version skew between job jars during a savepoint restore; corrupted type metadata in shipped state.","solutions":["Use only the built-in MapDataStatistics / SketchDataStatistics types with the shuffle sink","Ensure the same connector version is used across the whole job and when restoring from a savepoint","Check the statisticsType value in the message; if it is null or odd, trace where the DataStatistics was created","Remove any custom DataStatistics wrapper classes from the sink configuration"],"exampleFix":"// before: custom type\nDataStatistics stats = new MyCustomStatistics();\n// after: built-in types only\nDataStatistics stats = new MapDataStatistics(map);","handlingStrategy":"type-guard","validationCode":"StatisticsType t = from != null ? from.type() : null;\nif (t != StatisticsType.Map && t != StatisticsType.Sketch) {\n  throw new IllegalArgumentException(\"Pre-check: unsupported statistics type \" + t);\n}","typeGuard":"static boolean isSupportedStatistics(DataStatistics s) {\n  return s instanceof MapDataStatistics || s instanceof SketchDataStatistics;\n}","tryCatchPattern":"try {\n  serializer.copy(stats, null);\n} catch (IllegalArgumentException e) {\n  // fall back to dropping statistics or rebuilding a supported instance\n}","preventionTips":["Use only built-in DataStatistics implementations with the shuffle sink","Avoid savepoint restores across connector major-version gaps","Audit any custom subclasses of DataStatistics before enabling statistics-based sinks"],"tags":["flink","serialization","data-statistics","type-mismatch"],"backgroundTag":"unsupported-enum-value","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"}