{"record":{"id":"24e7b052722d25d9","repo":"apache/iceberg","slug":"cannot-find-width-for-transform-transform-descr","errorCode":null,"errorMessage":"Cannot find width for transform: ${transform.describe()}","messagePattern":"Cannot find width for transform: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java","lineNumber":521,"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":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java#L503-L539","documentation":"Thrown by Spark3Util.findWidth when a truncate transform's literal width argument cannot be located. The transform's parameters did not contain a numeric literal (Literal<Integer>) from which the truncate width can be extracted.","triggerScenarios":"truncate(W) where W is not an integer literal — e.g. a column reference, a computed expression, a string, or a non-integer literal passed as the width.","commonSituations":"PARTITIONED BY (truncate(col_w, 10)) with arguments in the wrong order; using expressions like truncate(t.col, width) where width comes from a variable resolved to a non-literal; typos making the literal not match expected type.","solutions":["Pass an integer literal as the truncate width: truncate(col, 10)","Check the argument order — width is the literal parameter of the transform","Inspect transform.describe() in the message to see what was actually parsed"],"exampleFix":"// before\nPARTITIONED BY (truncate(id, \"10\"))\n// after\nPARTITIONED BY (truncate(id, 10))","handlingStrategy":"validation","validationCode":"// ensure the width argument is an integer literal before calling\nif (!(widthArg instanceof Literal) || !(((Literal<?>) widthArg).value() instanceof Integer)) {\n  throw new IllegalArgumentException(\"truncate width must be an integer literal\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  spec = Spark3Util.toPartitionSpec(schema, partitions);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Cannot find width for transform\")) {\n    // fix the truncate argument to an int literal and retry\n  }\n}","preventionTips":["Always pass truncate width as a plain integer literal","Check argument order: truncate(col, width)","Render transforms via describe() when debugging argument parsing"],"tags":["spark","truncate","transform-arguments"],"backgroundTag":"missing-required-argument","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}