{"record":{"id":"ab32a3a7a4f21d19","repo":"apache/iceberg","slug":"cannot-find-width-for-transform-transform-descri","errorCode":null,"errorMessage":"Cannot find width for transform: <transform.describe()>","messagePattern":"Cannot find width for transform: <transform\\.describe\\(\\)>","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java","lineNumber":504,"sourceCode":"          Preconditions.checkArgument(\n              lit.value() > 0, \"Unsupported width for transform: %s\", transform.describe());\n          return lit.value();\n\n        } else if (((Literal) expr).dataType() instanceof LongType) {\n          Literal<Long> lit = (Literal<Long>) expr;\n          Preconditions.checkArgument(\n              lit.value() > 0 && lit.value() < Integer.MAX_VALUE,\n              \"Unsupported width for transform: %s\",\n              transform.describe());\n          if (lit.value() > Integer.MAX_VALUE) {\n            throw new IllegalArgumentException();\n          }\n          return lit.value().intValue();\n        }\n      }\n    }\n\n    throw new IllegalArgumentException(\"Cannot find width for transform: \" + transform.describe());\n  }\n\n  private static String leafName(String[] fieldNames) {\n    Preconditions.checkArgument(\n        fieldNames.length > 0, \"Invalid field name: at least one name is required\");\n    return fieldNames[fieldNames.length - 1];\n  }\n\n  private static String peerName(String[] fieldNames, String fieldName) {\n    if (fieldNames.length > 1) {\n      String[] peerNames = Arrays.copyOf(fieldNames, fieldNames.length);\n      peerNames[fieldNames.length - 1] = fieldName;\n      return DOT.join(peerNames);\n    }\n    return fieldName;\n  }\n\n  private static String parentName(String[] fieldNames) {","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java#L486-L522","documentation":"findWidth extracts the width parameter (N for truncate) from a Spark truncate transform's literal argument. If the transform's parameters do not contain an integer Literal of the expected shape, it throws IllegalArgumentException because no width can be determined for the truncate spec.","triggerScenarios":"A truncate transform whose parameter is missing, non-literal, or not an integer literal (e.g. truncate(noW, col) or a non-constant expression) reaching findWidth via toPartitionSpec or sort conversion.","commonSituations":"Non-constant width expressions in DDL (variables/functions); typos or wrong argument order in truncate(); SQL generators emitting symbolic widths.","solutions":["Provide a constant integer width: truncate(W, col) with W a literal integer","Replace non-literal width expressions with their computed constant value in the DDL","Validate the transform's parameters before conversion"],"exampleFix":"// before\nPARTITIONED BY (truncate(width_col, data));\n// after\nPARTITIONED BY (truncate(10, data));","handlingStrategy":"validation","validationCode":"// ensure the truncate transform's width is a literal integer before conversion\nObject[] params = transform.parameters();\nif (params.length == 0 || !(params[0] instanceof Literal)\n    || !(((Literal<?>) params[0]).value() instanceof Integer)) {\n  throw new IllegalArgumentException(\"truncate requires a constant integer width\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Spark3Util.toPartitionSpec(schema, transforms);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Cannot find width\")) {\n    // prompt user to supply a constant width\n  }\n}","preventionTips":["Always write truncate with a literal integer width","Ban non-constant expressions in partition transform parameters","Validate DDL transforms before submitting"],"tags":["spark","truncate","transform"],"backgroundTag":"invalid-argument-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"}