dawidwys commented on a change in pull request #10312:
[FLINK-12996][table-common] Add type validators and strategies for FLIP-65
URL: https://github.com/apache/flink/pull/10312#discussion_r350131453
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeValidators.java
##########
@@ -34,6 +48,97 @@
*/
public static final InputTypeValidator PASSING = new
PassingTypeValidator();
+ /**
+ * Validator that checks for a single argument that can be of any type.
+ */
+ public static final SingleInputTypeValidator ANY = new
AnyTypeValidator();
+
+ /**
+ * Validator that checks if a single argument is a literal.
+ */
+ public static final SingleInputTypeValidator LITERAL = new
LiteralTypeValidator(false);
+
+ /**
+ * Validator that checks if a single argument is a literal or null.
+ */
+ public static final SingleInputTypeValidator LITERAL_OR_NULL = new
LiteralTypeValidator(true);
+
+ /**
+ * Validator that checks if each operand corresponds to an explicitly
defined logical type.
+ *
+ * <p>Note: The validation happens on {@link LogicalType} level only.
+ */
+ public static SingleInputTypeValidator explicit(DataType...
expectedDataTypes) {
+ final List<LogicalType> expectedTypes =
Arrays.stream(expectedDataTypes)
+ .map(DataType::getLogicalType)
+ .collect(Collectors.toList());
+ return new ExplicitTypeValidator(expectedTypes);
+ }
+
+ /**
+ * Conjunction of multiple {@link SingleInputTypeValidator}s into one
like {@code f(NUMERIC && LITERAL)}.
+ */
+ public static SingleInputTypeValidator and(SingleInputTypeValidator...
validators) {
+ return new CompositeTypeValidator(Composition.AND,
Arrays.asList(validators), null);
+ }
+
+ /**
+ * Conjunction of multiple {@link InputTypeValidator}s into one like
{@code f(NUMERIC) && f(LITERAL)}.
+ */
+ public static InputTypeValidator and(InputTypeValidator... validators) {
+ return new CompositeTypeValidator(Composition.AND,
Arrays.asList(validators), null);
+ }
+
+ /**
+ * Conjunction of multiple {@link SingleInputTypeValidator}s into one
like {@code f(NUMERIC || STRING)}.
+ */
+ public static SingleInputTypeValidator or(SingleInputTypeValidator...
validators) {
+ return new CompositeTypeValidator(Composition.OR,
Arrays.asList(validators), null);
+ }
+
+ /**
+ * Conjunction of multiple {@link InputTypeValidator}s into one like
{@code f(NUMERIC) || f(STRING)}.
+ */
+ public static InputTypeValidator or(InputTypeValidator... validators) {
+ return new CompositeTypeValidator(Composition.OR,
Arrays.asList(validators), null);
+ }
+
+ /**
+ * A sequence of {@link SingleInputTypeValidator}s for validating an
entire function signature
+ * like {@code f(STRING, NUMERIC)}.
+ */
+ public static InputTypeValidator sequence(SingleInputTypeValidator...
validators) {
+ return new CompositeTypeValidator(Composition.SEQUENCE,
Arrays.asList(validators), null);
+ }
+
+ /**
+ * A sequence of {@link SingleInputTypeValidator}s for validating an
entire named function signature
+ * like {@code f(s STRING, n NUMERIC)}.
+ */
+ public static InputTypeValidator sequence(String[] argumentNames,
SingleInputTypeValidator[] validators) {
+ return new CompositeTypeValidator(Composition.SEQUENCE,
Arrays.asList(validators), Arrays.asList(argumentNames));
+ }
+
+ /**
+ * A varying sequence of {@link SingleInputTypeValidator}s for
validating an entire function signature
+ * like {@code f(INT, STRING, NUMERIC...)}. The first n - 1 arguments
must be constant and are validated
+ * according to {@link #sequence(String[],
SingleInputTypeValidator[])}. The n-th argument can
Review comment:
```suggestion
* according to {@link #sequence(SingleInputTypeValidator[])}. The n-th
argument can
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services