{"record":{"id":"4087ef827e714182","repo":"apache/druid","slug":"cannot-filter-datasource-s-using-s","errorCode":null,"errorMessage":"Cannot filter datasource [%s] using [%s]","messagePattern":"Cannot filter datasource \\[(.+?)\\] using \\[(.+?)\\]","errorType":"validation","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"multi-stage-query/src/main/java/org/apache/druid/msq/querykit/datasource/DataSourcePlannerUtils.java","lineNumber":79,"sourceCode":"  }\n\n  /**\n   * Verify that the provided {@link QuerySegmentSpec} is a {@link MultipleIntervalSegmentSpec} with\n   * interval {@link Intervals#ETERNITY}. If not, throw an {@link UnsupportedOperationException}.\n   * <p>\n   * See {@link org.apache.druid.sql.calcite.rel.DruidQuery#canUseIntervalFiltering(DataSource)}.\n   */\n  public static void checkQuerySegmentSpecIsEternity(\n      final DataSource dataSource,\n      final QuerySegmentSpec querySegmentSpec\n  )\n  {\n    final boolean querySegmentSpecIsEternity =\n        querySegmentSpec instanceof MultipleIntervalSegmentSpec\n        && querySegmentSpec.getIntervals().equals(Intervals.ONLY_ETERNITY);\n\n    if (!querySegmentSpecIsEternity) {\n      throw new UOE(\n          \"Cannot filter datasource [%s] using [%s]\",\n          dataSource.getClass().getName(),\n          ColumnHolder.TIME_COLUMN_NAME\n      );\n    }\n  }\n}\n","sourceCodeStart":61,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/datasource/DataSourcePlannerUtils.java#L61-L87","documentation":"When a Druid 'table' (or similar) datasource is used with MSQ, the query's segment spec must cover all of time (eternity). checkQuerySegmentSpecIsEternity throws this UnsupportedOperationException when the intervals filter is anything other than [MIN-MAX]/eternity, i.e. the user tried to restrict the datasource with an intervals() filter that MSQ cannot push down here.","triggerScenarios":"Issuing an MSQ/dsql query against a datasource with a non-eternity intervals segment spec (e.g. intervals() filter or a table Function datasource restricted to specific intervals), such as SELECT ... FROM TABLE(...WHERE intervals filter) rather than a WHERE __time filter.","commonSituations":"Migrating native queries that use intervals() filters to SQL/MSQ; tooling that generates TableFunction datasources with interval restrictions; users expecting interval pruning like the native engine provides.","solutions":["Replace the intervals filter with a WHERE __time >= ... AND __time < ... predicate on the time column.","Remove the interval restriction and query the full datasource, filtering results in SQL.","Rewrite as a native query (not MSQ) if interval-based segment pruning is essential.","Upgrade Druid if a newer version supports interval pushdown for this datasource type."],"exampleFix":"// before\nSELECT * FROM TABLE(intervals('2023-01-01/2023-02-01')) AS t\n// after\nSELECT * FROM myds t WHERE __time >= TIMESTAMP '2023-01-01 00:00:00' AND __time < TIMESTAMP '2023-02-01 00:00:00'","handlingStrategy":"validation","validationCode":"// Ensure any intervals spec on the datasource is eternity before submitting to MSQ\nif (spec.intervals && !(spec.intervals.length === 1 && spec.intervals[0] === '-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z')) {\n  throw new Error('MSQ datasource intervals must be eternity; use WHERE __time filters instead');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use WHERE __time predicates for time restriction in MSQ/SQL.","Avoid TABLE(intervals(...)) datasource functions in MSQ queries.","Translate native intervals() filters into SQL time predicates when migrating."],"tags":["msq","sql","intervals"],"backgroundTag":"unsupported-operation","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}