Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .agents/skills/mz-commit/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,23 @@ the current `LIR_VERSION` has shipped (see below), bump it first so the old
`lir_v{N}.json` stays in place for migration tooling and the rewrite targets
a fresh file.

### Scalar function changes: regenerate the builtin registry
### Function changes: regenerate the builtin registry

The schema registry sees a plan's shape, not what its functions compute.
`builtin_registry` covers that gap for `UnaryFunc`, `BinaryFunc`, and
`VariadicFunc`. Run it whenever the diff touches
`src/expr/src/scalar/func.rs` or `src/expr/src/scalar/func/` (including
`impls/` and `#[sqlfunc]` bodies):
`builtin_registry` covers that gap for `UnaryFunc`, `BinaryFunc`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "New function with a payload" bullet below (line 100) still names only unary_samples(), binary_samples() and variadic_samples(). Could it also name aggregate_samples() and table_samples()?

`VariadicFunc`, `AggregateFunc`, and `TableFunc`. Run it whenever the diff
touches `src/expr/src/scalar/func.rs`, `src/expr/src/scalar/func/`
(including `impls/` and `#[sqlfunc]` bodies),
`src/expr/src/relation/func.rs`, or `src/compute-types/src/plan/reduce.rs`
(which records each aggregate's reduction type):

```
cargo test -p mz-catalog --test builtin_registry
```

* It fails when a function is added, removed, or has a changed property
(nullability, error behavior, monotonicity, output type, sqlfunc
signature) or a changed `#[sqlfunc]` body. If the failure names removed or
(any field recorded in `builtin_registry.json`) or a changed `#[sqlfunc]`
body. If the failure names removed or
changed functions, or a body change that alters results, settle the
`LIR_VERSION` question below **before** regenerating. A rewrite at the old
version overwrites that version's entry in `builtin_registry_digests.json`
Expand All @@ -96,8 +98,8 @@ cargo test -p mz-catalog --test builtin_registry
* **New function with a payload** (any variant that carries data, e.g. a
target type, a regex, a scale): the registry build panics naming the
variant. Add a representative `Sample` to `unary_samples()`,
`binary_samples()`, or `variadic_samples()` in
`src/expr/src/scalar/func/registry.rs`. If a property depends on the
`binary_samples()`, `variadic_samples()`, `aggregate_samples()`, or
`table_samples()` in `src/expr/src/scalar/func/registry.rs`. If a property depends on the
payload (e.g. a cast only errors when it has a scale), add a second sample
with `.labeled("...")` covering the other branch. Payload-free variants and
plain `#[sqlfunc]` functions need no sample.
Expand Down
10 changes: 6 additions & 4 deletions .agents/skills/mz-pr-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ in `mz-expr` or `mz-repr`.
`StableRow` / `StableEvalError`, enforced by
`lir_schema_contains_only_stable_types`.

### Scalar function registry
Applies when the diff touches `UnaryFunc`, `BinaryFunc`, or `VariadicFunc`
(`src/expr/src/scalar/func.rs`, `src/expr/src/scalar/func/**`, `#[sqlfunc]`
bodies).
### Function registry
Applies when the diff touches `UnaryFunc`, `BinaryFunc`, `VariadicFunc`,
`AggregateFunc`, or `TableFunc` (`src/expr/src/scalar/func.rs`,
`src/expr/src/scalar/func/**`, `#[sqlfunc]` bodies,
`src/expr/src/relation/func.rs`), or an aggregate's reduction type in
`src/compute-types/src/plan/reduce.rs`.
- The registry snapshots under `src/catalog/tests/snapshots/` are
regenerated in the same PR. A property change moves `builtin_registry.json`
and the current version's entry in `builtin_registry_digests.json`, a
Expand Down
14 changes: 8 additions & 6 deletions .agents/skills/mz-test/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ Rewrite datadriven test expectations with `REWRITE=1 cargo test ...`.
Do not manually update `*.snap` files.
Use `cargo test` followed by `cargo insta accept` to update snapshot files.

### Scalar function registry
### Function registry

`cargo test -p mz-catalog --test builtin_registry` snapshots every
`UnaryFunc`, `BinaryFunc`, and `VariadicFunc` variant's properties and
`#[sqlfunc]` body fingerprint into `src/catalog/tests/snapshots/`. It
fails when a variant is added or removed, when a recorded property changes,
and when a `#[sqlfunc]` declaration or body changes. It records nothing for
the bodies of hand-written variants, so a change to one of those passes.
`UnaryFunc`, `BinaryFunc`, `VariadicFunc`, `AggregateFunc`, and `TableFunc`
variant's properties and `#[sqlfunc]` body fingerprint into
`src/catalog/tests/snapshots/`. It fails when a variant is added or removed,
when a recorded property changes, and when a `#[sqlfunc]` declaration or body
changes. It records nothing for the bodies of hand-written variants, which
include every `AggregateFunc` and `TableFunc` variant, so a change to one of
those passes.
Removals and property changes to a shipped `LIR_VERSION` require a bump
**before** regenerating, because a rewrite at the old version silently
overwrites that version's digest. See the mz-commit skill for the decision
Expand Down
42 changes: 34 additions & 8 deletions src/catalog/tests/builtin_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
//! canonical name, and splits each record into a properties half and a source
//! half.
//!
//! The scalar functions come from [`FuncRegistry::build`], which records every
//! `UnaryFunc`, `BinaryFunc` and `VariadicFunc` variant, see `Record` in the
//! registry module. It lives in `mz-expr` behind its `func-registry` feature,
//! which this crate's dev-dependency enables. The LIR schema snapshot in
//! `mz-compute-types` complements it: that pins the serialized shape of the
//! function enums but not what the variants mean.
//! The functions come from [`FuncRegistry::build`], which records every
//! `UnaryFunc`, `BinaryFunc`, `VariadicFunc`, `AggregateFunc` and `TableFunc`
//! variant, see `Record` in the registry module. It lives in `mz-expr` behind
//! its `func-registry` feature, which this crate's dev-dependency enables. The
//! LIR schema snapshot in `mz-compute-types` complements it: that pins the
//! serialized shape of the function enums but not what the variants mean.
//!
//! TODO(mgree): follow-up PRs will handle SQL-defined builtin functions and
//! builtin views.
Expand All @@ -47,6 +47,7 @@

use std::collections::{BTreeMap, BTreeSet};

use mz_compute_types::plan::reduce::reduction_type;
use mz_compute_types::plan::{LIR_VERSION, LIR_VERSION_POLICY};
use mz_expr::func::registry::{FuncRegistry, Record};
use serde::Serialize;
Expand All @@ -70,11 +71,11 @@ type Records = BTreeMap<String, BTreeMap<String, serde_json::Value>>;
/// Builds the properties and source halves of every builtin the snapshot
/// tracks.
fn build() -> (Records, Records) {
fn split_into<P: Serialize>(
fn split_into<F, P: Serialize>(
properties: &mut Records,
sources: &mut Records,
kind: &str,
map: &BTreeMap<String, Record<P>>,
map: &BTreeMap<String, Record<F, P>>,
) {
for (name, record) in map {
properties
Expand Down Expand Up @@ -102,6 +103,31 @@ fn build() -> (Records, Records) {
"VariadicFunc",
&registry.variadic,
);
split_into(
&mut properties,
&mut sources,
"AggregateFunc",
&registry.aggregate,
);
// Lowering stores each aggregate's reduction type in the plan, and
// rendering dispatches on the function within that type, panicking on a
// function it does not expect there (see `get_monoid` in `mz-compute`'s
// `render/reduce.rs`). `mz-expr` cannot see the classification, so it is
// recorded here.
let aggregates = properties
.get_mut("AggregateFunc")
.expect("aggregates recorded");
for (name, record) in &registry.aggregate {
let serde_json::Value::Object(fields) = aggregates.get_mut(name).expect("recorded above")
else {
panic!("aggregate properties serialize as an object");
};
fields.insert(
"reduction_type".to_string(),
to_value(&reduction_type(&record.func)),
);
}
split_into(&mut properties, &mut sources, "TableFunc", &registry.table);
(properties, sources)
}

Expand Down
Loading