Skip to content

bug: unknown aggregate / window function only errors once a row matches; returns empty on no data #414

Closed

Description

@adityamukho

Summary

Split out of #405 (see its comment). Whether a query with an unregistered aggregate or window function errors depends on the data. With no matching rows it returns "No results found". Once a row matches, it fails with INT-029 (aggregate) or INT-030 (window function).

Unknown predicates (QRY-007) already error in both cases.

Repro (REPL, main at 06db149)

(query [:find (frob ?b) :where [?a :x ?b]])
;; No results found.
(transact [[:a :x 1]])
(query [:find (frob ?b) :where [?a :x ?b]])
;; Error: [INT-029] unknown aggregate function: 'frob'
(query [:find ?b (frob ?b :over (:order-by ?b)) :where [?a :x ?b]])
;; No results found.
(transact [[:a :x 1]])
(query [:find ?b (frob ?b :over (:order-by ?b)) :where [?a :x ?b]])
;; Error: [INT-030] unknown window function 'frob' — register it with register_aggregate() before querying

Cause

The function name is resolved only when rows are aggregated or windowed (src/query/datalog/executor.rs, Int029 near line 1495, Int030 near line 1608). The empty-result path returns before that point.

Suggested fix

Resolve every aggregate and window function in :find against the FunctionRegistry before execution, or at least before the empty-result short-circuit, the same way predicates are checked. The error should probably be a user-facing QRY-* code rather than an INT-* code, since this is a user error, not an internal one. Error codes are never removed, so keep INT-029/INT-030 registered.

Why v3.0.0

The fix turns queries that currently return an empty result into errors. #406 was moved to v3.0.0 for the same reason.

Tests

  • Unknown aggregate on an empty database fails.
  • Unknown aggregate when the :where clause matches nothing fails.
  • Unknown window function in both cases fails.
  • A registered UDF aggregate or window function on an empty database still returns an empty result.

Activity

  1. added this to the v3.0.0 milestone on Sep 26, 2026
  2. added a commit that references this issue on Oct 8, 2026
  3. adityamukho commented on Oct 8, 2026

    @adityamukho
    CollaboratorAuthor

    Fixed on v3 by #483 (ships in v3.0.0).

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

    bugSomething isn't workingstabilityStability/panic issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions