Skip to content

expr: Convert CastUint16ToNumeric to the sqlfunc macro - #39084

Closed
antiguru wants to merge 1 commit into
sqlfunc-convert-int64from
sqlfunc-convert-uint16
Closed

antiguru wants to merge 1 commit into
sqlfunc-convert-int64from
sqlfunc-convert-uint16

Conversation

@antiguru

@antiguru antiguru commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Converts CastUint16ToNumeric to #[sqlfunc]. It carries an optional NumericMaxScale, so the function takes &self and builds its output type in an output_type_expr. sqlname keeps the SQL name uint2_to_numeric. could_error stays self.0.is_some(), which a Result output would otherwise widen to true.

The registry reports only the macro provenance fields moving, on both records. No declared property changed.

Based on #39083.

🤖 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-int64 branch from 357c809 to a577d40 Compare September 24, 2026 10:14
@antiguru
antiguru force-pushed the sqlfunc-convert-uint16 branch from 0f3bb92 to 205a9c1 Compare September 24, 2026 10:14
@antiguru
antiguru requested a review from petrosagg September 24, 2026 11:17
@antiguru
antiguru force-pushed the sqlfunc-convert-uint16 branch from 205a9c1 to dbb1da2 Compare September 24, 2026 14:29
@antiguru
antiguru force-pushed the sqlfunc-convert-int64 branch from 17c5201 to dd04ef6 Compare September 25, 2026 16:00
@antiguru
antiguru force-pushed the sqlfunc-convert-uint16 branch from dbb1da2 to 4e9b249 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-int64 branch from dd04ef6 to de477b0 Compare October 14, 2026 09:11
@antiguru
antiguru force-pushed the sqlfunc-convert-uint16 branch from 4e9b249 to 0f6b03a Compare October 14, 2026 09:11
@antiguru
antiguru requested a review from mgree October 14, 2026 10:22
`CastUint16ToNumeric` carries an optional `NumericMaxScale`, so the annotated
function takes a `&self` receiver and the macro generates `call` as a method on
the existing struct instead of defining a unit struct. The hand-written
`Display` wrote the fixed string `uint2_to_numeric` without reading the payload,
so `sqlname` reproduces it and the impl is deleted. The macro then generates
`FuncName` with `NAME` from the annotated function's name, which is the
`"cast_uint16_to_numeric"` the manual `func_name!` entry declared, so that entry
is deleted to avoid a duplicate impl.

Every method the deleted `EagerUnaryFunc` impl overrode is accounted for:

* `call`: the annotated function's body, unchanged.
* `output_sql_type`: expressed as `output_type_expr`, which reads `self.0` and
  the `input_type` binding. The generated tail ORs in `propagates_nulls &&
  input_type.nullable`, and `propagates_nulls` derives to `true` from the
  non-nullable `u16` input, so the result is the same
  `nullable(input_type.nullable)` the deleted body returned.
* `could_error`: carried across as `self.0.is_some()`. The derived default reads
  the `Result` output and would widen it to an unconditional `true`.
* `inverse`: carried across.
* `is_monotone`: carried across.

`introduces_nulls` is not overridden: `Result<Numeric, EvalError>` derives
`false`, which is what the impl inherited. `propagates_nulls` and
`preserves_uniqueness` were not overridden and keep deriving as before.

The registry reports only `sqlfunc_signature` moving, on both the unscaled and
the scaled `cast_uint16_to_numeric` record. No declared property changed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@antiguru
antiguru force-pushed the sqlfunc-convert-int64 branch from de477b0 to 3cc5192 Compare October 14, 2026 15:18
@antiguru
antiguru force-pushed the sqlfunc-convert-uint16 branch from 0f6b03a to 662661d 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-uint16 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