apache/iceberg · error · IllegalArgumentException
unsupported strategy: + strategy + . Only binpack or sort is
Error message
unsupported strategy: + strategy + . Only binpack or sort is supported
What it means
RewriteDataFilesProcedure accepts only the rewrite strategies 'binpack' or 'sort' for the strategy option. Any other string reaches checkAndApplyStrategy's final else and throws IllegalArgumentException listing the accepted values. This is input validation of the strategy enum-like argument.
Source
Thrown at spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/procedures/RewriteDataFilesProcedure.java:204
.flatMap(zOrder -> zOrder.refs().stream().map(NamedReference::name))
.toArray(String[]::new);
return action.zOrder(columnNames);
} else if (!sortOrderFields.isEmpty()) {
return action.sort(buildSortOrder(sortOrderFields, schema));
} else {
return action.sort();
}
}
if (strategy.equalsIgnoreCase("binpack")) {
RewriteDataFilesSparkAction binPackAction = action.binPack();
if (sortOrderString != null) {
// calling below method to throw the error as user has set both binpack strategy and sort
// order
return binPackAction.sort(buildSortOrder(sortOrderFields, schema));
}
return binPackAction;
} else {
throw new IllegalArgumentException(
"unsupported strategy: " + strategy + ". Only binpack or sort is supported");
}
}
private SortOrder buildSortOrder(
List<ExtendedParser.RawOrderField> rawOrderFields, Schema schema) {
SortOrder.Builder builder = SortOrder.builderFor(schema);
rawOrderFields.forEach(
rawField -> builder.sortBy(rawField.term(), rawField.direction(), rawField.nullOrder()));
return builder.build();
}
private InternalRow[] toOutputRows(RewriteDataFiles.Result result) {
int rewrittenDataFilesCount = result.rewrittenDataFilesCount();
long rewrittenBytesCount = result.rewrittenBytesCount();
int addedDataFilesCount = result.addedDataFilesCount();
int failedDataFilesCount = result.failedDataFilesCount();
int removedDeleteFilesCount = result.removedDeleteFilesCount();View on GitHub (pinned to 86d9c8fc54)
Solutions
- Use strategy => 'binpack' or strategy => 'sort' exactly (lowercase).
- Remove the strategy option entirely to use the default.
- For Z-order layout, use strategy => 'sort' with the z_order sort option instead of strategy => 'zorder'.
- Trim/normalize the value before invoking the procedure programmatically.
Example fix
-- before CALL iceberg.system.rewrite_data_files(table => 'db.t', strategy => 'zorder'); -- after CALL iceberg.system.rewrite_data_files(table => 'db.t', strategy => 'sort', z_order => 'col1,col2');
Defensive patterns
Strategy: validation
Validate before calling
if (!"binpack".equals(strategy) && !"sort".equals(strategy)) throw new IllegalArgumentException("strategy must be 'binpack' or 'sort', got: " + strategy); Try / catch
try { rewriteDataFiles(..., strategy); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("unsupported strategy")) { /* use binpack or sort */ } else throw e; } Prevention
- Use lowercase 'binpack' or 'sort' literally.
- For Z-order, use strategy 'sort' plus the z_order option.
- Trim user-supplied strategy strings before passing them.
When it happens
Trigger: CALL iceberg.system.rewrite_data_files(table => 'db.t', strategy => 'zorder') or strategy => 'compact' or 'SORT' (case-sensitive) — any value outside binpack/sort.
Common situations: Assuming 'zorder' is a valid strategy value (Zorder is configured via sort options, not strategy); misspellings like 'binpack ' with trailing space or 'bin-pack'; copying options from other engines (e.g. 'auto').
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Cannot pass path based identifier to %s method. %s is a path
- Invalid session catalog: sparkSessionCatalog
- Unable to parse sortOrder: %s
- Cannot pass path based identifier to %s method. %s is a path
- Cannot mix identity sort columns and a Zorder sort expressio
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/1d546b89695ac313.
Report an issue: GitHub.