snuyanzin commented on code in PR #29385:
URL: https://github.com/apache/flink/pull/29385#discussion_r4193284762
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/utils/FilterUtils.java:
##########
@@ -154,22 +232,73 @@ private static boolean binaryFilterApplies(
}
}
+ /** Returns NULL for a missing field, an out-of-range index or a container
of the wrong kind. */
+ private static @Nullable Variant getVariantElement(Variant variant, Object
key) {
+ if (key instanceof String) {
+ return variant.isObject() ? variant.getField((String) key) : null;
+ }
+ final int index = ((Number) key).intValue();
+ return variant.isArray() && 1 <= index && index <=
variant.getArraySize()
+ ? variant.getElement(index - 1)
+ : null;
+ }
+
+ private static @Nullable Object cast(
+ @Nullable Object value, LogicalTypeRoot targetType, boolean
tryCast) {
+ if (value == null) {
+ return null;
+ }
+ if (targetType == LogicalTypeRoot.VARCHAR || targetType ==
LogicalTypeRoot.CHAR) {
+ return value.toString();
+ }
+ if (targetType == LogicalTypeRoot.BOOLEAN && value instanceof Boolean)
{
+ return value;
+ }
+ if (value instanceof Number) {
+ final Number number = (Number) value;
+ switch (targetType) {
+ case TINYINT:
+ return number.byteValue();
+ case SMALLINT:
+ return number.shortValue();
+ case INTEGER:
+ return number.intValue();
+ case BIGINT:
+ return number.longValue();
+ case FLOAT:
+ return number.floatValue();
+ case DOUBLE:
+ return number.doubleValue();
+ default:
+ break;
+ }
+ }
Review Comment:
aren't we duplicating this `CAST_TARGETS`?
--
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]