[
https://issues.apache.org/jira/browse/FLINK-39049?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18095850#comment-18095850
]
Ramin Gharib edited comment on FLINK-39049 at 7/13/26 10:30 AM:
----------------------------------------------------------------
[~jkk123] ({{{}VARIANT_GET / TRY_VARIANT_GET{}}}) is a convenience wrapper, not
a capability. It combines path navigation and a typed cast into one
JSONPath-string function. We already have native dot/bracket/array navigation,
and typed extraction is delivered by {{CAST/TRY_CAST}} from {{{}VARIANT{}}}.
{{VARIANT_GET(v, '$.a.b', RETURNING INT)}} is exactly {{{}CAST(v.a.b AS
INT){}}}. So {{VARIANT_GET}} adds no capability we don't get from navigation +
{{{}CAST{}}}, and we should drop it from scope. Revisit only if a customer
explicitly needs Snowflake GET/JSONPath-string compatibility.
However, I see the benefit of {{TRY_VARIANT_GET }}in case the path does not
exists we return a NULL instead of an error. This behavior cannot be mirrored
with a simple CAST/TRY_CAST
I would suggest that we keep this ticket and reduce the priority of it to
Minor. I am currently working on the {{CAST/TRY_CAST}} functionality of the
VARIANT type. See FLINK-37925, FLINK-37926
cc [~twalthr] [~sxnan] [~rayokota]
was (Author: JIRAUSER304722):
[~jkk123] ({{{}VARIANT_GET / TRY_VARIANT_GET{}}}) is a convenience wrapper, not
a capability. It combines path navigation and a typed cast into one
JSONPath-string function. We already have native dot/bracket/array navigation,
and typed extraction is delivered by {{CAST/TRY_CAST}} from {{{}VARIANT{}}}.
{{VARIANT_GET(v, '$.a.b', RETURNING INT)}} is exactly {{{}CAST(v.a.b AS
INT){}}}. So {{VARIANT_GET}} adds no capability we don't get from navigation +
{{{}CAST{}}}, and we should drop it from scope. Revisit only if a customer
explicitly needs Snowflake GET/JSONPath-string compatibility.
I would suggest that we keep this ticket and reduce the priority of it to
Minor. I am currently working on the {{CAST/TRY_CAST}} functionality of the
VARIANT type. See FLINK-37925, FLINK-37926
cc [~twalthr] [~sxnan] [~rayokota]
> Introduce built-in functions `VARIANT_GET` and `TRY_VARIANT_GET ` to extract
> values from a variant
> --------------------------------------------------------------------------------------------------
>
> Key: FLINK-39049
> URL: https://issues.apache.org/jira/browse/FLINK-39049
> Project: Flink
> Issue Type: Sub-task
> Components: Table SQL / API
> Reporter: Jinkun Liu
> Assignee: Jinkun Liu
> Priority: Major
>
> ||SQL Function||Table Function||Description||
> |VARIANT_GET(variant, path RETURNING)|VARIANT.variantGet(variant, path,
> returnType])|Extracts a sub-value from a Variant using the specified path and
> casts it to the target type.
>
> If the path does not exist or is invalid, this function returns {{{}NULL{}}}.
> If the target return type is incompatible with the extracted value, this
> function throws an error.
>
> {{```sql}}
> {{-- TRUE}}
> {{VARIANT_GET(PARSE_JSON('\{"a": true}'), '$.a' RETURNING BOOLEAN)}}
>
> –- NULL
> {{VARIANT_GET(PARSE_JSON('\{"a": true}'), '$.b' RETURNING INT)}}
>
> {{-- throws: cannot cast VARIANT(STRING) to INT}}
> {{VARIANT_GET(PARSE_JSON('\{"a": "oops"}'), '$.a' RETURNING INT)}}
> {{```}}|
> |TRY_VARIANT_GET(variant, path RETURNING)|VARIANT.tryVariantGet(variant,
> path, returnType])|Similar to {{{}VARIANT_GET{}}}, but returns {{NULL}}
> instead of throwing an error when the extracted value cannot be cast to the
> target return type.
>
> If the path does not exist or is invalid, this function also returns
> {{{}NULL{}}}.|
> *reference:*
> [https://downloads.apache.org/spark/docs/4.2.0-preview3/api/sql/variant-functions/#try_variant_get]
> [https://docs.snowflake.com/en/sql-reference/functions/get]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)