gustavodemorais commented on code in PR #28199:
URL: https://github.com/apache/flink/pull/28199#discussion_r3280410441
##########
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:
It's true, mapArgIncludesKey feels very specific to TO_CHANGELOG. I'll move
these to BuildInFunctionDefinitions.
> we also wouldn't need the or and not construct in the
withConditionalTrait() method because argMatches() checks for arg presence
This we still need though. If the op_mapping is not present, we want to
_add_ the trait, since the default behavior should be adding
REQUIRE_UPDATE_BEFORE and REQUIRE_FULL_DELETES. But I think that's alright, I
think both are good building blocks and the definition reads quite well.
##########
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}.
Review Comment:
done
--
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]