Skip to content

Add support for cast between NUMBER and JSON#28868

Merged
findepi merged 1 commit into
trinodb:masterfrom
findepi:findepi/number-json-cast
Apr 1, 2026
Merged

Add support for cast between NUMBER and JSON#28868
findepi merged 1 commit into
trinodb:masterfrom
findepi:findepi/number-json-cast

Conversation

@findepi
Copy link
Copy Markdown
Member

@findepi findepi commented Mar 25, 2026

Implements cast operators to convert between NUMBER and JSON types,
following the same pattern as existing DECIMAL-JSON casts.

NUMBER to JSON conversion:

  • Regular numbers are converted to JSON numbers
  • NaN, +Infinity, -Infinity are converted to JSON strings

JSON to NUMBER conversion:

  • JSON numbers (integer and float) are converted to NUMBER
  • JSON booleans are converted to 1 (true) or 0 (false)
  • JSON strings containing numbers or special values (NaN, Infinity) are parsed
  • JSON null is converted to SQL NULL

release notes

General
* Support cast from/to NUMBER and JSON (#28394)

@cla-bot cla-bot Bot added the cla-signed label Mar 25, 2026
@findepi findepi force-pushed the findepi/number-json-cast branch from 9cd8412 to d1484a2 Compare March 25, 2026 23:15
@gertjanal
Copy link
Copy Markdown
Contributor

gertjanal commented Mar 26, 2026

Looks ok to me 👍

@findepi
Copy link
Copy Markdown
Member Author

findepi commented Mar 26, 2026

@findepi
Copy link
Copy Markdown
Member Author

findepi commented Mar 26, 2026

@wendigo why did you add syntax-needs-review?
Anything specifically raises your concern?
This follows same route as other numeric casts from/to JSON, and fixes some (hopefully) obvious bugs.

@wendigo
Copy link
Copy Markdown
Contributor

wendigo commented Mar 26, 2026

@findepi last time I've merged varbinary to json conversions and @martint objected that it required syntax review. Here we have a similar situation

@findepi findepi force-pushed the findepi/number-json-cast branch from 09a7d57 to b1a308f Compare March 26, 2026 11:26
@findepi findepi requested review from losipiuk, martint and wendigo and removed request for losipiuk, martint and wendigo March 26, 2026 11:27
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Mar 26, 2026

@findepi findepi marked this pull request as draft March 26, 2026 11:40
@findepi findepi force-pushed the findepi/number-json-cast branch from b1a308f to 6e9b11a Compare March 30, 2026 09:12
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Mar 30, 2026

@findepi findepi force-pushed the findepi/number-json-cast branch from 6e9b11a to da0570b Compare March 30, 2026 09:27
@findepi findepi marked this pull request as ready for review March 30, 2026 09:27
Comment thread core/trino-main/src/main/java/io/trino/util/JsonUtil.java Outdated
@martint
Copy link
Copy Markdown
Member

martint commented Mar 31, 2026

Syntax is good. It's consistent with what we do for other numeric conversions.

@findepi findepi force-pushed the findepi/number-json-cast branch from da0570b to 45ec3ba Compare April 1, 2026 15:05
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Apr 1, 2026

( rebased, no other changes (yet) )

Implements cast operators to convert between NUMBER and JSON types,
following the same pattern as existing DECIMAL-JSON casts.

NUMBER to JSON conversion:
- Regular numbers are converted to JSON numbers
- NaN, +Infinity, -Infinity are converted to JSON strings

JSON to NUMBER conversion:
- JSON numbers (integer and float) are converted to NUMBER
- JSON booleans are converted to 1 (true) or 0 (false)
- JSON strings containing numbers or special values (NaN, Infinity) are parsed
- JSON null is converted to SQL NULL
@findepi findepi force-pushed the findepi/number-json-cast branch from 45ec3ba to 91baeb8 Compare April 1, 2026 15:16
@findepi findepi merged commit d95a9fe into trinodb:master Apr 1, 2026
98 checks passed
@findepi findepi deleted the findepi/number-json-cast branch April 1, 2026 18:17
@github-actions github-actions Bot added this to the 481 milestone Apr 1, 2026
@ebyhr ebyhr mentioned this pull request Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

7 participants