apache/shardingsphere · error · UnsupportedSQLOperationException

1

1

Error message

Unsupported SQL operation: unsupported strategy type `%s`.

What it means

UnsupportedSQLOperationException thrown by ShardingStrategyType.getValueOf(String) when the strategy type name in a DistSQL sharding rule cannot be matched to an enum constant: valueOf(name.toUpperCase()) throws IllegalArgumentException and the catch rethrows with the offending name. The accepted names are the enum constants (STANDARD, COMPLEX, HINT, NONE for sharding strategy types).

Source

Thrown at features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/enums/ShardingStrategyType.java:167

     * Check whether the configuration is valid.
     *
     * @param shardingColumn sharding column
     * @return valid or invalid
     */
    public abstract boolean isValid(String shardingColumn);
    
    /**
     * Returns the sharding strategy type.
     *
     * @param name name
     * @return sharding strategy type
     * @throws UnsupportedSQLOperationException unsupported SQL operation exception
     */
    public static ShardingStrategyType getValueOf(final String name) {
        try {
            return valueOf(name.toUpperCase());
        } catch (final IllegalArgumentException ignored) {
            throw new UnsupportedSQLOperationException(String.format("unsupported strategy type `%s`", name));
        }
    }
    
    /**
     * Returns the sharding strategy type.
     *
     * @param config sharding strategy configuration
     * @return sharding strategy type
     */
    public static ShardingStrategyType getValueOf(final ShardingStrategyConfiguration config) {
        return Arrays.stream(values()).filter(each -> config.getClass().isAssignableFrom(each.getImplementedClass())).findFirst()
                .orElseThrow(() -> new UnsupportedOperationException(String.format("unsupported strategy type: `%s`.", config.getClass().getName())));
    }
    
    /**
     * Judge whether the input strategy type is valid.
     *
     * @param type type

View on GitHub (pinned to e952770a21)

Solutions

  1. Use a valid strategy type name (STANDARD, COMPLEX, HINT, NONE — case-insensitive) in the TYPE clause.
  2. If you meant an algorithm, put its name in the algorithm segment, not the strategy-type position.
  3. Check the DistSQL reference for your ShardingSphere version; strategy-type sets differ across releases.

Example fix

-- before: algorithm name used as strategy type
ALTER SHARDING TABLE RULE t_order (
  ..., TYPE(NAME=hash_mod, PROPERTIES("sharding-count"=4))
);

-- after: valid strategy type + algorithm where applicable
ALTER SHARDING TABLE RULE t_order (
  ..., TYPE(STANDARD, SHARDING_COLUMN=order_id, SHARDING_ALGORITHM(NAME=hash_mod, PROPERTIES("sharding-count"=4)))
);
Defensive patterns

Strategy: validation

Validate before calling

// Whitelist strategy type names before applying DistSQL
Set<String> VALID = Set.of("STANDARD", "COMPLEX", "HINT", "NONE");
if (!VALID.contains(strategyTypeName.toUpperCase(Locale.ROOT))) {
    throw new IllegalArgumentException("Unknown sharding strategy type: " + strategyTypeName);
}

Type guard

boolean isValidShardingStrategyType(final String name) {
    return Arrays.stream(ShardingStrategyType.values()).anyMatch(t -> t.name().equalsIgnoreCase(name));
}

Try / catch

try {
    ShardingStrategyType.getValueOf(name);
} catch (final UnsupportedSQLOperationException ex) {
    // surface valid type names to the user; do not retry with the same input
}

Prevention

When it happens

Trigger: TYPE(NAME=xxx) in CREATE/ALTER SHARDING TABLE RULE (or ALTER SHARDING ... STRATEGY) where xxx is not a valid ShardingStrategyType constant — typos like 'hash_mod' used in the strategy-type position, or names from an older/newer version.

Common situations: Confusing the strategy type name with the sharding algorithm name; using strategy types removed or renamed between ShardingSphere versions; hand-crafted DistSQL without checking the grammar.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/fd074ad7a7a3930b. Report an issue: GitHub.