raminqaf opened a new pull request, #29118:
URL: https://github.com/apache/flink/pull/29118

   ## What is the purpose of the change
   
   This pull request adds `CAST` and `TRY_CAST` from `VARIANT` to `MAP<STRING, 
V>`. It is the last of the stacked constructed-cast PRs and builds on the same 
design: `ARRAY` (merged), `ROW`/`STRUCTURED` (#29092), and now `MAP`. It is 
stacked on #29092 and should be reviewed and merged after it.
   
   `MAP` is the schemaless read of an object: unlike `ROW`, no field is named 
in advance, so it is the way to read an object whose keys are dynamic or 
unknown at query time.
   
   Key semantics:
   - The variant must be an object. Each field name becomes a key and each 
value casts to `V` by the same `VARIANT`-to-value rules, recursively.
   - The key type must be a character string, since a variant object's keys are 
always strings. A non-string key type is rejected at validation.
   - A value present but set to a variant null maps to SQL `NULL` when `V` is 
nullable and fails the cast when `V` is `NOT NULL`. An empty object casts to an 
empty map.
   - A `MAP<STRING, VARIANT>` value type is the identity, so a variant null is 
kept as a variant null rather than downgraded to SQL `NULL`. This matches 
`ARRAY<VARIANT>` and a `ROW` with `VARIANT` fields.
   - Leaves are never parsed, and `TRY_CAST` returns `NULL` for the entire 
value on any failure.
   
   ## Brief change log
   
   - Add `VariantToMapCastRule` that casts a variant object to `MAP<STRING, 
V>`, mapping field names to keys and casting each value with the existing 
VARIANT-to-value rules.
   - Allow the explicit cast in `LogicalTypeCasts` when the key is a character 
string and `VARIANT` casts to the value type.
   - Document the VARIANT to `MAP` cast and mark `VARIANT` → `MAP` in the 
cast-support matrix.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   - `CastRulesTest`: key/value mapping, an empty object, a non-object input, 
and `MAP<STRING, VARIANT>` with and without a variant null value.
   - `CastFunctionITCase`: end-to-end SQL and Table API cases (the Table API 
cases use the `parseJson()` expression method).
   - `LogicalTypeCastsTest` and `CastRuleProviderTest`: castability and rule 
resolution, including the non-string-key rejection.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? docs
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change the checkbox below to `[X]` and replace the placeholder in the 
"Generated-by"
   line with the tool name and version. Otherwise remove the "Generated-by" 
line.
   See the ASF Generative Tooling Guidance for details:
   https://www.apache.org/legal/generative-tooling.html
   
   You are responsible for the quality and correctness of every change in this 
PR
   regardless of the tooling used. Low-effort AI-generated PRs will be closed. 
See
   AGENTS.md for the full guidance.
   -->
   
   - [ ] Yes (please specify the tool below)
   
   Generated-by: [Tool Name and Version]
   


-- 
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]

Reply via email to