{"record":{"id":"6f86f36d01b11062","repo":"apache/iceberg","slug":"cannot-convert-type-to-sql-s","errorCode":null,"errorMessage":"Cannot convert type to SQL: %s","messagePattern":"Cannot convert type to SQL: (.+?)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java","lineNumber":610,"sourceCode":"        case DOUBLE:\n          return \"double\";\n        case DATE:\n          return \"date\";\n        case TIME:\n          return \"time\";\n        case TIMESTAMP:\n          return \"timestamp\";\n        case STRING:\n        case UUID:\n          return \"string\";\n        case FIXED:\n        case BINARY:\n          return \"binary\";\n        case DECIMAL:\n          Types.DecimalType decimal = (Types.DecimalType) primitive;\n          return \"decimal(\" + decimal.precision() + \",\" + decimal.scale() + \")\";\n      }\n      throw new UnsupportedOperationException(\"Cannot convert type to SQL: \" + primitive);\n    }\n  }\n\n  private static class DescribeExpressionVisitor\n      extends ExpressionVisitors.ExpressionVisitor<String> {\n    private static final DescribeExpressionVisitor INSTANCE = new DescribeExpressionVisitor();\n\n    private DescribeExpressionVisitor() {}\n\n    @Override\n    public String alwaysTrue() {\n      return \"true\";\n    }\n\n    @Override\n    public String alwaysFalse() {\n      return \"false\";\n    }","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java#L592-L628","documentation":"Spark3Util's DescribeExpressionVisitor converts Iceberg types to Spark SQL type strings; this UnsupportedOperationException is thrown for any PrimitiveType not handled by the visitor's switch (all standard types are handled, so this fires only for exotic or future primitive types).","triggerScenarios":"Calling Spark3Util.describeType (via DESCRIBE TABLE / schema-to-SQL conversion) with a PrimitiveType case missing from the visitor's switch, e.g. a new primitive added to the Iceberg spec but not yet mapped here.","commonSituations":"Using a table whose schema contains a primitive type the installed Iceberg Spark module version doesn't know how to render; forward/backward version mismatch between writer and reader libraries.","solutions":["Upgrade the Iceberg Spark runtime to a version whose DescribeExpressionVisitor covers the primitive type in the schema","Identify the offending type via the message text and rewrite the column type (e.g. via migration) to a supported primitive","Copy the DescribeTypeVisitor logic and add a case for the missing type in a local fork"],"exampleFix":"// before\nthrow new UnsupportedOperationException(\"Cannot convert type to SQL: \" + primitive);\n// after\ncase TIMESTAMP_NANO:\n  return \"timestamp_ntz\";\ndefault:\n  throw new UnsupportedOperationException(\"Cannot convert type to SQL: \" + primitive);","handlingStrategy":"validation","validationCode":"if (type instanceof Types.PrimitiveType p && !SUPPORTED_SQL_PRIMITIVES.contains(p.typeId())) {\n  throw new IllegalArgumentException(\"Type not renderable as SQL: \" + p);\n}","typeGuard":"boolean isSupportedPrimitive(Type t) { return t.isPrimitiveType() && KNOWN_TYPE_IDS.contains(t.typeId()); }","tryCatchPattern":"try { return Spark3Util.describeType(type); } catch (UnsupportedOperationException e) { log.warn(\"SQL rendering unsupported: {}\", e.getMessage()); return type.toString(); }","preventionTips":["Keep the Iceberg Spark runtime version aligned with the library that wrote the schema","Check the type against TypeID before rendering to SQL","Avoid custom/future primitive types in schemas rendered via describeType"],"tags":["spark","sql","unsupported-type"],"backgroundTag":"unsupported-operation","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"}