bojana-db opened a new pull request, #60089: URL: https://github.com/apache/spark/pull/60089
### What changes were proposed in this pull request? `VariantExpressionEvalUtils.castToVariant` builds the variant for `CAST(x AS VARIANT)` and `to_variant_object`, but unlike `parse_json` and the variant mutation functions it did not translate the internal `VariantSizeLimitException` thrown by `VariantBuilder` when the result exceeds the variant size limit. This PR: - adds a `castToVariant(input, dataType, functionName)` overload that catches `VariantSizeLimitException` and raises `VARIANT_SIZE_LIMIT` naming the calling function; the existing two-argument form delegates to it with `cast`; - routes `to_variant_object` (interpreted and codegen paths) through it with its own name; - passes the function name through from `variant_insert`, `variant_set`, and `variant_array_append`, so an overflow while casting their value argument reports the right function. ### Why are the changes needed? `VariantSizeLimitException` is a plain `RuntimeException` with no error class or message, so users hit an opaque failure with no explanation or SQLSTATE. The same condition is already reported as `VARIANT_SIZE_LIMIT` by `parse_json`, `variant_set`, `variant_insert`, and `variant_array_append`; the cast path should be consistent. ### Does this PR introduce _any_ user-facing change? Yes. Casting a value whose variant encoding exceeds the size limit now fails with ``` [VARIANT_SIZE_LIMIT] Cannot build variant bigger than 16.0 MiB in `cast`. ... ``` (or `to_variant_object`) instead of an unclassified `org.apache.spark.types.variant.VariantSizeLimitException`. Successful casts are unchanged. ### How was this patch tested? Added checks to the existing `cast to variant/to_variant_object` test in `VariantExpressionSuite` that cast a 16 MiB string, directly and inside an array via `to_variant_object`, and assert the error class and function name in both codegen and interpreted modes. `VariantExpressionSuite` and `VariantExpressionEvalUtilsSuite` pass locally, and `sql/core` test code compiles against the new signature. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Fable 5.1) This pull request and its description were written by Isaac. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
