{"record":{"id":"d38dddbdef0ea288","repo":"apache/iceberg","slug":"cannot-use-column-s-of-type-s-in-zordering-the-d38ddd","errorCode":null,"errorMessage":"Cannot use column %s of type %s in ZOrdering, the type is unsupported","messagePattern":"Cannot use column (.+?) of type (.+?) in ZOrdering, the type is unsupported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/SparkZOrderUDF.java","lineNumber":343,"sourceCode":"      return longToOrderedBytesUDF().apply(column);\n    } else if (type instanceof FloatType) {\n      return floatToOrderedBytesUDF().apply(column);\n    } else if (type instanceof DoubleType) {\n      return doubleToOrderedBytesUDF().apply(column);\n    } else if (type instanceof StringType) {\n      return stringToOrderedBytesUDF().apply(column);\n    } else if (type instanceof BinaryType) {\n      return bytesTruncateUDF().apply(column);\n    } else if (type instanceof BooleanType) {\n      return booleanToOrderedBytesUDF().apply(column);\n    } else if (type instanceof TimestampType) {\n      return longToOrderedBytesUDF().apply(column.cast(DataTypes.LongType));\n    } else if (type instanceof TimestampNTZType) {\n      return timestampNtzToOrderedBytesUDF().apply(column);\n    } else if (type instanceof DateType) {\n      return longToOrderedBytesUDF().apply(functions.unix_date(column).cast(DataTypes.LongType));\n    } else {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Cannot use column %s of type %s in ZOrdering, the type is unsupported\",\n              column, type));\n    }\n  }\n\n  private void increaseOutputSize(int bytes) {\n    totalOutputBytes = Math.min(totalOutputBytes + bytes, maxOutputSize);\n  }\n}\n","sourceCodeStart":325,"sourceCodeEnd":354,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/SparkZOrderUDF.java#L325-L354","documentation":"SparkZOrderUDF.sortedLexicographically converts a Spark column to lexicographically ordered bytes for Z-order sorting; it supports numeric, string, boolean, date, timestamp (incl. NTZ) and similar types. Any other type (maps, arrays, structs, binary, nested types) throws IllegalArgumentException.","triggerScenarios":"Calling SparkActions.zOrder(table, \"col\") / sort-zorder rewrite with a column whose Spark type is not in the supported set — e.g. struct, array, map, variant, or complex columns.","commonSituations":"Passing nested or complex columns (from schema evolution or misconfigured column names) to zOrder; assuming all primitive-adjacent types are supported.","solutions":["Restrict Z-ordering to supported columns (numeric, string, boolean, date, timestamp/NTZ).","Add a transform/expression producing a supported type, e.g. zOrder by a struct field or cast to string where meaningful.","Use regular sortOrder (rewriteSortOrder) for types ZOrdering doesn't support."],"exampleFix":"// before\nactions.rewriteDataFiles(table).zOrder(\"location.address\").execute(); // struct unsupported\n// after\nactions.rewriteDataFiles(table).zOrder(\"location\").execute(); // or a primitive column","handlingStrategy":"validation","validationCode":"Set<String> supported = Set.of(\"integer\",\"long\",\"short\",\"byte\",\"float\",\"double\",\"string\",\"boolean\",\"date\",\"timestamp\",\"timestamp_ntz\",\"decimal\"); List<Types.NestedField> cols = table.schema().columns(); // check each zOrder column's type is supported","typeGuard":"boolean zOrderable(DataType t) { return t instanceof NumericType || t instanceof StringType || t instanceof BooleanType || t instanceof DateType || t instanceof TimestampType || t instanceof TimestampNTZType; }","tryCatchPattern":"try { rewrite.zOrder(col).execute(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"ZOrdering, the type is unsupported\")) { /* fall back to sortCol or pick supported columns */ } else throw e; }","preventionTips":["Only pass primitive, supported columns to zOrder","Inspect table.schema() before choosing Z-order columns","Use sortOrder instead for complex/nested columns"],"tags":["spark","zorder","unsupported-type","sort"],"backgroundTag":"unsupported-dtype","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"}