{"record":{"id":"fcb49093474a47d9","repo":"apache/iceberg","slug":"unsupported-time-unit","errorCode":null,"errorMessage":"Unsupported time unit: ","messagePattern":"Unsupported time unit: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/transforms/Dates.java","lineNumber":61,"sourceCode":"    Apply(ChronoUnit granularity) {\n      this.granularity = granularity;\n    }\n\n    @Override\n    public Integer apply(Integer days) {\n      if (days == null) {\n        return null;\n      }\n\n      switch (granularity) {\n        case YEARS:\n          return DateTimeUtil.daysToYears(days);\n        case MONTHS:\n          return DateTimeUtil.daysToMonths(days);\n        case DAYS:\n          return days;\n        default:\n          throw new UnsupportedOperationException(\"Unsupported time unit: \" + granularity);\n      }\n    }\n  }\n\n  private final ChronoUnit granularity;\n  private final String name;\n  private final Apply apply;\n\n  Dates(ChronoUnit granularity, String name) {\n    this.granularity = granularity;\n    this.name = name;\n    this.apply = new Apply(granularity);\n  }\n\n  /**\n   * Transforms a value to its corresponding partition value.\n   *\n   * @param days a source value","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/transforms/Dates.java#L43-L79","documentation":"Dates.DateToYearsTransform (and sibling date transforms) apply only to a fixed set of granularities: YEARS, MONTHS, DAYS. If apply() encounters any other ChronoUnit, Iceberg throws UnsupportedOperationException. This indicates the transform was constructed or dispatched with a granularity the date transform does not implement.","triggerScenarios":"Building a Dates transform (e.g. via TransformUtil or parsing) with a granularity outside YEARS/MONTHS/DAYS (e.g. HOURS, MINUTES), then calling apply(days).","commonSituations":"Parsing partition field transforms from strings or specs where an invalid granularity slipped in; generic transform-dispatch code reusing a date transform for hour-level source data (which belongs to the Hours/ timestamps transforms).","solutions":["Use the correct transform family: Dates for day-granularity sources, Hours for hour sources, or a timestamp transform for finer units.","Validate granularity is one of ChronoUnit.YEARS/MONTHS/DAYS before constructing/calling the date transform.","Catch UnsupportedOperationException at dispatch boundaries when translating unknown granularities."],"exampleFix":"// before\nTransform<Integer, Integer> t = Dates.from(granularity); // granularity = HOURS\nInteger out = t.apply(days);\n// after\nPreconditions.checkArgument(granularity == ChronoUnit.YEARS || granularity == ChronoUnit.MONTHS || granularity == ChronoUnit.DAYS, \"Invalid date granularity: %s\", granularity);\nTransform<Integer, Integer> t = Dates.from(granularity);","handlingStrategy":"validation","validationCode":"if (granularity != ChronoUnit.YEARS && granularity != ChronoUnit.MONTHS && granularity != ChronoUnit.DAYS) { throw new IllegalArgumentException(\"Invalid date granularity: \" + granularity); }","typeGuard":"boolean isDateGranularity(ChronoUnit u) { return u == ChronoUnit.YEARS || u == ChronoUnit.MONTHS || u == ChronoUnit.DAYS; }","tryCatchPattern":"try { return dateTransform.apply(days); } catch (UnsupportedOperationException e) { throw new IllegalArgumentException(\"Granularity not supported by date transform\", e); }","preventionTips":["Route HOUR-granularity data to the Hours transform, not Dates","Validate granularity when parsing transforms from strings","Enumerate supported granularities in a constant set and check membership"],"tags":["java","transforms","dates","unsupported-operation"],"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"}