twalthr commented on code in PR #26396:
URL: https://github.com/apache/flink/pull/26396#discussion_r2028257636
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/ProcessTableFunctionTestUtils.java:
##########
@@ -605,6 +614,80 @@ public void eval(
}
}
+ /** Testing function. */
+ public static class ListStateFunction extends TestProcessTableFunctionBase
{
+ public void eval(
+ Context ctx,
+ @StateHint ListView<String> s,
+ @ArgumentHint({TABLE_AS_SET, OPTIONAL_PARTITION_BY}) Row r)
+ throws Exception {
+ collectObjects(s.getList(), s.getClass().getSimpleName(), r);
+
+ // get
+ int count = s.getList().size();
+
+ // create
+ s.add(String.valueOf(count));
+
+ // null behavior
+ assertThatThrownBy(() -> s.add(null))
+ .isInstanceOf(TableRuntimeException.class)
+ .hasMessageContaining("List views don't support null
values.");
+ assertThatThrownBy(() -> s.addAll(Arrays.asList("item0", null)))
+ .isInstanceOf(TableRuntimeException.class)
+ .hasMessageContaining("List views don't support null
values.");
+
+ // clear
+ if (count == 2) {
+ ctx.clearState("s");
+ }
+ }
+ }
+
+ /** Testing function. */
+ public static class MapStateFunction extends TestProcessTableFunctionBase {
+ public void eval(
+ Context ctx,
+ @StateHint MapView<String, Integer> s,
+ @ArgumentHint({TABLE_AS_SET, OPTIONAL_PARTITION_BY}) Row r)
+ throws Exception {
+ final String viewToString =
+ s.getMap().entrySet().stream()
+ .map(Objects::toString)
+ .sorted()
+ .collect(Collectors.joining(", ", "{", "}"));
+ collectObjects(viewToString, s.getClass().getSimpleName(), r);
+
+ // get
+ final String name = r.getFieldAs("name");
+ int count = 1;
+ if (s.contains(name)) {
+ count = s.get(name);
+ }
+
+ // create
+ s.put("old" + name, count);
+ s.put(name, count + 1);
+
+ // null behavior
+ assertThatThrownBy(() -> s.put(null, 42))
+ .isInstanceOf(TableRuntimeException.class)
+ .hasMessageContaining("Map views don't support null
keys.");
+ final Map<String, Integer> mapWithNull = new HashMap<>();
+ mapWithNull.put("key", 42);
+ mapWithNull.put(null, 42);
+ assertThatThrownBy(() -> s.putAll(mapWithNull))
Review Comment:
`Map.of` doesn't support null values.
--
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]