Skip to content

SQL: subquery-valued predicates (IN/EXISTS/scalar), DISTINCT ON, and median/array_agg unsupported #111

Description

@zzylol

Summary

Three structural SQL features are rejected by the lowerer. Grouped because each is individually small; split out if any one is prioritized.

Like #110, none of these are exercised by the existing SQL corpus tests, which pass.

Reproduction

Against the netflow_table / hosts catalog:

-- 1. subquery-valued predicates (three shapes, one error)
SELECT * FROM netflow_table WHERE srcip IN (SELECT ip FROM hosts);
SELECT * FROM netflow_table n WHERE EXISTS (SELECT 1 FROM hosts h WHERE h.ip = n.srcip);
SELECT srcip, (SELECT MAX(pkt_len) FROM netflow_table) FROM netflow_table;
-- unsupported feature: subquery-valued expression in predicate

-- 2. DISTINCT ON
SELECT DISTINCT ON (srcip) srcip, pkt_len FROM netflow_table;
-- unsupported feature: DISTINCT ON

-- 3. long-tail aggregates
SELECT median(pkt_len) FROM netflow_table;      -- unsupported aggregate: median
SELECT array_agg(srcip) FROM netflow_table;     -- unsupported aggregate: array_agg  (WONTFIX)

Location

  • crates/frontend-sql/src/sql/expr.rs:191subquery-valued expression in predicate
  • crates/frontend-sql/src/sql/mod.rs:106LogicalPlan::Subquery(_)
  • crates/frontend-sql/src/sql/mod.rs:82Distinct::On(_)
  • crates/frontend-sql/src/sql/mod.rs:469UnsupportedAggregate(name)

Notes

  • Subqueries. IN (subquery), EXISTS, and a scalar subquery in the select list all hit the same expr.rs:191 rejection. Uncorrelated cases (IN, scalar) reduce to a semi-join / broadcast scalar and are the tractable subset; correlated EXISTS is materially harder. Note that derived tables (FROM (SELECT …)) and WITH do lower today — this is specifically about subqueries in expression position. See also SQL: derived-table joins silently degenerate to a cross product #66 (derived-table joins → cross product), now closed.
  • median is the interesting one for this project: it is exactly AggIntent::Quantile { q: 0.5 }, which the lowerer already emits for approx_percentile_cont (which does lower). Mapping median onto it is close to a one-liner and directly feeds the sketch path.
  • array_agg — WONTFIX (decided 2026-07-09). It does not pre-aggregate (output is O(input rows)), has no bounded-memory approximate form, and its partial state is the data, so "mergeable" means nothing for it. plan::boundary::realize is an exhaustive match over AggIntent, so adding a variant would force boundary, bind and schema derivation to each handle it — and every answer would be PassThrough. It also appears in neither SQL corpus. unsupported aggregate: array_agg is the intended behaviour. See the comment below.
  • DISTINCT ON is Postgres-flavoured "first row per group" — it overlaps with the partitioned-topk work in SQL: partitioned topk (top-k per group via window functions) is unsupported #24.
  • Aside, not filed: SELECT SUM(x) FILTER (WHERE …) fails earlier, inside DataFusion 43's parser (ParserError("Expected end of statement, found: (")), so it is not our rejection to fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsqlSQL front-end lowering (DataFusion → L2)testingCorpus, regression, differential, or benchmark tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions