Skip to content

sql: Final tweaks to TRY_CAST - #39833

Closed
mgree wants to merge 17 commits into
MaterializeInc:mainfrom
mgree:trycast
Closed

mgree wants to merge 17 commits into
MaterializeInc:mainfrom
mgree:trycast

Conversation

@mgree

@mgree mgree commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

This PR adds some tiny tweaks that were accidentally left out of #38845.

@mgree
mgree requested review from a team as code owners October 14, 2026 17:55
mgree and others added 17 commits October 14, 2026 13:55
- Document that a parameter typed by TRY_CAST is decoded as the target
  type at bind time, and how to get NULL instead.
- Soft-panic when TryCast would swallow an EvalError::Internal, so a
  planner bug stays visible in CI while production still yields NULL.
- Reword the refused-cast error to say the cast exists and CAST
  supports it.
- Enable enable_try_cast by default and mark TRY_CAST as added in
  v26.45.
- Rewrite the docs' list of differences from CAST: catalog-lookup casts,
  constructors typed on their own, and the MAP constructor rejection as
  a consequence of that.
- Pin that an infallible TRY_CAST stays unwrapped and NOT NULL, and
  stop using UnaryFunc::try_cast as the coverage test's own oracle.
- After rebasing onto the "char" cast fix, thread the failure mode
  through its cast lookup, regenerate the "char" matrix rows, and lift
  the property test's "char" exclusion.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- Keep the type hint for empty ARRAY, LIST, and MAP constructors under
  TRY_CAST, which have no element casts to protect. Only a non-empty
  MAP constructor is still rejected.
- Make TryCast's inner function private, with
  UnaryFunc::try_cast_if_fallible as the only constructor, so a wrapper
  always holds a fallible function and is always nullable.
- Use the parser's CastFailureMode throughout and drop the mz_expr copy.
- Document the chain shape a cast template needs for TRY_CAST.
- Pin how TRY_CAST plans with EXPLAIN over columns: a single fallible
  stage, an infallible cast, multi-stage chains, and the optimized plan.
- Move the adapter's TRY_CAST tests into catalog/try_cast_tests.rs.
- Put the refused-cast remedy in a hint, and log a swallowed internal
  error in production instead of staying silent.
- Mark TRY_CAST as added in v26.46, and drop SqlScalarType::contains,
  whose only caller was the "char" exclusion the property test no
  longer needs.

Co-Authored-By: Claude Fable 5.1 <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