apache/shardingsphere · error · IllegalArgumentException
Invalid compaction type. Must be 'MAJOR', 'MINOR' or 'REBALA
Error message
Invalid compaction type. Must be 'MAJOR', 'MINOR' or 'REBALANCE'
What it means
Thrown by HiveDDLStatementVisitor when an ALTER TABLE ... COMPACT statement specifies a compaction type string that is not MAJOR, MINOR, or REBALANCE (case-insensitive check via isValidCompactionType after stripping quotes). Note this is an IllegalArgumentException, not SQLParsingException, even though it is a parse-time failure — so callers catching only SQLParsingException will not intercept it.
Source
Thrown at parser/sql/engine/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/engine/hive/visitor/statement/type/HiveDDLStatementVisitor.java:149
public ASTNode visitAlterTable(final AlterTableContext ctx) {
AlterTableStatement.AlterTableStatementBuilder result = AlterTableStatement.builder().databaseType(getDatabaseType())
.table((SimpleTableSegment) visit(ctx.alterTableCommonClause().tableName()));
if (null != ctx.changeColumn()) {
ChangeColumnDefinitionSegment changeColumnSegment = (ChangeColumnDefinitionSegment) visit(ctx.changeColumn());
result.changeColumnDefinition(changeColumnSegment);
}
if (null != ctx.addColumns()) {
AddColumnDefinitionSegment addSeg = (AddColumnDefinitionSegment) visit(ctx.addColumns());
result.addColumnDefinition(addSeg);
}
if (null != ctx.replaceColumns()) {
ReplaceColumnDefinitionSegment repSeg = (ReplaceColumnDefinitionSegment) visit(ctx.replaceColumns());
result.replaceColumnDefinition(repSeg);
}
if (null != ctx.COMPACT()) {
String compactionType = ctx.string_().getText().replace("'", "");
if (!isValidCompactionType(compactionType)) {
throw new IllegalArgumentException("Invalid compaction type. Must be 'MAJOR', 'MINOR' or 'REBALANCE'");
}
if ((null != ctx.clusteredIntoClause() || null != ctx.orderByClause())
&& !"REBALANCE".equalsIgnoreCase(compactionType)) {
throw new IllegalArgumentException("[CLUSTERED INTO n BUCKETS] and [ORDER BY col_list] clauses can only be used with REBALANCE compaction");
}
}
if (null != ctx.cherryPickClause()) {
int numberStartIndex = ctx.cherryPickClause().NUMBER_().getSymbol().getStartIndex();
int numberStopIndex = ctx.cherryPickClause().NUMBER_().getSymbol().getStopIndex();
LiteralExpressionSegment snapshotId = new LiteralExpressionSegment(numberStartIndex, numberStopIndex,
new NumberLiteralValue(ctx.cherryPickClause().NUMBER_().getText()).getValue());
result.cherryPickDefinition(new CherryPickDefinitionSegment(ctx.cherryPickClause().EXECUTE().getSymbol().getStartIndex(), numberStopIndex, snapshotId));
}
if (null != ctx.tableRollback()) {
int startIndex = ctx.tableRollback().EXECUTE().getSymbol().getStartIndex();
if (null != ctx.tableRollback().string_()) {
int stringStartIndex = ctx.tableRollback().string_().getStart().getStartIndex();
int stringStopIndex = ctx.tableRollback().string_().getStop().getStopIndex();View on GitHub (pinned to e952770a21)
Solutions
- Use exactly 'MAJOR', 'MINOR', or 'REBALANCE' (either case) as the quoted compaction type
- Check for trailing spaces or smart quotes in the literal
- If a newer compaction type is genuinely supported by your engine, upgrade ShardingSphere or extend isValidCompactionType locally
Example fix
// before ALTER TABLE ice_t COMPACT 'full' // after ALTER TABLE ice_t COMPACT 'MAJOR'
Defensive patterns
Strategy: validation
Validate before calling
Set<String> VALID = Set.of("MAJOR", "MINOR", "REBALANCE");
String normalize(String compactionType) {
String t = compactionType.replace("'", "").trim().toUpperCase();
if (!VALID.contains(t)) throw new IllegalArgumentException("Compaction type must be one of " + VALID);
return t;
} Try / catch
try { ddlEngine.parse(alterSql); } catch (IllegalArgumentException e) { /* message names the valid values; surface to user */ } Prevention
- Whitelist compaction types in your SQL builder before emitting COMPACT
- Strip whitespace and normalize case in generated compaction literals
When it happens
Trigger: Hive/Iceberg-style ALTER TABLE t COMPACT 'full' / 'minor_merge' / any unrecognized literal; typo in the quoted type; grammar accepts any string_ so the visitor validates the value. Triggered inside visitAlterTable when ctx.COMPACT() is non-null and isValidCompactionType returns false.
Common situations: Copying compaction commands from engine docs whose type vocabulary differs (e.g. 'full' from other systems); version drift where new compaction types exist upstream but not in this grammar's whitelist; case/whitespace mistakes inside the quoted string.
Related errors
- [CLUSTERED INTO n BUCKETS] and [ORDER BY col_list] clauses c
- Unsupported PostgreSQL format code `%s`
- 40
- Either key generator name or algorithm segment must be provi
- 1
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/e795076278e4b508.
Report an issue: GitHub.