{"record":{"id":"5345d3a2c6cc2dc2","repo":"apache/iceberg","slug":"not-implemented-for-variant-5345d3","errorCode":null,"errorMessage":"Not implemented for variant","messagePattern":"Not implemented for variant","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/ParquetWithSparkSchemaVisitor.java","lineNumber":236,"sourceCode":"\n  public T struct(StructType sStruct, GroupType struct, List<T> fields) {\n    return null;\n  }\n\n  public T list(ArrayType sArray, GroupType array, T element) {\n    return null;\n  }\n\n  public T map(MapType sMap, GroupType map, T key, T value) {\n    return null;\n  }\n\n  public T primitive(DataType sPrimitive, PrimitiveType primitive) {\n    return null;\n  }\n\n  public T variant(VariantType sVariant, GroupType variant) {\n    throw new UnsupportedOperationException(\"Not implemented for variant\");\n  }\n\n  protected String[] currentPath() {\n    return Lists.newArrayList(fieldNames.descendingIterator()).toArray(new String[0]);\n  }\n\n  protected String[] path(String name) {\n    List<String> list = Lists.newArrayList(fieldNames.descendingIterator());\n    list.add(name);\n    return list.toArray(new String[0]);\n  }\n}\n","sourceCodeStart":218,"sourceCodeEnd":249,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/ParquetWithSparkSchemaVisitor.java#L218-L249","documentation":"ParquetWithSparkSchemaVisitor is a schema visitor used when reading Parquet data with a Spark schema. Its default variant(...) method is a stub that throws UnsupportedOperationException — subclass/visitor implementations must override it to handle Iceberg variant columns in Parquet files.","triggerScenarios":"Reading a Parquet file whose schema contains a variant (ShreddedVariant/VariantType) column using a visitor that does not override variant(), e.g. generic Parquet value readers path over a table with variant columns.","commonSituations":"Reading tables containing variant columns (Iceberg spec v3) with code paths that predate variant support; custom readers subclassing ParquetWithSparkSchemaVisitor without implementing variant().","solutions":["Upgrade Iceberg to a version where the reader used supports variant columns","Implement/override the variant() method in your visitor subclass","Avoid reading variant columns through this reader path (exclude them from the projection)","Convert variant columns to string/json for engines or code paths without variant support"],"exampleFix":"// before\nnew ParquetWithSparkSchemaVisitor<T>() { public T primitive(DataType s, PrimitiveType p) {...} }\n// after\nnew ParquetWithSparkSchemaVisitor<T>() {\n  @Override public T variant(VariantType sv, GroupType g) { return variantReader(g); }\n  public T primitive(DataType s, PrimitiveType p) {...}\n}","handlingStrategy":"type-guard","validationCode":"Schema schema = table.schema();\nboolean hasVariant = schema.columns().stream()\n    .anyMatch(c -> c.type().typeId() == Type.TypeID.VARIANT);\nif (hasVariant) { /* use a variant-capable reader or override variant() */ }","typeGuard":"boolean readerSupportsVariant(ParquetWithSparkSchemaVisitor<?> v) {\n  try { v.getClass().getMethod(\"variant\", VariantType.class, GroupType.class); return true; }\n  catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n  ParquetIO.read(reader).call(visitor);\n} catch (UnsupportedOperationException e) {\n  if (\"Not implemented for variant\".equals(e.getMessage())) { /* switch to variant-capable reader */ }\n  else throw e;\n}","preventionTips":["Always override variant() in visitor subclasses when the schema may contain variant columns","Upgrade Iceberg before reading v3-spec tables with variant types","Project out variant columns if your reader path does not support them"],"tags":["spark","parquet","variant","visitor"],"backgroundTag":"method-not-implemented","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"}