{"record":{"id":"8497923308080327","repo":"apache/iceberg","slug":"cannot-use-column-s-of-type-s-in-zordering-the-849792","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.1/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.1/spark/src/main/java/org/apache/iceberg/spark/actions/SparkZOrderUDF.java#L325-L354","documentation":"SparkZOrderUDF sorts columns by converting values to order-preserving byte arrays. The typeToOrderedBytesUDF helper only supports Iceberg's Z-order compatible types (numeric, temporal, string, etc.); any other Spark DataType is rejected with IllegalArgumentException because lexicographic byte ordering would not preserve value ordering for that type.","triggerScenarios":"Calling the zorder sort_order rewrite (RewriteDataFilesSparkAction with sort strategy 'zorder') including a column whose Spark type is not in the supported set, e.g. a MAP, ARRAY, STRUCT, or BINARY column.","commonSituations":"Configuring zorder on nested/complex columns; typos that resolve to a complex type; tables with variant or binary columns included in zorder_cols property.","solutions":["Remove the unsupported column from the zorder column list and keep only primitive columns","Cast or extract a primitive value (e.g. an element or hash of the complex value) into a supported column before zordering","Check the table property sort-order / rewrite options for the exact column list","Refer to SparkZOrderUDF.typeToOrderedBytesUDF for the supported type list"],"exampleFix":"// before\nSparkActions.get().rewriteDataFiles(table).sort(SortOrderBuilder.builderFor(table).zOrder(\"location MAP<STRING,STRING>\").build())\n// after\nSparkActions.get().rewriteDataFiles(table).sort(SortOrderBuilder.builderFor(table).zOrder(\"country\").build())","handlingStrategy":"validation","validationCode":"for (String col : zorderCols) {\n  DataType t = spark.table(table.name()).schema().apply(col).dataType();\n  if (!(t instanceof NumericType) && !(t instanceof StringType) && !(t instanceof DateType)\n      && !(t instanceof TimestampType) && !(t instanceof TimestampNTZType)) {\n    throw new IllegalArgumentException(\"Unsupported zorder column type: \" + col + \" -> \" + t);\n  }\n}","typeGuard":"boolean isZOrderCompatible(DataType t) {\n  return t instanceof NumericType || t instanceof StringType || t instanceof DateType\n      || t instanceof TimestampType || t instanceof TimestampNTZType;\n}","tryCatchPattern":"try {\n  rewrite.sort(SortOrderBuilder.builderFor(table).zOrder(cols).build()).execute();\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"ZOrdering\")) { /* drop or remap the offending column */ }\n  else throw e;\n}","preventionTips":["Only zorder primitive columns with natural ordering","Validate column types against the supported set before configuring zorder","Extract/hash complex values into a supported column first"],"tags":["spark","zorder","unsupported-type","compaction"],"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"}