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

   ## What is the purpose of the change
   
   Since FLINK-40996, `PARSE_JSON` and `TRY_PARSE_JSON` share one generated 
parse method. That method called `SqlJsonUtils#parseJsonToVariant`, which built 
the `PARSE_JSON` error on every failure. `TRY_PARSE_JSON` then dropped it and 
returned NULL.
   
   ```sql
   SELECT TRY_PARSE_JSON(j) FROM (VALUES ('not json')) AS t(j)
   ```
   
   | Work per rejected row                          | Before | After  |
   |------------------------------------------------|--------|--------|
   | Parser throws `JsonParseException`             | yes    | yes    |
   | Scan the input for invalid UTF-8               | yes    | no     |
   | Copy the input into the error message          | yes    | no     |
   | Create a `TableRuntimeException` + stack trace | yes    | no     |
   | Result                                         | `NULL` | `NULL` |
   
   `TRY_PARSE_JSON` is meant for input that may not be JSON, so this can hit a 
large share of the rows. Results do not change.
   
   ## Brief change log
   
   - `SqlJsonUtils#parseJsonToVariant` now lets the parser's exception through.
   - New `SqlJsonUtils#parseJsonError(StringData, Throwable)` builds the 
`TableRuntimeException` with the UTF-8 diagnostics.
   - Only a `PARSE_JSON` call site calls it, in place of 
`ExceptionUtils.rethrow`. A `TRY_PARSE_JSON` that shares the parse with a 
`PARSE_JSON` still returns NULL, and the `PARSE_JSON` still fails with `Failed 
to parse JSON string: not json`.
   
   ## Verifying this change
   
   - The `PARSE_JSON` and `TRY_PARSE_JSON` specs in `JsonFunctionsITCase` pass 
unchanged, including `Failed to parse JSON string: Invalid UTF-8 byte at index 
1 of 3.`
   - `JsonParseReuseTest#testParseErrorRethrowForParseJson`: `PARSE_JSON` and 
`TRY_PARSE_JSON` on the same invalid input parse once, build the error at one 
call site, and fail with `Failed to parse JSON string: not json`.
   - New `JsonParseReuseTest#testTryParseJsonDoesNotBuildParseError`: the 
generated code of a query with only `TRY_PARSE_JSON` returns NULL and never 
calls `parseJsonError`.
   
   ## 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): yes. It 
removes work from the failure path of `TRY_PARSE_JSON`.
     - 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? no
     - If yes, how is the feature documented? not applicable
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code 2.1.309 (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