Ramin Gharib created FLINK-41301:
------------------------------------
Summary: Throw TableRuntimeException for every failed cast from
VARIANT
Key: FLINK-41301
URL: https://issues.apache.org/jira/browse/FLINK-41301
Project: Flink
Issue Type: Improvement
Components: Table SQL / Runtime
Reporter: Ramin Gharib
h3. Problem
A failed cast from {{VARIANT}} throws a different exception type depending on
the target. For most targets, {{FromVariantConverter}} throws a
{{TableRuntimeException}} built by {{VariantCastUtils.unsupportedKind}}. The
{{BOOLEAN}}, {{DATE}}, {{BINARY}} and {{VARBINARY}} readers call the strict
{{Variant}} getters instead, which throw a {{VariantTypeException}} with the
getter's own message. A malformed variant escapes
{{FromVariantConverter#convert}} the same way. The Javadoc of {{convert}}
documents both.
||Query||Exception||Message||
|{{CAST(PARSE_JSON('"abc"') AS INT)}}|{{TableRuntimeException}}|{{Cannot cast a
VARIANT STRING value to INTEGER. ...}}|
|{{CAST(PARSE_JSON('"abc"') AS BOOLEAN)}}|{{VariantTypeException}}|{{Expected
type BOOLEAN but got STRING}}|
{{BYTES}} and {{DATE}} fail like {{BOOLEAN}}, because {{getBytes}} and
{{getDate}} check the type the same way. The {{VariantTypeException}} message
names neither the cast nor the target SQL type, and its type differs from every
other failed cast from {{VARIANT}}. {{TRY_CAST}} is not affected, because it
catches any {{Throwable}}.
h3. Proposal
* Have the {{BOOLEAN}}, {{DATE}} and binary readers check the kind and throw
{{unsupportedKind}}, like every other reader.
* In {{FromVariantConverter#convert}}, wrap a {{VariantTypeException}} that
still escapes a reader, such as for a malformed variant, in a
{{TableRuntimeException}}. {{ToVariantConverter}} already does this for the
other direction.
* Update the Javadoc of {{convert}}.
FLINK-40319 and FLINK-41281 would let some of these kinds reach the target. The
kinds that remain still need the error.
h3. Tests
* A cast to {{BOOLEAN}}, {{DATE}}, {{BINARY}} and {{VARBINARY}} from a kind the
target doesn't accept fails with a {{TableRuntimeException}} and the
{{unsupportedKind}} message.
* A malformed variant fails with a {{TableRuntimeException}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)