matriv commented on a change in pull request #17341:
URL: https://github.com/apache/flink/pull/17341#discussion_r717367218
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/BuiltInFunctionTestBase.java
##########
@@ -261,6 +248,14 @@ TestSpec withFunction(Class<? extends UserDefinedFunction>
functionClass) {
TestSpec testTableApiResult(
Expression expression, Object result, AbstractDataType<?>
dataType) {
+ return testTableApiResult(
+ new Expression[] {expression},
+ new Object[] {result},
+ new AbstractDataType<?>[] {dataType});
+ }
+
+ TestSpec testTableApiResult(
+ Expression[] expression, Object[] result,
AbstractDataType<?>[] dataType) {
Review comment:
Don't have any objection, just chose arrays here to avoid the overhead
of List objects especially for the common cases of only one element, but
considering it's test, Lists are nicer indeed.
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/BuiltInFunctionTestBase.java
##########
@@ -383,18 +439,69 @@ public String toString() {
}
}
- private static class SqlErrorTestItem extends ErrorTestItem {
- final String expression;
+ private static class SqlErrorTestItem extends ErrorTestItem<String> {
private SqlErrorTestItem(
String expression, String errorMessage, boolean
expectedDuringValidation) {
- super(errorMessage, expectedDuringValidation);
- this.expression = expression;
+ super(expression, errorMessage, expectedDuringValidation);
+ }
+
+ @Override
+ String expression() {
+ return expression;
}
@Override
public String toString() {
return "[SQL] " + expression;
}
}
+
+ private static List<DataType> createDataTypes(
+ DataTypeFactory dataTypeFactory, AbstractDataType<?>[] dataTypes) {
+ return Stream.of(dataTypes)
+ .map(dataTypeFactory::createDataType)
+ .collect(Collectors.toList());
+ }
+
+ /** Helper POJO to store test parameters. */
+ public static class TableTestSpecColumn {
+
+ Expression tableApiExpression;
+ String sqlExpression;
+ Object result;
+ AbstractDataType<?> tableApiDataType;
+ AbstractDataType<?> sqlDataType;
+
+ public static TableTestSpecColumn of(
+ Expression tableApiExpression,
+ String sqlExpression,
+ Object result,
+ AbstractDataType<?> dataType) {
+ return of(tableApiExpression, sqlExpression, result, dataType,
dataType);
+ }
+
+ public static TableTestSpecColumn of(
+ Expression tableApiExpression,
+ String sqlExpression,
+ Object result,
+ AbstractDataType<?> tableApiDataType,
+ AbstractDataType<?> sqlQueryDataType) {
Review comment:
I kept this variant exposed as there are a couple of tests in
`JsonFunctionsITCase` that make use of different return data types:
https://github.com/apache/flink/pull/17341/files#diff-14f6e87fed00e28afef4a5e995126c430b4065661e3dc2f66d14f3741378f874R180
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/BuiltInFunctionTestBase.java
##########
@@ -383,18 +439,69 @@ public String toString() {
}
}
- private static class SqlErrorTestItem extends ErrorTestItem {
- final String expression;
+ private static class SqlErrorTestItem extends ErrorTestItem<String> {
private SqlErrorTestItem(
String expression, String errorMessage, boolean
expectedDuringValidation) {
- super(errorMessage, expectedDuringValidation);
- this.expression = expression;
+ super(expression, errorMessage, expectedDuringValidation);
+ }
+
+ @Override
+ String expression() {
+ return expression;
}
@Override
public String toString() {
return "[SQL] " + expression;
}
}
+
+ private static List<DataType> createDataTypes(
+ DataTypeFactory dataTypeFactory, AbstractDataType<?>[] dataTypes) {
+ return Stream.of(dataTypes)
+ .map(dataTypeFactory::createDataType)
+ .collect(Collectors.toList());
+ }
+
+ /** Helper POJO to store test parameters. */
+ public static class TableTestSpecColumn {
Review comment:
Makes sense, thx, couldn't come up with a nice name.
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CoalesceFunctionITCase.java
##########
@@ -40,23 +41,28 @@
.onFieldsWithData(null, null, 1)
.andDataTypes(BIGINT().nullable(), INT().nullable(),
INT().notNull())
.testResult(
- coalesce($("f0"), $("f1")),
- "COALESCE(f0, f1)",
- null,
- BIGINT().nullable())
- .testResult(
- coalesce($("f0"), $("f2")),
- "COALESCE(f0, f2)",
- 1L,
- BIGINT().notNull())
- .testResult(
- coalesce($("f1"), $("f2")), "COALESCE(f1,
f2)", 1, INT().notNull())
- .testResult(
- coalesce($("f0"), 1),
- "COALESCE(f0, 1)",
- 1L,
- // In this case, the return type is not null
because we have a
- // constant in the function invocation
- BIGINT().notNull()));
+ of(
Review comment:
Sure, I'd prefer though the name `resultSpec()` since `resultItem` is
another more lower level pojo within the class and can cause confusion.
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/BuiltInFunctionTestBase.java
##########
@@ -150,7 +153,7 @@ private static void testResult(
assertEquals(
"Result of column [" + i + "] doesn't match.",
Review comment:
Something like:
```
"Logical type for spec [" + i + "] of test [" + testItem + "] doesn't match"
&
"Result for spec [" + i + "] of test [" + testItem + "] doesn't match"
```
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/BuiltInFunctionTestBase.java
##########
@@ -150,7 +153,7 @@ private static void testResult(
assertEquals(
"Result of column [" + i + "] doesn't match.",
Review comment:
Something like:
```
"Logical type for spec [" + i + "] of test [" + testItem + "] doesn't match"
```
&
```
"Result for spec [" + i + "] of test [" + testItem + "] doesn't match"
```
looks good?
##########
File path:
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/BuiltInFunctionTestBase.java
##########
@@ -150,7 +153,7 @@ private static void testResult(
assertEquals(
"Result of column [" + i + "] doesn't match.",
Review comment:
Pushed this change, along with a fix regarding the relevant `toString()`
implementation for TableAPI cases.
--
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]