Skip to content

expr: Return specific output types instead of Datum - #39105

Merged
antiguru merged 1 commit into
sqlfunc-convert-int16from
sqlfunc-specific-output-types
Oct 14, 2026
Merged

antiguru merged 1 commit into
sqlfunc-convert-int16from
sqlfunc-specific-output-types

Conversation

@antiguru

@antiguru antiguru commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Fifteen #[sqlfunc] functions returned a bare Datum although each always produces an array, a list, a map or a JSON value. Each therefore restated its nullability with introduces_nulls. They now return Array<'a>, DatumList<'a> or DatumMap<'a>, or an Option of one where the function can return NULL, and the macro derives the value. The shared helpers return the typed values too, and the two jsonb_delete functions drop their output_type_expr.

The registry reports only sqlfunc_signature moving, on all fifteen records.

Based on #39062.

🤖 Generated with Claude Code

@antiguru
antiguru requested a review from a team as a code owner September 24, 2026 10:15
@antiguru
antiguru added this pull request to stack #38942 September 24, 2026 10:15
@antiguru
antiguru requested a review from petrosagg September 24, 2026 11:18
@antiguru
antiguru force-pushed the sqlfunc-specific-output-types branch from 72d9f56 to 70281de Compare September 24, 2026 14:29
@antiguru
antiguru force-pushed the sqlfunc-specific-output-types branch from 70281de to 4941c1e Compare September 25, 2026 16:00
@antiguru
antiguru removed the request for review from petrosagg October 13, 2026 15:55
@antiguru
antiguru force-pushed the sqlfunc-specific-output-types branch from 4941c1e to f499b3c Compare October 14, 2026 09:11
@antiguru
antiguru requested a review from mgree October 14, 2026 10:22
@antiguru
antiguru force-pushed the sqlfunc-specific-output-types branch from f499b3c to 9cf6009 Compare October 14, 2026 15:18
@antiguru
antiguru removed this pull request from stack #38942 October 14, 2026 15:45
@antiguru
antiguru changed the base branch from sqlfunc-convert-string to sqlfunc-convert-int16 October 14, 2026 15:45
@antiguru
antiguru force-pushed the sqlfunc-specific-output-types branch from 9cf6009 to 7c97bf1 Compare October 14, 2026 15:46
@antiguru
antiguru added this pull request to stack #39823 October 14, 2026 15:46

@mgree mgree left a comment

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.

Looks okay!

Fifteen `#[sqlfunc]` functions returned a bare `Datum` although each always
produces an array, a list, a map or a JSON value. `Datum`'s `OutputDatumType`
reports nullable, so every one of them carried an explicit `introduces_nulls` to
restate what the body already guaranteed. Returning `Array<'a>`, `DatumList<'a>`,
`DatumMap<'a>`, or an `Option` of one, lets the macro derive that value instead.

`array_create`, `array_fill`, `array_remove`, `string_to_array` and both arities
of `regexp_split_to_array` return `Array<'a>`. `list_create`, `record_create`,
`list_slice_linear` and `timezone_offset` return `DatumList<'a>`, and `map_build`
returns `DatumMap<'a>`. Each drops `introduces_nulls = false`. Both arities of
`regexp_match` return `Option<Array<'a>>`, since a failed match is NULL, and
`jsonb_delete_int64` and `jsonb_delete_string` return `Option<JsonbRef<'a>>`,
since deleting from a JSON scalar is NULL. `JsonbRef` has a column type, so the
two `jsonb_delete` functions also drop their `output_type_expr`.

The shared helpers `array_create_scalar`, `array_create_multidim`,
`regexp_match_static`, `regexp_split_to_array_re` and `string_to_array_impl`
return the typed value too, so the conversion happens where the datum is packed.
`regexp_match_static` takes the haystack as `&str`, which lets the unary
`regexp_match` take `&'a str` in place of `ExcludeNull<Datum<'a>>`.

The registry reports only `sqlfunc_signature` moving, on all fifteen records.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@antiguru
antiguru force-pushed the sqlfunc-specific-output-types branch from 7c97bf1 to a3cfb05 Compare October 14, 2026 19:12
@antiguru
antiguru merged commit 64a76e1 into main Oct 14, 2026
83 checks passed
@antiguru
antiguru deleted the sqlfunc-specific-output-types branch October 14, 2026 19:50
antiguru added a commit that referenced this pull request Oct 14, 2026
…d_from_record_list (#39814)

Two functions declared properties more conservatively than their bodies
need, inherited from hand-written impls and kept by their conversion to
`#[sqlfunc]` in #39062. This drops the pins and lets the macro derive
the properties from the output type.

* `record_get` returns a field of its input record and never produces an
`EvalError`, but it declared `could_error = true`, the `LazyUnaryFunc`
default. It now derives `false` from the non-`Result` output.
* `map_build_from_record_list` skips NULL records and keys and always
returns a map, but it declared `introduces_nulls` and `could_error` true
and a nullable output. Both flags now derive `false` from the `DatumMap`
output, and the output type is non-nullable.

The registry reports exactly these moves. The current `LIR_VERSION`
hasn't shipped, so the snapshots are regenerated in place. The
sqllogictest files that mention `record_get` show no plan changes, and
the sqllogictest shards passed on an earlier version of the stack that
carried the `map_build_from_record_list` change.

Based on #39105.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants