raminqaf commented on code in PR #29311:
URL: https://github.com/apache/flink/pull/29311#discussion_r4152617550
##########
docs/content/docs/sql/reference/data-types.md:
##########
@@ -1677,6 +1678,45 @@ CAST(o AS MAP<STRING, VARIANT>) -- values kept as
variants, the variant null in
CAST(o AS MAP<INT, STRING>) -- fails at validation, a MAP key must be a
character string
```
+A scalar value can also be cast to a `VARIANT` with `CAST` or `TRY_CAST`. Only
a type that a
+`VARIANT` kind holds without loss is supported, and any other type, such as
`INTERVAL`, `RAW`, or
+`BITMAP`, is rejected at validation. The value keeps the kind of its SQL type:
+
+| Input type | Stored `VARIANT` kind
|
+|--------------------------------------------|-------------------------------------------------|
+| `BOOLEAN` | `BOOLEAN`
|
+| `TINYINT`, `SMALLINT`, `INTEGER`, `BIGINT` | `TINYINT`, `SMALLINT`, `INT`,
`BIGINT` |
+| `FLOAT`, `DOUBLE`, `DECIMAL` | `FLOAT`, `DOUBLE`, `DECIMAL`
|
+| `CHAR`, `VARCHAR`, `STRING` | `STRING`
|
+| `BINARY`, `VARBINARY`, `BYTES` | `BYTES`
|
+| `DATE`, `TIME`, `UUID` | `DATE`, `TIME`, `UUID`
|
+| `TIMESTAMP`, `TIMESTAMP_LTZ` | `TIMESTAMP`, `TIMESTAMP_LTZ`
|
+
+- An integer keeps the width of its SQL type, so a `BIGINT` is stored as a
`BIGINT` even when the
+ value would fit a smaller kind. `PARSE_JSON('1')` instead picks the smallest
kind, a `TINYINT`.
+ Either way it casts back to any integer type that holds the value.
+- A character string is stored as a `STRING` and is never parsed. Use
`PARSE_JSON` to parse JSON text.
+- A `TIMESTAMP(p)` or `TIMESTAMP_LTZ(p)` keeps its declared precision. Up to a
precision of 6 it is
+ stored with microseconds, and above with nanoseconds, even when the value
has no digits below a
+ microsecond. Nanoseconds only cover 1677-09-21 to 2262-04-11, so for a
precision above 6 a value
+ outside that range fails the cast, and `TRY_CAST` returns `NULL`.
+- A `NaN` or infinite `FLOAT` or `DOUBLE` is stored as is, although
`PARSE_JSON` rejects them. A
Review Comment:
Agreed. The NaN bullet now says that writing such a value with the `json` or
`raw` format fails the job, as `JSON_STRING` does.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]