{"record":{"id":"e1491c4974663557","repo":"apache/iceberg","slug":"unsupported-strategy-s-only-binpack-or-sort-is","errorCode":null,"errorMessage":"unsupported strategy: %s. Only binpack or sort is supported","messagePattern":"unsupported strategy: (.+?)\\. Only binpack or sort is supported","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/procedures/RewriteDataFilesProcedure.java","lineNumber":182,"sourceCode":"    if (sortOrderString != null) {\n      parseSortOrder(sortOrderString, zOrderTerms, hilbertTerms, sortOrderFields);\n    }\n\n    // caller of this function ensures that between strategy and sortOrder, at least one of them is\n    // not null.\n    if (strategy == null || strategy.equalsIgnoreCase(\"sort\")) {\n      return applySortStrategy(action, zOrderTerms, hilbertTerms, sortOrderFields, schema);\n    }\n    if (strategy.equalsIgnoreCase(\"binpack\")) {\n      RewriteDataFilesSparkAction binPackAction = action.binPack();\n      if (sortOrderString != null) {\n        // calling below method to throw the error as user has set both binpack strategy and sort\n        // order\n        return binPackAction.sort(buildSortOrder(sortOrderFields, schema));\n      }\n      return binPackAction;\n    } else {\n      throw new IllegalArgumentException(\n          \"unsupported strategy: \" + strategy + \". Only binpack or sort is supported\");\n    }\n  }\n\n  private void parseSortOrder(\n      String sortOrderString,\n      List<Zorder> zOrderTerms,\n      List<Hilbert> hilbertTerms,\n      List<ExtendedParser.RawOrderField> sortOrderFields) {\n    ExtendedParser.parseSortOrder(spark(), sortOrderString)\n        .forEach(\n            field -> {\n              if (field.term() instanceof Zorder) {\n                zOrderTerms.add((Zorder) field.term());\n              } else if (field.term() instanceof Hilbert) {\n                hilbertTerms.add((Hilbert) field.term());\n              } else {\n                sortOrderFields.add(field);","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/procedures/RewriteDataFilesProcedure.java#L164-L200","documentation":"RewriteDataFilesProcedure validates the user-supplied 'strategy' option before building the rewrite action. Only 'binpack' and 'sort' are recognized strategy names; anything else (e.g. a typo like 'bin-pack', 'zorder', or uppercase 'BinPack') throws this IllegalArgumentException. The strategy controls how Iceberg rewrites compacted data files.","triggerScenarios":"Calling the rewrite_data_files Spark procedure with WHERE strategy = 'zorder' (as a strategy name rather than a sort expression), 'compaction', a misspelled value like 'binsort', or any value other than exactly 'binpack' or 'sort'. The strategy string is parsed in checkAndApplyStrategy before actions are built.","commonSituations":"Copy-pasting configs from older blog posts that reference strategy names that never existed; confusing the zorder/hilbert sort expression syntax with a strategy value; case mistakes ('Binpack') since the comparison is case-sensitive; migrating from other engines' compaction terminology (e.g. Delta's 'compact' optimization mode).","solutions":["Set strategy to exactly 'binpack' (default) or 'sort' in the procedure options map.","If you intended Z-order compaction, keep strategy='sort' and pass sort_order='zorder(col1,col2)' instead of strategy='zorder'.","Check the option value for typos and casing; the check is exact string comparison.","Consult the RewriteDataFilesSparkAction Strategy enum for valid names in your Iceberg version."],"exampleFix":"// before\nactions.rewriteDataFiles(t).option(\"strategy\", \"zorder\").execute();\n// after\nactions.rewriteDataFiles(t)\n    .option(\"strategy\", \"sort\")\n    .option(\"sort_order\", \"zorder(c1, c2)\")\n    .execute();","handlingStrategy":"validation","validationCode":"Set<String> VALID = Set.of(\"binpack\", \"sort\");\nif (!VALID.contains(strategy)) {\n    throw new IllegalArgumentException(\"strategy must be 'binpack' or 'sort', got: \" + strategy);\n}","typeGuard":null,"tryCatchPattern":"try {\n    SparkActions.get().rewriteDataFiles(table).option(\"strategy\", strategy).execute();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"unsupported strategy\")) { /* fix option and retry */ }\n}","preventionTips":["Keep strategy values in a constants set shared with procedure invocation code","Remember comparison is case-sensitive; lowercase 'binpack'/'sort'","Express zorder/hilbert via sort_order, never as a strategy"],"tags":["spark","config-validation","rewrite-data-files"],"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-23T08:17:48.524Z"}