apache/shardingsphere · error · UnsupportedOperationException

Unsupported interval unit

Error message

Unsupported interval unit

What it means

IntervalExpressionConverter maps interval unit keywords to Calcite TimeUnits (SECOND..YEAR). Any unit outside the switch (e.g. MICROSECOND, SQL_TSI_DAY, or dialect-specific units) hits the default branch and throws UnsupportedOperationException, meaning the interval literal cannot be represented for the federated plan.

Source

Thrown at kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/expression/impl/IntervalExpressionConverter.java:76

                return TimeUnit.MICROSECOND;
            case SECOND:
                return TimeUnit.SECOND;
            case MINUTE:
                return TimeUnit.MINUTE;
            case HOUR:
                return TimeUnit.HOUR;
            case DAY:
                return TimeUnit.DAY;
            case WEEK:
                return TimeUnit.WEEK;
            case MONTH:
                return TimeUnit.MONTH;
            case QUARTER:
                return TimeUnit.QUARTER;
            case YEAR:
                return TimeUnit.YEAR;
            default:
                throw new UnsupportedOperationException("Unsupported interval unit");
        }
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Rewrite the interval using supported units (e.g. INTERVAL 2 DAY instead of INTERVAL 48 HOUR where needed, or move computation to application code).
  2. Disable SQL federation for the statement so the interval is handled by the underlying database directly.
  3. Use DATE_ADD/date functions understood end-to-end instead of interval literals.

Example fix

-- before
SELECT ... WHERE ts > NOW() - INTERVAL 90 SECOND;  -- unit not in converter map depending on dialect
-- after
SELECT ... WHERE ts > NOW() - INTERVAL 1 MINUTE;
Defensive patterns

Strategy: validation

Validate before calling

Set<String> SUPPORTED_UNITS = Set.of("SECOND","MINUTE","HOUR","DAY","WEEK","MONTH","QUARTER","YEAR");
if (!SUPPORTED_UNITS.contains(unit.name())) { /* rewrite query or disable federation */ }

Try / catch

try {
    rs = executeFederated(sql);
} catch (final UnsupportedOperationException ex) {
    if ("Unsupported interval unit".equals(ex.getMessage())) { rs = executeRouted(rewrittenSql); } else { throw ex; }
}

Prevention

When it happens

Trigger: A federated query uses INTERVAL syntax with a unit keyword not in the supported set (HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, and the earlier SECOND/MINUTE cases); conversion is attempted while building the Calcite SqlNode for the interval expression.

Common situations: Porting MySQL/PostgreSQL date arithmetic that uses fine-grained or vendor-specific interval units into federated queries; dialect parsers accepting units the federation layer cannot compile.

Related errors


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