{"record":{"id":"4221589f4f4a1947","repo":"apache/iceberg","slug":"not-implemented-set-422158","errorCode":null,"errorMessage":"Not implemented: set","messagePattern":"Not implemented: set","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/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.1/spark/src/main/java/org/apache/iceberg/spark/SparkStructLike.java#L34-L55","documentation":"SparkStructLike wraps a Spark InternalRow to expose it as Iceberg's StructLike. Iceberg's StructLike contract includes a set() mutation method, but this wrapper is read-only, so calling set() throws UnsupportedOperationException. It exists only to read struct values out of Spark rows during scans.","triggerScenarios":"Calling set(int pos, T value) on a SparkStructLike instance — e.g. passing it to code that assumes a mutable StructLike (such as writers or updaters) instead of read-only scan contexts.","commonSituations":"Piping an Iceberg-wrapped Spark row into a custom writer, updater, or copy routine that mutates StructLike fields; using SparkStructLike outside the read path it was designed for.","solutions":["Do not mutate SparkStructLike; treat it as read-only and build a mutable StructLike (e.g. via a Record or a fixed StructLike implementation) when writes are needed","Copy the values out of the Spark row into your own mutable record before mutation","Check whether the API you are calling truly needs a mutable StructLike; read paths (comparators, readers) never call set()"],"exampleFix":"// before\nstructLike.set(0, newValue); // throws UnsupportedOperationException\n// after\nRecord copy = GenericRecord.create(schema).copyFieldValues(...);\ncopy.setField(\"col\", newValue);","handlingStrategy":"validation","validationCode":"if (structLike instanceof SparkStructLike) {\n  throw new IllegalArgumentException(\"SparkStructLike is read-only; use a mutable record\");\n}","typeGuard":"boolean isReadOnlyStructLike(StructLike s) { return s instanceof SparkStructLike; }","tryCatchPattern":"try { s.set(pos, value); } catch (UnsupportedOperationException e) { /* build a mutable copy instead */ }","preventionTips":["Treat SparkStructLike as read-only; never pass it to write/update APIs","Materialize values into GenericRecord or another mutable StructLike when mutation is required","Check the receiving API's docs for whether it mutates its StructLike argument"],"tags":["spark","structlike","read-only","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}