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

   ## What is the purpose of the change
   
   Adds four FLIP-618 functions that read a `VARIANT` without changing it.
   
   ```sql
   -- v = PARSE_JSON('{"order_id": 17, "user": {"name": "ada"}, "items": 
[{"qty": 2}], "coupon": null}')
   ```
   
   | Call                                                | Result               
             |
   
|-----------------------------------------------------|-----------------------------------|
   | `IS_VARIANT_NULL(v['coupon'])`                      | `TRUE`               
             |
   | `IS_VARIANT_NULL(v['discount'])`                    | `NULL`               
             |
   | `VARIANT_TYPE(v['order_id'])`                       | `'TINYINT'`          
             |
   | `VARIANT_TYPE(CAST(CAST(17 AS BIGINT) AS VARIANT))` | `'BIGINT'`           
             |
   | `VARIANT_KEYS(v)`                                   | `[coupon, items, 
order_id, user]` |
   | `VARIANT_EXISTS(v, '$.coupon')`                     | `TRUE`               
             |
   | `VARIANT_EXISTS(v, '$.items[1]')`                   | `FALSE`              
             |
   
   The decisions beyond the FLIP text:
   
   - All four return NULL for a SQL NULL, also `IS_VARIANT_NULL`, as the FLIP's 
open question settles. Spark's `is_variant_null` returns FALSE there.
   - `VARIANT_TYPE` names the stored type, so an integer keeps its size. 
`SCHEMA_OF_VARIANT` (#30229) shows `BIGINT` for every integer instead.
   - `VARIANT_KEYS` returns `ARRAY<STRING NOT NULL>` in the order the object 
stores its keys, without sorting again. A valid value stores them by UTF-8 
bytes. Values that Flink 2.1 to 2.3 wrote keep their UTF-16 order, which the 
docs page names.
   - `VARIANT_KEYS` decodes the keys through `Variant#getFieldNames`, as a cast 
to `MAP` does. Copying the UTF-8 key bytes was about 1.4x faster in a nanoTime 
loop on JDK 17 (5 keys: 129 vs 90 ns per row, 100 keys: 2.64 vs 1.77 µs), but 
it could put invalid UTF-8 into a `STRING`. The casts from `VARIANT` never do 
that: a string decodes invalid bytes to U+FFFD, and a binary value with invalid 
UTF-8 fails.
   - `VARIANT_EXISTS` takes the paths of `VARIANT_GET`: a malformed literal 
fails at planning time, and a malformed path from a column fails the job.
   - `IS_VARIANT_NULL` and `VARIANT_TYPE` fail the job on a value whose type 
can't be read, such as a type id from a later spec, as a cast does.
   
   The first commit moves the path handling of `VARIANT_GET` into 
`VariantPathArgument` and `VariantPathInputTypeStrategy`, so `VARIANT_EXISTS` 
and the later FLIP-618 path functions share it. Its cache for a path that isn't 
a literal now compares bytes, where it decoded the path on every row before. 
Then each function has its own commit, and every commit builds and passes the 
tests on its own.
   
   This PR and #30229 change the same files, such as 
`BuiltInFunctionDefinitions` and `VariantFunctionsITCase`, so whichever lands 
second needs a rebase.
   
   ## Brief change log
   
   - `VariantPathArgument` and `VariantPathInputTypeStrategy`, shared by 
`VARIANT_GET`, `TRY_VARIANT_GET` and `VARIANT_EXISTS`.
   - `IS_VARIANT_NULL`, `VARIANT_TYPE`, `VARIANT_KEYS` and `VARIANT_EXISTS` 
definitions with their runtime classes.
   - Table API `isVariantNull()`, `variantType()`, `variantKeys()`, 
`variantExists(path)` and the PyFlink methods.
   - A docs page per function, and the "VARIANT Paths" page names 
`VARIANT_EXISTS`.
   
   ## Verifying this change
   
   - `VariantFunctionsITCase`: SQL and Table API results for each function, 
NULL inputs, a path from a column, the job failure for a malformed path from a 
column, and the failure for a value of an unknown type.
   - `VariantPathInputTypeStrategyTest`: the signature, literal, non-literal 
and NULL paths, and the error for a malformed literal path.
   - `ExpressionSerializationTest` and `test_expression.py` for the Table API 
and PyFlink calls.
   - The existing `VariantFunctionsITCase` cases for `VARIANT_GET` and 
`VariantSemanticTest`, which reads a path that changes from row to row, cover 
the moved path handling.
   
   ## 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)`: yes, four new methods in `BaseExpressions`
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): yes, 
`VARIANT_GET` now checks its path cache by comparing bytes. Otherwise only the 
new functions
     - 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, a page for each function
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code 2.1.336 (Claude Opus 5.5)
   


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