JinkunLiu commented on code in PR #27330:
URL: https://github.com/apache/flink/pull/27330#discussion_r2605242708
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/ItemAtIndexArgumentTypeStrategy.java:
##########
@@ -86,12 +89,36 @@ public Optional<DataType> inferArgumentType(
}
}
+ if (collectionType.is(LogicalTypeRoot.VARIANT)) {
+ if
(indexType.getLogicalType().is(LogicalTypeFamily.INTEGER_NUMERIC)) {
+
+ if (callContext.isArgumentLiteral(1)) {
+ Optional<Integer> literalVal =
callContext.getArgumentValue(1, Integer.class);
+ if (literalVal.isPresent() && literalVal.get() <= 0) {
+ return callContext.fail(
+ throwOnFailure,
+ "The provided index must be a valid SQL index
starting from 1, but was '%s'",
+ literalVal.get());
+ }
+ }
+
+ return Optional.of(indexType);
+ } else if
(indexType.getLogicalType().is(LogicalTypeFamily.CHARACTER_STRING)) {
+ return Optional.of(indexType);
+ } else {
+ return callContext.fail(
+ throwOnFailure,
+ "Variant values can only be accessed with a CHARACTER
STRING key or indexed with an INTEGER NUMERIC index.");
+ }
+ }
+
return Optional.empty();
}
@Override
public Signature.Argument getExpectedArgument(
FunctionDefinition functionDefinition, int argumentPos) {
- return Signature.Argument.of("[<INTEGER NUMERIC> | <MAP_KEY_TYPE>]");
+ return Signature.Argument.of(
+ "[<INTEGER NUMERIC> | <MAP_KEY_TYPE> | <CHARACTER STRING> or
<INTEGER NUMERIC>]");
Review Comment:
My original intent was to clearly illustrate the one-to-one correspondence
between logical root types and their allowed index/key argument types, for
example:
- `LogicalTypeRoot.ARRAY` → `<INTEGER NUMERIC>`
- `LogicalTypeRoot.MAP` → `<MAP_KEY_TYPE>`
- `LogicalTypeRoot.VARIANT` → `<CHARACTER STRING>` or `<INTEGER
NUMERIC>`
The expected function signatures in old code are:
```
at([<ARRAY> | <MAP> | <VARIANT>], [<INTEGER NUMERIC> | <MAP_KEY_TYPE> |
<CHARACTER STRING> or <INTEGER NUMERIC>])
```
However, I have realized that this mapping is already effectively conveyed
through the error messages generated by `inferArgumentType()`. I have updated
the implementation to reflect this.
Thanks for your reminder!
--
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]