{"record":{"id":"ebbe1d98f633d159","repo":"apache/iceberg","slug":"unsupported-value-for-variant-in-structinternalrow-ebbe1d","errorCode":null,"errorMessage":"Unsupported value for VARIANT in StructInternalRow: \" + value.getClass()","messagePattern":"Unsupported value for VARIANT in StructInternalRow: \" \\+ value\\.getClass\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java","lineNumber":386,"sourceCode":"        throw new UnsupportedOperationException(\"Unsupported array element type: \" + elementType);\n    }\n  }\n\n  private static VariantVal toVariantVal(Object value) {\n    if (value instanceof Variant) {\n      Variant variant = (Variant) value;\n      byte[] metadataBytes = new byte[variant.metadata().sizeInBytes()];\n      ByteBuffer metadataBuffer = ByteBuffer.wrap(metadataBytes).order(ByteOrder.LITTLE_ENDIAN);\n      variant.metadata().writeTo(metadataBuffer, 0);\n\n      byte[] valueBytes = new byte[variant.value().sizeInBytes()];\n      ByteBuffer valueBuffer = ByteBuffer.wrap(valueBytes).order(ByteOrder.LITTLE_ENDIAN);\n      variant.value().writeTo(valueBuffer, 0);\n\n      return new VariantVal(valueBytes, metadataBytes);\n    }\n\n    throw new UnsupportedOperationException(\n        \"Unsupported value for VARIANT in StructInternalRow: \" + value.getClass());\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  private <T> GenericArrayData fillArray(\n      Collection<?> values, Function<Object[], BiConsumer<Integer, T>> makeSetter) {\n    Object[] array = new Object[values.size()];\n    BiConsumer<Integer, T> setter = makeSetter.apply(array);\n\n    int index = 0;\n    for (Object value : values) {\n      if (value == null) {\n        array[index] = null;\n      } else {\n        setter.accept(index, (T) value);\n      }\n\n      index += 1;","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java#L368-L404","documentation":"toVariantVal converts Iceberg Variant values into Spark VariantVal. It only handles org.apache.iceberg.variants.Variant instances; any other runtime value encountered for a VARIANT-typed field throws UnsupportedOperationException with the value's Java class.","triggerScenarios":"Reading a VARIANT column where the in-memory value is neither an Iceberg Variant nor byte[] (the handled inputs) — typically indicates an internal bug or an unexpected writer format.","commonSituations":"Mixed Iceberg versions (table written by a different Iceberg runtime producing a different in-memory Variant representation), or custom extensions passing non-standard values through the scan pipeline.","solutions":["Ensure all Iceberg runtime jars (core and spark) are the same version","Verify the value's class in the message and check which writer produced the data","Upgrade Iceberg to a version where variant support matches your Spark version","If reproducible, report as a bug with the value class from the message"],"exampleFix":"// before\nmvn dependency:tree | grep iceberg  # mixed versions\n// after\n# pin all org.apache.iceberg modules to one version, e.g.\nimplementation(\"org.apache.iceberg:iceberg-spark-runtime-4.1_2.13:1.10.0\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static boolean isIcebergVariant(Object v) { return v instanceof org.apache.iceberg.variants.Variant; }","tryCatchPattern":"try {\n  VariantVal vv = row.getVariant(ordinal);\n} catch (UnsupportedOperationException e) {\n  throw new IllegalStateException(\"Non-Variant value in VARIANT column; check Iceberg version alignment: \" + e.getMessage(), e);\n}","preventionTips":["Use one Iceberg version for all modules and writers","Don't inject custom objects into VARIANT-typed positions","Reproduce/report with the class name included in the message"],"tags":["spark","variant","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}