Skip to content

Commit ae3cc46

Browse files
antiguruclaude
andauthored
expr: Accept stateful unary and binary functions in the sqlfunc macro (#38941)
`EagerUnaryFunc::call` receives a `&RowArena`, and the `#[sqlfunc]` macro accepts a `&self` receiver and a trailing `&RowArena` at unary and binary arity, not only at variadic. This unblocks the hand-written functions that need state or an arena. A new `skip_display` modifier keeps a hand-written `Display` for names that depend on state. `inverse` and `negate` take the function itself, and `output_type_expr` no longer requires `introduces_nulls`. `RangeCreate` is converted as the first user, and the macro reference in `doc/developer/sqlfunc.md` is corrected. The last commits tidy the macro crate. Modifier validation happens in one place and reports every error at its modifier, all arities take their parameters the same way, so a nested reference in a unary or binary parameter gets the trait's lifetime, and the tests move to `test.rs`. The registry reports only `range_create`'s `sqlfunc_signature` moving. No declared property changed. Based on #38929. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent 8d7fa94 commit ae3cc46

63 files changed

Lines changed: 1806 additions & 1325 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎doc/developer/sqlfunc.md‎

Lines changed: 118 additions & 51 deletions
Large diffs are not rendered by default.

‎src/catalog/tests/audit_log_details.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use mz_audit_log::EventDetails;
2626
use mz_catalog::durable::objects::serialization::RustType;
2727
use mz_catalog_protos::objects::audit_log_event_v1;
2828
use mz_expr::func::{EagerUnaryFunc, ParseCatalogAuditLogDetails};
29+
use mz_repr::RowArena;
2930
use mz_repr::adt::jsonb::Jsonb;
3031
use proptest::prelude::*;
3132

@@ -42,8 +43,9 @@ proptest! {
4243
let proto_json = serde_json::to_value(&proto).expect("proto serializes");
4344
let jsonb = Jsonb::from_serde_json(proto_json).expect("valid jsonb");
4445

46+
let temp_storage = RowArena::new();
4547
let got = ParseCatalogAuditLogDetails
46-
.call(jsonb.as_ref())
48+
.call(jsonb.as_ref(), &temp_storage)
4749
.expect("helper succeeded");
4850
let got_json = got.as_ref().to_serde_json();
4951

‎src/catalog/tests/sql_parse_catalog.rs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@ use mz_repr::adt::jsonb::Jsonb;
2020
use mz_repr::adt::mz_acl_item::{AclMode, MzAclItem};
2121
use mz_repr::network_policy_id::NetworkPolicyId;
2222
use mz_repr::role_id::RoleId;
23-
use mz_repr::{CatalogItemId, GlobalId};
23+
use mz_repr::{CatalogItemId, GlobalId, RowArena};
2424
use mz_sql::names::{DatabaseId, SchemaId};
2525
use proptest::prelude::*;
2626

2727
fn serialize_and_parse_catalog_id(val: &impl serde::Serialize) -> String {
2828
let json = serde_json::to_value(val).unwrap();
2929
let jsonb = Jsonb::from_serde_json(json).unwrap();
30-
ParseCatalogId.call(jsonb.as_ref()).unwrap()
30+
let temp_storage = RowArena::new();
31+
ParseCatalogId.call(jsonb.as_ref(), &temp_storage).unwrap()
3132
}
3233

3334
fn serialize_and_parse_catalog_privileges(val: &impl serde::Serialize) -> Vec<MzAclItem> {
3435
let json = serde_json::to_value(val).unwrap();
3536
let jsonb = Jsonb::from_serde_json(json).unwrap();
36-
ParseCatalogPrivileges.call(jsonb.as_ref()).unwrap().0
37+
let temp_storage = RowArena::new();
38+
ParseCatalogPrivileges
39+
.call(jsonb.as_ref(), &temp_storage)
40+
.unwrap()
41+
.0
3742
}
3843

3944
proptest! {

‎src/compute-types/tests/snapshots/func_registry.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/compute-types/tests/snapshots/func_registry_digests.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)