Skip to content

expr: Convert timestamp.rs to the sqlfunc macro - #39096

Closed
antiguru wants to merge 1 commit into
sqlfunc-convert-listfrom
sqlfunc-convert-timestamp
Closed

antiguru wants to merge 1 commit into
sqlfunc-convert-listfrom
sqlfunc-convert-timestamp

Conversation

@antiguru

@antiguru antiguru commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Converts the sixteen hand-written EagerUnaryFunc impls in timestamp.rs to #[sqlfunc]. All of them read their payload, so they take &self. The four precision casts build their output precision from self.to in an output_type_expr. The other twelve print their payload in Display, so they keep their hand-written impls under skip_display.

func_registry_records_sqlfunc_sources switches its example of a function with no recorded source to cast_array_to_array. The registry reports only sqlfunc_signature moving, on all twenty-six records. No declared property changed.

Based on #39095.

🤖 Generated with Claude Code

@antiguru
antiguru requested a review from a team as a code owner September 23, 2026 21:10
@antiguru
antiguru added this pull request to stack #38942 September 24, 2026 08:52
@antiguru
antiguru force-pushed the sqlfunc-convert-list branch from e1e3e5f to f9a0c1b Compare September 24, 2026 10:14
@antiguru
antiguru force-pushed the sqlfunc-convert-timestamp branch from 4ec5632 to 9aebe53 Compare September 24, 2026 10:14
@antiguru
antiguru requested a review from petrosagg September 24, 2026 11:18
@antiguru
antiguru force-pushed the sqlfunc-convert-timestamp branch from 9aebe53 to ab55f6f Compare September 24, 2026 14:29
@antiguru
antiguru force-pushed the sqlfunc-convert-list branch 2 times, most recently from 4ecb9b0 to e0ab240 Compare September 25, 2026 16:00
@antiguru
antiguru force-pushed the sqlfunc-convert-timestamp branch from ab55f6f to ba19b21 Compare September 25, 2026 16:00
@antiguru
antiguru removed the request for review from petrosagg October 13, 2026 15:56
@antiguru
antiguru force-pushed the sqlfunc-convert-timestamp branch from ba19b21 to f2987f6 Compare October 14, 2026 09:11
@antiguru
antiguru requested a review from mgree October 14, 2026 10:22
All sixteen hand-written `EagerUnaryFunc` impls in the file read their payload in
`call`, so each takes a `&self` receiver and the macro attaches the annotated
function as an inherent method on the existing struct.

Four of them need `output_type_expr`. `CastTimestampToTimestampTz`,
`AdjustTimestampPrecision`, `CastTimestampTzToTimestamp` and
`AdjustTimestampTzPrecision` build the output precision out of `self.to`, which
the derived `CheckedTimestamp` column type cannot express. Each expression sets
nullability from the input, and the unary tail adds only `propagates_nulls &&
input_type.nullable`, which the non-nullable timestamp input makes the same
term. `introduces_nulls` derives false from the non-`Option` output. Their
shared `preserves_uniqueness` body carries over verbatim as a block expression
over `self`.

The other twelve need no output modifier. `Result<Numeric, EvalError>`,
`Result<f64, EvalError>`, `Result<CheckedTimestamp<_>, EvalError>` and `String`
derive `Numeric { max_scale: None }`, `Float64`, `Timestamp`/`TimestampTz` with
`precision: None`, and `String` respectively, which is exactly what each
`output_sql_type` returned once the tail is applied.

Per-override accounting: `call` becomes the function body. `is_monotone` carries
over as a constant on the four precision functions and the two `date_trunc`
functions, and as an expression over `self` on `ExtractTimestamp` and
`ExtractTimestampTz`. `inverse` carries over on the two casts. The two
`AdjustTimestamp*Precision` impls overrode `inverse` with `None`, which is the
trait default, so the override disappears. `could_error` stays derived, true for
the `Result` outputs and false for the two `to_char` functions, matching impls
that never overrode it. `propagates_nulls` was never overridden and derives true
from the non-nullable inputs.

The four precision functions wrote a fixed string in `Display`, so `sqlname`
reproduces it. The other twelve format their payload, so they keep their
hand-written `Display` under `skip_display = true`.

`func_registry_records_sqlfunc_sources` used `extract_interval` as its example of
a function with no recorded source. It now uses `cast_array_to_array`, one of the
compound-type casts generic over an `Eval` implementor, a shape the macro does
not cover.

The registry reports only `sqlfunc_signature` moving, on all twenty-six records.
No declared property changed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@antiguru
antiguru force-pushed the sqlfunc-convert-list branch from 07abebd to cb7b4a1 Compare October 14, 2026 15:18
@antiguru
antiguru force-pushed the sqlfunc-convert-timestamp branch from f2987f6 to 7937dc3 Compare October 14, 2026 15:18
@antiguru
antiguru removed this pull request from stack #38942 October 14, 2026 15:45
@antiguru

Copy link
Copy Markdown
Member Author

Folded into #39062, which now carries all twenty file conversions as separate commits, per review feedback to land them as one PR.

Posted by Claude Code.

@antiguru antiguru closed this Oct 14, 2026
@antiguru
antiguru deleted the sqlfunc-convert-timestamp branch October 14, 2026 19:52
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.

1 participant