{"record":{"id":"0b8cc4e60749e774","repo":"apache/shardingsphere","slug":"unsupported-interval-unit","errorCode":null,"errorMessage":"Unsupported interval unit","messagePattern":"Unsupported interval unit","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/expression/impl/IntervalExpressionConverter.java","lineNumber":76,"sourceCode":"                return TimeUnit.MICROSECOND;\n            case SECOND:\n                return TimeUnit.SECOND;\n            case MINUTE:\n                return TimeUnit.MINUTE;\n            case HOUR:\n                return TimeUnit.HOUR;\n            case DAY:\n                return TimeUnit.DAY;\n            case WEEK:\n                return TimeUnit.WEEK;\n            case MONTH:\n                return TimeUnit.MONTH;\n            case QUARTER:\n                return TimeUnit.QUARTER;\n            case YEAR:\n                return TimeUnit.YEAR;\n            default:\n                throw new UnsupportedOperationException(\"Unsupported interval unit\");\n        }\n    }\n}\n","sourceCodeStart":58,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/expression/impl/IntervalExpressionConverter.java#L58-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rewrite the interval using supported units (e.g. INTERVAL 2 DAY instead of INTERVAL 48 HOUR where needed, or move computation to application code).","Disable SQL federation for the statement so the interval is handled by the underlying database directly.","Use DATE_ADD/date functions understood end-to-end instead of interval literals."],"exampleFix":"-- before\nSELECT ... WHERE ts > NOW() - INTERVAL 90 SECOND;  -- unit not in converter map depending on dialect\n-- after\nSELECT ... WHERE ts > NOW() - INTERVAL 1 MINUTE;","handlingStrategy":"validation","validationCode":"Set<String> SUPPORTED_UNITS = Set.of(\"SECOND\",\"MINUTE\",\"HOUR\",\"DAY\",\"WEEK\",\"MONTH\",\"QUARTER\",\"YEAR\");\nif (!SUPPORTED_UNITS.contains(unit.name())) { /* rewrite query or disable federation */ }","typeGuard":null,"tryCatchPattern":"try {\n    rs = executeFederated(sql);\n} catch (final UnsupportedOperationException ex) {\n    if (\"Unsupported interval unit\".equals(ex.getMessage())) { rs = executeRouted(rewrittenSql); } else { throw ex; }\n}","preventionTips":["Restrict INTERVAL literals to SECOND..YEAR units in federated queries.","Push date arithmetic down to the storage when possible.","Test interval-heavy SQL against federation before shipping."],"tags":["sql-federation","interval","calcite","expression"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}