raminqaf commented on code in PR #29073:
URL: https://github.com/apache/flink/pull/29073#discussion_r3924799242
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java:
##########
@@ -379,6 +384,116 @@ private static List<TestSetSpec> variantCasts() {
TINYINT()));
}
+ private static List<TestSetSpec> variantArrayCasts() {
+ return List.of(
+ TestSetSpec.forExpression("Cast a VARIANT produced by
PARSE_JSON to an ARRAY")
+ .onFieldsWithData("unused")
+ .andDataTypes(STRING())
+ // ARRAY: each element casts by the same
VARIANT-to-element rule.
+ .testResult(
+ call("PARSE_JSON", "[1, 2,
3]").cast(ARRAY(INT())),
+ "CAST(PARSE_JSON('[1, 2, 3]') AS ARRAY<INT>)",
+ new Integer[] {1, 2, 3},
+ ARRAY(INT()).notNull())
+ // an approximate leaf takes any numeric kind
+ .testResult(
+ call("PARSE_JSON", "[1, 2,
3]").cast(ARRAY(DOUBLE())),
+ "CAST(PARSE_JSON('[1, 2, 3]') AS
ARRAY<DOUBLE>)",
+ new Double[] {1.0, 2.0, 3.0},
+ ARRAY(DOUBLE()).notNull())
+ // each element renders to string like the scalar cast
+ .testResult(
+ call("PARSE_JSON", "[1, 2,
3]").cast(ARRAY(STRING())),
+ "CAST(PARSE_JSON('[1, 2, 3]') AS
ARRAY<STRING>)",
+ new String[] {"1", "2", "3"},
+ ARRAY(STRING()).notNull())
+ // a heterogeneous array renders every element to
string
+ .testResult(
+ call("PARSE_JSON", "[1, \"a\", 2,
\"b\"]").cast(ARRAY(STRING())),
+ "CAST(PARSE_JSON('[1, \"a\", 2, \"b\"]') AS
ARRAY<STRING>)",
+ new String[] {"1", "a", "2", "b"},
+ ARRAY(STRING()).notNull())
+ .testResult(
+ call("PARSE_JSON", "[]").cast(ARRAY(INT())),
+ "CAST(PARSE_JSON('[]') AS ARRAY<INT>)",
+ new Integer[] {},
+ ARRAY(INT()).notNull())
+ // a JSON null element maps to SQL NULL for a nullable
element type
+ .testResult(
+ call("PARSE_JSON", "[1, null,
3]").cast(ARRAY(INT())),
+ "CAST(PARSE_JSON('[1, null, 3]') AS
ARRAY<INT>)",
+ new Integer[] {1, null, 3},
+ ARRAY(INT()).notNull())
+ // a JSON null element fails a NOT NULL element type
+ .testTableApiRuntimeError(
+ call("PARSE_JSON", "[1, null,
3]").cast(ARRAY(INT().notNull())),
Review Comment:
there's no dedicated Table API `parseJson()` — `PARSE_JSON` exists only as
`BuiltInFunctionDefinitions.PARSE_JSON`, invoked via `call()`. So `call()`
can't be avoided
--
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]