Skip to content

expr: Convert date.rs to the sqlfunc macro - #39089

Closed
antiguru wants to merge 1 commit into
sqlfunc-convert-jsonbfrom
sqlfunc-convert-date
Closed

antiguru wants to merge 1 commit into
sqlfunc-convert-jsonbfrom
sqlfunc-convert-date

Conversation

@antiguru

@antiguru antiguru commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Converts CastDateToTimestamp, CastDateToTimestampTz and ExtractDate to #[sqlfunc]. All three read their payload, so they take &self. The two casts build their output precision from the payload in an output_type_expr. ExtractDate prints its payload in Display, so it keeps its hand-written impl under skip_display.

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

Based on #39088.

🤖 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-date branch from 39c186f to f2e201e Compare September 24, 2026 10:14
@antiguru
antiguru force-pushed the sqlfunc-convert-jsonb branch from 960542c to b107894 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-date branch 2 times, most recently from d45e6db to 893ab72 Compare September 25, 2026 16:00
@antiguru
antiguru force-pushed the sqlfunc-convert-jsonb branch from 205c406 to 862741f 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-date branch from 893ab72 to 27ae985 Compare October 14, 2026 09:11
@antiguru
antiguru force-pushed the sqlfunc-convert-jsonb branch from 862741f to 4adb0cd Compare October 14, 2026 09:11
@antiguru
antiguru requested a review from mgree October 14, 2026 10:22
`CastDateToTimestamp`, `CastDateToTimestampTz` and `ExtractDate` all read their
payload in `call`, so each takes a `&self` receiver.

The two casts need `output_type_expr`: their `output_sql_type` built the
precision out of the payload, which the derived `CheckedTimestamp` column type
cannot express. The expression sets nullability from the input and the macro's
unary tail adds only `propagates_nulls && input_type.nullable`, which the
non-nullable `Date` input makes the same term. `introduces_nulls` derives false
from the non-`Option` output.

`ExtractDate` needs no output modifier. Its `output_sql_type` returned
`Numeric { max_scale: None }.nullable(input.nullable)`, which is exactly what
`Result<Numeric, EvalError>` derives once the tail is applied.

Per-override accounting, for all three: `call` becomes the function body.
`preserves_uniqueness = true` and `inverse` carry over on the casts as
modifiers, `is_monotone = true` likewise, and `ExtractDate` keeps its
payload-dependent `is_monotone` as an expression over `self`. `could_error`
stays derived, true for the `Result` outputs, matching impls that never
overrode it. `propagates_nulls` was never overridden and derives true from the
non-nullable input.

The casts' `Display` wrote a fixed string, so `sqlname` reproduces it, and the
SQL names differ from the function names. `ExtractDate` formats its payload, so
it keeps its hand-written `Display` under `skip_display = true`.

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

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@antiguru
antiguru force-pushed the sqlfunc-convert-date branch from 27ae985 to add3025 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-date 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