gustavodemorais commented on code in PR #28199:
URL: https://github.com/apache/flink/pull/28199#discussion_r3280424751
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/TraitCondition.java:
##########
@@ -68,4 +74,58 @@ static TraitCondition not(final TraitCondition condition) {
return new BuiltInCondition(
BuiltInCondition.Kind.NOT, List.of(condition), ctx ->
!condition.test(ctx));
}
+
+ /** True when either {@code left} or {@code right} evaluates to true. */
+ static TraitCondition or(final TraitCondition left, final TraitCondition
right) {
+ return new BuiltInCondition(
+ BuiltInCondition.Kind.OR,
+ List.of(left, right),
+ ctx -> left.test(ctx) || right.test(ctx));
+ }
+
+ /** True when the named scalar argument was provided by the caller. */
+ static TraitCondition argIsPresent(final String argName) {
+ return new BuiltInCondition(
+ BuiltInCondition.Kind.ARG_IS_PRESENT,
+ List.of(argName),
+ ctx -> ctx.hasScalarArgument(argName));
+ }
+
+ /**
+ * True when the named scalar argument is present and its value matches
{@code predicate}. False
+ * when the argument is absent or cannot be resolved as a literal of
{@code argClass}.
+ *
+ * <p>Use this for ad-hoc conditions on scalar literals. Prefer the named
factories above when
+ * one fits.
+ */
+ static <X> TraitCondition argMatches(
+ final String argName, final Class<X> argClass, final Predicate<X>
predicate) {
+ return new BuiltInCondition(
+ BuiltInCondition.Kind.ARG_MATCHES,
+ List.of(argName, argClass, predicate),
+ ctx -> ctx.getScalarArgument(argName,
argClass).stream().anyMatch(predicate));
+ }
+
+ /**
+ * True when the named {@code MAP<STRING, STRING>} scalar argument is
present and contains
+ * {@code key} among its keys. False when the argument is absent or cannot
be resolved as a
+ * literal {@link Map}.
+ *
+ * <p>Also matches compound keys: if a key contains commas (e.g. {@code
"INSERT,UPDATE_AFTER"}),
+ * each comma-separated part is trimmed and compared against {@code key} -
useful for mappings
+ * where one entry covers multiple kinds.
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ static TraitCondition mapArgIncludesKey(final String argName, final String
key) {
+ return argMatches(
+ argName, Map.class, map -> mapKeysContain((Map<String,
String>) map, key));
+ }
Review Comment:
Take a look
https://github.com/apache/flink/pull/28199/commits/2e87ebe4c0c144712065725e222c94ca6b3c149c
:)
--
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]