{"record":{"id":"21cbd9d25f71dcff","repo":"apache/iceberg","slug":"unsupported-type-primitive-21cbd9","errorCode":null,"errorMessage":"Unsupported type: {primitive}","messagePattern":"Unsupported type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/SparkAvroWriter.java","lineNumber":171,"sourceCode":"            return ValueWriters.tinyints();\n          } else if (type instanceof ShortType) {\n            return ValueWriters.shorts();\n          }\n          return ValueWriters.ints();\n        case LONG:\n          return ValueWriters.longs();\n        case FLOAT:\n          return ValueWriters.floats();\n        case DOUBLE:\n          return ValueWriters.doubles();\n        case STRING:\n          return SparkValueWriters.strings();\n        case FIXED:\n          return ValueWriters.fixed(primitive.getFixedSize());\n        case BYTES:\n          return ValueWriters.bytes();\n        default:\n          throw new IllegalArgumentException(\"Unsupported type: \" + primitive);\n      }\n    }\n  }\n}\n","sourceCodeStart":153,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/SparkAvroWriter.java#L153-L176","documentation":"SparkAvroWriter's primitive() maps Avro primitive types to value writers; the default branch is unreachable for valid Avro primitives but guards against unknown/unexpected primitive enum values, throwing IllegalArgumentException. It indicates the Avro schema contains a primitive the writer cannot handle.","triggerScenarios":"Encountering an Avro primitive type outside the handled set (STRING, INT, LONG, FLOAT, DOUBLE, BOOLEAN, FIXED, BYTES, NULL) — typically only possible with a corrupted or non-standard schema, or a future Avro primitive type.","commonSituations":"Schema parsing anomalies from hand-written Avro schemas; forward-compatibility issues with newer Avro libraries introducing new primitives.","solutions":["Validate the Avro schema against the standard primitive set before writing","Upgrade Iceberg for newer Avro primitive support","Remap the field to a supported primitive type (e.g. BYTES/FIXED)","Check that the schema was not hand-edited or generated incorrectly"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"Set<Schema.Type> allowed = Set.of(STRING, INT, LONG, FLOAT, DOUBLE, BOOLEAN, FIXED, BYTES, NULL);\navroSchema.getFields().forEach(f -> {\n  if (f.schema().getType() == Schema.Type.UNION) {\n    f.schema().getTypes().forEach(t -> Preconditions.checkArgument(allowed.contains(t.getType()), t.getType()));\n  } else Preconditions.checkArgument(allowed.contains(f.schema().getType()), f.schema().getType());\n});","typeGuard":"boolean supportedPrimitive(org.apache.avro.Schema s) {\n  return s.getType() != UNION || s.getTypes().stream().allMatch(t -> t.getType() != UNION && isKnown(t));\n}","tryCatchPattern":"try {\n  writer.write(row);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unsupported type\")) { /* sanitize the Avro schema */ }\n  else throw e;\n}","preventionTips":["Validate Avro schemas before writing","Use standard Avro primitives only","Keep the Avro library and Iceberg versions in sync"],"tags":["spark","avro","writer","unsupported-type"],"backgroundTag":"invalid-enum-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"}