{"record":{"id":"426f5d665ccb1753","repo":"apache/iceberg","slug":"unexpected-command-command","errorCode":null,"errorMessage":"Unexpected command: command","messagePattern":"Unexpected command: command","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkWriteConf.java","lineNumber":373,"sourceCode":"    return SparkWriteUtil.copyOnWriteRequirements(\n        table,\n        command,\n        copyOnWriteDistributionMode(command),\n        fanoutWriterEnabled(),\n        dataAdvisoryPartitionSize());\n  }\n\n  @VisibleForTesting\n  DistributionMode copyOnWriteDistributionMode(Command command) {\n    switch (command) {\n      case DELETE:\n        return deleteDistributionMode();\n      case UPDATE:\n        return updateDistributionMode();\n      case MERGE:\n        return copyOnWriteMergeDistributionMode();\n      default:\n        throw new IllegalArgumentException(\"Unexpected command: \" + command);\n    }\n  }\n\n  public SparkWriteRequirements positionDeltaRequirements(Command command) {\n    if (ignoreTableDistributionAndOrdering()) {\n      LOG.info(\"Skipping distribution/ordering: disabled per job configuration\");\n      return SparkWriteRequirements.EMPTY;\n    }\n\n    return SparkWriteUtil.positionDeltaRequirements(\n        table,\n        command,\n        positionDeltaDistributionMode(command),\n        fanoutWriterEnabled(),\n        command == DELETE ? deleteAdvisoryPartitionSize() : dataAdvisoryPartitionSize());\n  }\n\n  @VisibleForTesting","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkWriteConf.java#L355-L391","documentation":"SparkWriteConf.copyOnWriteDistributionMode() maps a row-level Command (DELETE, UPDATE, MERGE) to its copy-on-write distribution mode. Any Command outside that enum set is unexpected and throws IllegalArgumentException — an internal invariant/default-case guard.","triggerScenarios":"Calling copyOnWriteDistributionMode() (directly or via copyOnWriteRequirements/checkMode) with a Command value that is not DELETE, UPDATE, or MERGE — e.g. a Command overwrite/insert variant or null.","commonSituations":"Custom Spark extensions or tests constructing SparkWriteConf and passing their own command; new Command enum values added upstream not yet handled by this distribution-mode method.","solutions":["Only pass DELETE, UPDATE, or MERGE to this method; route other commands to their dedicated configuration methods (e.g. appendDistributionMode for writes)","If a new Command value exists, upgrade the Iceberg Spark module so it is handled","In custom code, switch on command yourself and only delegate supported values"],"exampleFix":"// before\nDistributionMode mode = writeConf.copyOnWriteDistributionMode(command);\n// after\nif (command == Command.DELETE || command == Command.UPDATE || command == Command.MERGE) {\n  DistributionMode mode = writeConf.copyOnWriteDistributionMode(command);\n}","handlingStrategy":"validation","validationCode":"if (command == null || (command != Command.DELETE && command != Command.UPDATE && command != Command.MERGE)) {\n  throw new IllegalArgumentException(\"copyOnWriteDistributionMode requires DELETE/UPDATE/MERGE\");\n}","typeGuard":"boolean isRowLevelCommand = command == Command.DELETE || command == Command.UPDATE || command == Command.MERGE;","tryCatchPattern":"try {\n  mode = writeConf.copyOnWriteDistributionMode(command);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Unsupported command for CoW planning: \" + command, e);\n}","preventionTips":["Only pass row-level Command values to this method","When adding new Command enum values, update all SparkWriteConf mode methods","Switch on command explicitly and delegate each command to its own config method"],"tags":["spark","write-config","illegal-argument"],"backgroundTag":"invalid-enum-value","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"}