Skip to content

SQL: qualified column refs in extension intents and temporal aggregates bind by name only #1280

Open

Description

@zzylol

Problem, by example

The two SQL queries below are each lowered over a join. The example comes from reading the code; it has not been run.

-- (1) the qualifier names the wrong side, but the query still lowers
SELECT a.k, arg_max(a.payload, a.ts)
FROM t a JOIN u b ON a.k = b.k
GROUP BY a.k;          -- suppose only `u` has a `ts` column

-- (2) the qualifier names a side, but the query is refused
SELECT a.k, arg_max(a.payload, a.v)
FROM t a JOIN u b ON a.k = b.k
GROUP BY a.k;          -- both `t` and `u` have `v`
  • What happens today. In (1), a.ts binds to b.ts, because ts is the only column with that name. In (2), a.v fails with column v matches several columns.
  • What should happen. (1) should report that a has no column ts. (2) should bind a.v to the left side's v.

The same applies to the timestamp, value and group arguments of SQL temporal aggregates.

Why it happens

A schema carries no table qualifier any more: column lineage replaced Field.table. The front end resolves every other qualified name with its own Scope (crates/frontend-common/src/resolve.rs), using the qualifiers it tracks for each column.

Two paths do not go through that scope. They keep a ColumnRef::Qualified and resolve it later with resolve_column_ref (crates/types/src/ir/scalar/column_resolution.rs), which drops the qualifier and matches the name only:

  • the payload columns of an extension intent (arg_max / arg_min), resolved at crates/types/src/ir/operator/agg_intent.rs (resolve("arg_col") / resolve("val_col"));
  • the arguments of a SQL temporal aggregate, resolved in crates/frontend-sql/src/sql/mod.rs (timestamp_ref, value_ref, group_ref).

Making the Qualified arm strict (a debug_assert or an error) breaks 18 existing tests, so for now it stays name-only, and its comment says so.

Proposal

The front ends bind these references through their Scope while lowering, as they do for every other column, and pass a positional ColumnRef::Id or Named into the IR. After that, resolve_column_ref rejects Qualified as an error ("a qualified name reaches the IR unbound").

Scope and acceptance

  • In scope: the SQL front end's extension intents and temporal aggregates, plus the Qualified arm of resolve_column_ref.
  • Out of scope: PromQL, which has no qualifiers.
  • Acceptance:
    • Query (1) returns an error.
    • Query (2) binds a.v.
    • The 18 tests that a strict arm breaks today pass with the strict arm.

Related

Activity

  1. added
    bugSomething isn't working
    sqlSQL front-end lowering (DataFusion → L2)
    bindingLogical-to-physical binding and implementation selection
    on Nov 11, 2026
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

    bindingLogical-to-physical binding and implementation selectionbugSomething isn't workingsqlSQL front-end lowering (DataFusion → L2)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions