{"record":{"id":"1f9a9448ccac1b52","repo":"apache/iceberg","slug":"not-implemented-for-variant-1f9a94","errorCode":null,"errorMessage":"Not implemented for variant","messagePattern":"Not implemented for variant","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkTypeVisitor.java","lineNumber":64,"sourceCode":"          visit(((MapType) type).keyType(), visitor),\n          visit(((MapType) type).valueType(), visitor));\n\n    } else if (type instanceof ArrayType) {\n      return visitor.array((ArrayType) type, visit(((ArrayType) type).elementType(), visitor));\n\n    } else if (type instanceof VariantType) {\n      return visitor.variant((VariantType) type);\n\n    } else if (type instanceof UserDefinedType) {\n      throw new UnsupportedOperationException(\"User-defined types are not supported\");\n\n    } else {\n      return visitor.atomic(type);\n    }\n  }\n\n  public T variant(VariantType variant) {\n    throw new UnsupportedOperationException(\"Not implemented for variant\");\n  }\n\n  public T struct(StructType struct, List<T> fieldResults) {\n    return null;\n  }\n\n  public T field(StructField field, T typeResult) {\n    return null;\n  }\n\n  public T array(ArrayType array, T elementResult) {\n    return null;\n  }\n\n  public T map(MapType map, T keyResult, T valueResult) {\n    return null;\n  }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkTypeVisitor.java#L46-L82","documentation":"The default SparkTypeVisitor.variant implementation throws 'Not implemented for variant': subclasses of SparkTypeVisitor are expected to override variant(VariantType) to handle Spark VariantType, and the base class provides no meaningful default. Calling the base implementation (i.e., using a visitor that did not override it) on a schema containing VariantType columns raises UnsupportedOperationException.","triggerScenarios":"Traversing a Spark schema containing a VariantType column with a SparkTypeVisitor subclass that has not overridden variant(), so the base-class stub executes and throws.","commonSituations":"Writing custom type-traversal utilities for schemas containing the newer Spark/Iceberg Variant type; forgetting to update an existing visitor subclass after Variant support was introduced in the schema.","solutions":["Override variant(VariantType) in your SparkTypeVisitor subclass and return an appropriate result","Filter or reject VariantType columns before traversing if your use case cannot handle them","If the visitor is library-provided and you only read schemas without variants, strip Variant columns from the schema first"],"exampleFix":"// before\nSparkTypeVisitor<String> visitor = new SparkTypeVisitor<String>() {}; // variant() not overridden\n// after\nSparkTypeVisitor<String> visitor = new SparkTypeVisitor<String>() {\n  @Override\n  public String variant(VariantType variant) { return \"variant\"; }\n};","handlingStrategy":"type-guard","validationCode":"static boolean hasVariant(StructType schema) {\n  return java.util.Arrays.stream(schema.fields())\n      .anyMatch(f -> f.dataType() instanceof VariantType);\n}","typeGuard":"if (sparkType instanceof VariantType && visitorHandlesVariant) { visitor.variant((VariantType) sparkType); }","tryCatchPattern":"try {\n  return SparkTypeVisitor.visit(type, visitor);\n} catch (UnsupportedOperationException e) {\n  if (\"Not implemented for variant\".equals(e.getMessage())) { return fallbackForVariant(type); }\n  throw e;\n}","preventionTips":["Always override variant() when subclassing SparkTypeVisitor","Decide up front whether your traversal supports VariantType and reject schemas early otherwise","Add unit tests with schemas containing Variant columns"],"tags":["method-not-implemented","spark","variant"],"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-23T08:17:48.524Z"}