{"record":{"id":"57b3bb28291f65cd","repo":"apache/iceberg","slug":"not-implemented-set-57b3bb","errorCode":null,"errorMessage":"Not implemented: set","messagePattern":"Not implemented: set","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkStructLike.java","lineNumber":52,"sourceCode":"  public SparkStructLike wrap(Row row) {\n    this.wrapped = row;\n    return this;\n  }\n\n  @Override\n  public int size() {\n    return type.fields().size();\n  }\n\n  @Override\n  public <T> T get(int pos, Class<T> javaClass) {\n    Types.NestedField field = type.fields().get(pos);\n    return javaClass.cast(SparkValueConverter.convert(field.type(), wrapped.get(pos)));\n  }\n\n  @Override\n  public <T> void set(int pos, T value) {\n    throw new UnsupportedOperationException(\"Not implemented: set\");\n  }\n}\n","sourceCodeStart":34,"sourceCodeEnd":55,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkStructLike.java#L34-L55","documentation":"SparkStructLike adapts a Spark InternalRow to Iceberg's StructLike interface for reading; it is read-only by design. Calling set(pos, value) on it throws this UnsupportedOperationException because mutating Spark's internal rows through this wrapper is not implemented. StructLike mutation requires a mutable struct implementation.","triggerScenarios":"Calling ((StructLike) sparkStructLike).set(i, value); using a code path that expects a writable StructLike (e.g. writers, partition key builders that mutate) with a row obtained from Spark reader context.","commonSituations":"Custom Spark scan/read extensions trying to mutate rows in place; generic Iceberg utilities that accept StructLike for writes being handed a Spark row wrapper; test code assuming StructLike is always mutable.","solutions":["Use a mutable StructLike implementation and copy values into it instead of setting on SparkStructLike","Rewrite the code path to read values via get(pos, javaClass) rather than mutating","Wrap with your own StructLike that holds a materialized Object[] you can set","If writing data, construct Iceberg records directly instead of adapting Spark rows"],"exampleFix":"// before\n((StructLike) sparkStructLike).set(0, \"a\"); // UnsupportedOperationException\n// after\nObject[] copy = new Object[structLike.size()];\nfor (int i = 0; i < copy.length; i++) copy[i] = structLike.get(i, Object.class);\nmutableStructLike.set(0, \"a\"); // mutable implementation","handlingStrategy":"type-guard","validationCode":"// SparkStructLike is read-only; ensure your path never requires writes\nassert !isWritePath; // writers must use mutable StructLike implementations","typeGuard":"if (structLike instanceof org.apache.iceberg.spark.SparkStructLike) {\n  throw new IllegalStateException(\"SparkStructLike is read-only; copy to a mutable StructLike first\");\n}","tryCatchPattern":"try {\n  structLike.set(pos, value);\n} catch (UnsupportedOperationException e) {\n  // materialize into Object[]/mutable record and set there\n}","preventionTips":["Treat SparkStructLike strictly as a read adapter","Copy Spark rows into mutable StructLike implementations for write paths","Check StructLike mutability requirements in generic utilities before reuse","Add unit tests that fail fast if write paths receive read adapters"],"tags":["spark","structlike","read-only","unsupported-operation"],"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"}