{"record":{"id":"8ec3a571a6ced59a","repo":"apache/beam","slug":"could-not-find-a-partition-term-for","errorCode":null,"errorMessage":"Could not find a partition term for '{}'.","messagePattern":"Could not find a partition term for '(.+?)'\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/PartitionUtils.java","lineNumber":146,"sourceCode":"                  checkStateNotNull(matcher.group(1)),\n                  Integer.parseInt(checkStateNotNull(matcher.group(2)))),\n          BUCKET,\n          matcher ->\n              Expressions.bucket(\n                  checkStateNotNull(matcher.group(1)),\n                  Integer.parseInt(checkStateNotNull(matcher.group(2)))),\n          IDENTITY,\n          matcher -> Expressions.ref(checkStateNotNull(matcher.group(1))));\n\n  static Term toIcebergTerm(String field) {\n    for (Map.Entry<Pattern, Function<Matcher, Term>> entry : TERMS.entrySet()) {\n      Matcher matcher = entry.getKey().matcher(field);\n      if (matcher.find()) {\n        return entry.getValue().apply(matcher);\n      }\n    }\n\n    throw new IllegalArgumentException(\"Could not find a partition term for '\" + field + \"'.\");\n  }\n\n  /**\n   * Copied over from Apache Iceberg's <a\n   * href=\"https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/util/PartitionUtil.java\">PartitionUtil</a>.\n   *\n   * <p>Needed to accommodate CDC reads, where scans produce {@link ChangelogScanTask}s instead of\n   * {@link ContentScanTask}s.\n   */\n  public static Map<Integer, ?> constantsMap(\n      PartitionSpec spec, ContentFile<?> file, @Nullable Long dataSequenceNumber) {\n    Preconditions.checkState(\n        spec.specId() == file.specId(),\n        \"File spec ID (%s) does not match PartitionSpec ID (%s)\",\n        file.specId(),\n        spec.specId());\n    StructLike partitionData = file.partition();\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/PartitionUtils.java#L128-L164","documentation":"PartitionUtils.toIcebergTerm parses a partition-field expression string into an Iceberg partition term using a list of regex matchers. When no matcher matches the given string, IllegalArgumentException is thrown, meaning the expression syntax is unrecognized.","triggerScenarios":"Passing a partition term string to toIcebergTerm (used by dynamic-destination / partition write paths) that no registered regex matches — wrong transform keyword, missing or mispositioned parameters, unsupported syntax such as 'days(ts)' instead of 'day(ts)', or extra whitespace.","commonSituations":"Translating Iceberg/Spark SQL transform names (days, hours, years, bucket(size)) verbatim into Beam's matcher syntax; typos or case sensitivity issues; writing custom dynamic destination names that embed transform expressions incorrectly.","solutions":["Match the exact syntax PartitionUtils registers: year/month/day/hour(col), bucket[N](col), truncate[L](col), or bare column name for identity","Replace Spark-style names: days->day, hours->hour, years->year before passing","Trim whitespace and verify there are no typos in the transform keyword or column name","Inspect the term with a quick unit test calling PartitionUtils.toIcebergTerm to confirm it parses before deploying"],"exampleFix":"// before\nPartitionUtils.toIcebergTerm(\"days(event_ts)\");\n// after\nPartitionUtils.toIcebergTerm(\"day(event_ts)\");","handlingStrategy":"validation","validationCode":"if (!partitionTerm.matches(\"(year|month|day|hour)\\\\(\\\\w+\\\\)|(bucket|truncate)\\\\[\\\\d+\\\\]\\\\(\\\\w+\\\\)|^\\\\w+$\")) {\n  throw new IllegalArgumentException(\"Invalid partition term: \" + partitionTerm);\n}","typeGuard":"null","tryCatchPattern":"try {\n  PartitionSpec.PartitionFieldSpec term = PartitionUtils.toIcebergTerm(field);\n} catch (IllegalArgumentException e) {\n  LOG.error(\"Partition term unparsable: {}\", e.getMessage());\n  // normalize Spark-style names (days->day) and retry\n}","preventionTips":["Avoid Spark/Iceberg SQL alias names (days, hours); use Beam's expected keywords","Trim and lowercase transform keywords","Unit-test term parsing for every dynamic destination spec"],"tags":["java","iceberg","beam","partitioning","configuration"],"backgroundTag":"invalid-argument-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}