{"record":{"id":"bbc0fb65ad1b1ed4","repo":"apache/iceberg","slug":"invalid-statistics-type-type-should-be-map-or","errorCode":null,"errorMessage":"Invalid statistics type: ${type}. Should be Map or Sketch","messagePattern":"Invalid statistics type: (.+?)\\. Should be Map or Sketch","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/shuffle/RangePartitioner.java","lineNumber":79,"sourceCode":"    }\n  }\n\n  private AtomicLong roundRobinCounter(int numPartitions) {\n    if (roundRobinCounter == null) {\n      // randomize the starting point to avoid synchronization across subtasks\n      this.roundRobinCounter = new AtomicLong(new Random().nextInt(numPartitions));\n    }\n\n    return roundRobinCounter;\n  }\n\n  private Partitioner<RowData> delegatePartitioner(GlobalStatistics statistics) {\n    if (statistics.type() == StatisticsType.Map) {\n      return new MapRangePartitioner(schema, sortOrder, statistics.mapAssignment());\n    } else if (statistics.type() == StatisticsType.Sketch) {\n      return new SketchRangePartitioner(schema, sortOrder, statistics.rangeBounds());\n    } else {\n      throw new IllegalArgumentException(\n          String.format(\"Invalid statistics type: %s. Should be Map or Sketch\", statistics.type()));\n    }\n  }\n\n  /**\n   * Util method that handles rescale (write parallelism / numPartitions change).\n   *\n   * @param partition partition calculated based on the existing statistics\n   * @param numPartitionsStatsCalculation number of partitions when the assignment was calculated\n   *     based on\n   * @param numPartitions current number of partitions\n   * @return adjusted partition if necessary.\n   */\n  static int adjustPartitionWithRescale(\n      int partition, int numPartitionsStatsCalculation, int numPartitions) {\n    if (numPartitionsStatsCalculation <= numPartitions) {\n      // no rescale or scale-up case.\n      // new subtasks are ignored and not assigned any keys, which is sub-optimal and only","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/shuffle/RangePartitioner.java#L61-L97","documentation":"RangePartitioner.delegatePartitioner selects a concrete partitioner based on the GlobalStatistics type: Map uses MapRangePartitioner, Sketch uses SketchRangePartitioner. Any other type is invalid because range partitioning requires one of these statistics forms. This is a defensive dispatch guard.","triggerScenarios":"Feeding a GlobalStatistics with an unrecognized StatisticsType into partition(), typically from deserialized state written by an incompatible connector version or a corrupt statistics payload.","commonSituations":"Checkpoint/savepoint restore across connector versions, or mixed jar versions among TaskManagers during a shuffle job.","solutions":["Use matching connector versions for job submission and all TaskManagers.","Restart from clean state instead of restoring an incompatible checkpoint.","Confirm the GlobalStatistics instance was produced by this library's coordinator."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"StatisticsType t = statistics.type();\nif (t != StatisticsType.Map && t != StatisticsType.Sketch) {\n  throw new IllegalArgumentException(\"Range partitioning requires Map or Sketch statistics, got \" + t);\n}","typeGuard":"boolean hasUsableStatistics(GlobalStatistics s) {\n  return s.type() == StatisticsType.Map || s.type() == StatisticsType.Sketch;\n}","tryCatchPattern":"try {\n  partitioner = delegatePartitioner(globalStatistics);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid statistics type\")) {\n    partitioner = fallbackRoundRobinPartitioner;\n  } else throw e;\n}","preventionTips":["Only feed GlobalStatistics produced by this connector's coordinator.","Ensure checkpoint restore uses the same connector version.","Keep cluster jar versions consistent."],"tags":["flink","shuffle","partitioning"],"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"}