Ray's Knowledge Base
Unlock

A duql group or agg entry that is an expression lowers to hidden aggregates plus a derive and a drop

DecisionVerified 30 Sep 2026Holds project: dftracer-utils
Decision. The context, the choice, why, and the options that were turned down.

Context#

A group or agg entry can be an expression over aggregates, such as sum(a) / count(b).

Decision#

Lower it like window hidden columns: hidden aggregates, then a derive that computes the expression, then a drop of the hidden columns. The first aggregate takes the entry's name, so the derive replaces it in place and the block order holds. Pivot entries stay one aggregate call.

Why#

This reuses the existing hidden-column lowering and keeps the output columns in the order written.

Rejected options#

A syntax-tree rewrite: it needs a clone of the tree and loses error spans.

Also found by searching

  • duql agg entry sum(a) / count(b) not supported or column order wrong
  • an aggregate expression in group block puts output columns in wrong order
  • how do I lower an expression over aggregates in a duql group or agg entry
  • hidden aggregate columns then derive then drop, pivot entries single aggregate
  • duql agg entry like sum(a) / count(b) as an expression, how does it lower?
  • group entry that is an expression over aggregates, hidden columns derive drop
  • how does duql lower expression over aggregate calls and keep output column order?
  • why not do a syntax tree rewrite for agg expressions in duql lowering, error spans lost