apache/shardingsphere · error · UnsupportedSQLOperationException

Unsupported segment type: %s

Error message

Unsupported segment type: %s

What it means

TableConverter.convert dispatches on the FROM-clause table segment type: SimpleTableSegment, JoinTableSegment, SubqueryTableSegment, and DeleteMultiTableSegment are handled; any other TableSegment subclass throws UnsupportedSQLOperationException with the class name. Federation compilation only supports these table reference shapes.

Source

Thrown at kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/from/TableConverter.java:65

     * @throws UnsupportedSQLOperationException unsupported SQL operation exception
     */
    public static Optional<SqlNode> convert(final TableSegment segment) {
        if (null == segment) {
            return Optional.empty();
        }
        if (segment instanceof SimpleTableSegment) {
            return SimpleTableConverter.convert((SimpleTableSegment) segment);
        }
        if (segment instanceof JoinTableSegment) {
            return JoinTableConverter.convert((JoinTableSegment) segment);
        }
        if (segment instanceof SubqueryTableSegment) {
            return SubqueryTableConverter.convert((SubqueryTableSegment) segment);
        }
        if (segment instanceof DeleteMultiTableSegment) {
            return DeleteMultiTableConverter.convert((DeleteMultiTableSegment) segment);
        }
        throw new UnsupportedSQLOperationException("Unsupported segment type: " + segment.getClass());
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Restructure the query so FROM items are plain tables, joins of tables, or subqueries with aliases.
  2. Replace table-valued functions / LATERAL references with subqueries the converter supports.
  3. Disable federation for this query so it executes on the storage directly.

Example fix

-- before
SELECT * FROM GENERATE_SERIES(1, 10) AS g(n);
-- after
SELECT * FROM (SELECT 1 AS n UNION ALL SELECT 2) AS g;
Defensive patterns

Strategy: fallback

Try / catch

try {
    rs = executeFederated(sql);
} catch (final SQLFederationUnsupportedSQLException ex) {
    if (ex.getMessage().contains("Unsupported segment type")) { rs = executeOnSingleStorage(sql); } else { throw ex; }
}

Prevention

When it happens

Trigger: A federated query's FROM clause contains a table reference the converter does not model — e.g. a VALUES clause table, LATERAL table, function table (unnest/generate_series), or a newer parser segment type — reaching convert() during compilation.

Common situations: Queries with table-valued functions or CTE-only shapes; parser versions that produce distinct segment classes for exotic FROM items; dialect-specific joins.

Related errors


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