{"record":{"id":"1f1cf62c3d7c9e32","repo":"apache/iceberg","slug":"unsupported-time-unit-timestampunit","errorCode":null,"errorMessage":"Unsupported time unit: + timestampUnit","messagePattern":"Unsupported time unit: \\+ timestampUnit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/transforms/Timestamps.java","lineNumber":94,"sourceCode":"              return DateTimeUtil.microsToHours(timestamp);\n            default:\n              throw new UnsupportedOperationException(\"Unsupported time unit: \" + granularity);\n          }\n        case NANOS:\n          switch (granularity) {\n            case YEARS:\n              return DateTimeUtil.nanosToYears(timestamp);\n            case MONTHS:\n              return DateTimeUtil.nanosToMonths(timestamp);\n            case DAYS:\n              return DateTimeUtil.nanosToDays(timestamp);\n            case HOURS:\n              return DateTimeUtil.nanosToHours(timestamp);\n            default:\n              throw new UnsupportedOperationException(\"Unsupported time unit: \" + granularity);\n          }\n        default:\n          throw new UnsupportedOperationException(\"Unsupported time unit: \" + timestampUnit);\n      }\n    }\n  }\n\n  private final ChronoUnit granularity;\n  private final String name;\n  private final Apply apply;\n\n  Timestamps(ChronoUnit granularity, String name, TimestampUnit timestampUnit) {\n    this.name = name;\n    this.granularity = granularity;\n    this.apply = new Apply(granularity, timestampUnit);\n  }\n\n  /**\n   * Transforms a value to its corresponding partition value.\n   *\n   * @param timestamp a source value","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/transforms/Timestamps.java#L76-L112","documentation":"Thrown by the bound Timestamps transform's apply() when the timestamp precision unit itself (the outer switch) is neither MICROS nor NANOS. Iceberg only defines two timestamp precisions — microseconds and nanoseconds — so a Timestamps transform built with any other ChronoUnit as the unit is fundamentally unusable.","triggerScenarios":"Calling apply() on a bound Timestamps transform whose timestampUnit is ChronoUnit.SECOND, MINUTE, or any unit other than MICROS/NANOS — e.g. from a hand-constructed or deserialized transform with a bogus precision.","commonSituations":"Custom code constructing Timestamps directly instead of via Transforms factories; parsing a partition spec where the timestamp precision field was corrupted or hand-edited.","solutions":["Construct the transform only with ChronoUnit.MICROS or ChronoUnit.NANOS as the timestamp unit","Use Transforms.year/month/day/hour factory methods, which always produce a valid precision/granularity pair","Validate the precision field when deserializing transform specs and reject unknown values early"],"exampleFix":"// before\nnew Timestamps(ChronoUnit.SECONDS, ChronoUnit.DAYS);\n// after\nnew Timestamps(ChronoUnit.MICROS, ChronoUnit.DAYS);","handlingStrategy":"validation","validationCode":"if (unit != ChronoUnit.MICROS && unit != ChronoUnit.NANOS) {\n  throw new IllegalArgumentException(\"Timestamp unit must be MICROS or NANOS, got: \" + unit);\n}","typeGuard":null,"tryCatchPattern":"try { Object v = tsTransform.bind(type).apply(value); } catch (UnsupportedOperationException e) { /* invalid precision: rebuild transform via Transforms.day(...) */ }","preventionTips":["Only use MICROS or NANOS as timestamp precision — these are the only Iceberg precisions","Validate precision fields when deserializing transform specs","Prefer Transforms.* factories over direct Timestamps construction"],"tags":["java","iceberg","transform","unsupported-time-unit"],"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"}