{"record":{"id":"a13ddc71273ebbe9","repo":"apache/iceberg","slug":"unsupported-strategy-strategy-only-binpack-or","errorCode":null,"errorMessage":"unsupported strategy: ${strategy}. 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/v3.5/spark/src/main/java/org/apache/iceberg/spark/procedures/RewriteDataFilesProcedure.java","lineNumber":201,"sourceCode":"                .flatMap(zOrder -> zOrder.refs().stream().map(NamedReference::name))\n                .toArray(String[]::new);\n        return action.zOrder(columnNames);\n      } else if (!sortOrderFields.isEmpty()) {\n        return action.sort(buildSortOrder(sortOrderFields, schema));\n      } else {\n        return action.sort();\n      }\n    }\n    if (strategy.equalsIgnoreCase(\"binpack\")) {\n      RewriteDataFiles rewriteDataFiles = 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 rewriteDataFiles.sort(buildSortOrder(sortOrderFields, schema));\n      }\n      return rewriteDataFiles;\n    } else {\n      throw new IllegalArgumentException(\n          \"unsupported strategy: \" + strategy + \". Only binpack or sort is supported\");\n    }\n  }\n\n  private SortOrder buildSortOrder(\n      List<ExtendedParser.RawOrderField> rawOrderFields, Schema schema) {\n    SortOrder.Builder builder = SortOrder.builderFor(schema);\n    rawOrderFields.forEach(\n        rawField -> builder.sortBy(rawField.term(), rawField.direction(), rawField.nullOrder()));\n    return builder.build();\n  }\n\n  private InternalRow[] toOutputRows(RewriteDataFiles.Result result) {\n    int rewrittenDataFilesCount = result.rewrittenDataFilesCount();\n    long rewrittenBytesCount = result.rewrittenBytesCount();\n    int addedDataFilesCount = result.addedDataFilesCount();\n    int failedDataFilesCount = result.failedDataFilesCount();\n    int removedDeleteFilesCount = result.removedDeleteFilesCount();","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/procedures/RewriteDataFilesProcedure.java#L183-L219","documentation":"checkAndApplyStrategy validates the strategy option of RewriteDataFilesProcedure. Only 'binpack' (default) and 'sort' are supported; any other value results in this IllegalArgumentException. Note the throw also fires when both a binpack strategy and a sort order were set, since that combination falls into the else branch.","triggerScenarios":"CALL rewrite_data_files with strategy => 'auto', 'zorder' (as a strategy name), or any misspelled value; or setting strategy => 'binpack' together with a sort_order option.","commonSituations":"Typos in strategy ('sorted', 'sorts'), assuming 'zorder' is a strategy (it is expressed via sort_order), and setting sort_order while leaving strategy at binpack.","solutions":["Set strategy => 'sort' when using sort_order (including zorder(...) terms).","Set strategy => 'binpack' and omit sort_order for pure compaction.","Check spelling/typos of the strategy option value; it must be exactly 'binpack' or 'sort'."],"exampleFix":"// before\nCALL iceberg.system.rewrite_data_files(table => 'db.t', strategy => 'binpack', sort_order => 'id');\n// after\nCALL iceberg.system.rewrite_data_files(table => 'db.t', strategy => 'sort', sort_order => 'id');","handlingStrategy":"validation","validationCode":"String strategy = options.getOrDefault(\"strategy\", \"binpack\");\nif (!strategy.equals(\"binpack\") && !strategy.equals(\"sort\")) {\n  throw new IllegalArgumentException(\"strategy must be 'binpack' or 'sort'\");\n}\nif (strategy.equals(\"binpack\") && options.containsKey(\"sort_order\")) {\n  throw new IllegalArgumentException(\"sort_order requires strategy 'sort'\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass strategy values 'binpack' or 'sort'.","Always set strategy => 'sort' together with sort_order.","Validate procedure options in a wrapper SQL macro or script."],"tags":["spark","rewrite-data-files","invalid-option","strategy"],"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-14T21:17:11.552Z"}