rionmonster commented on code in PR #30251:
URL: https://github.com/apache/flink/pull/30251#discussion_r4801632339
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MathFunctionsITCase.java:
##########
@@ -176,7 +177,36 @@ private Stream<TestSetSpec> truncateTestCases() {
$("f0").truncate(2),
"TRUNCATE(f0, 2)",
new BigDecimal("123.45"),
- DataTypes.DECIMAL(6, 2).notNull()));
+ DataTypes.DECIMAL(6, 2).notNull()),
+ TestSetSpec.forFunction(BuiltInFunctionDefinitions.TRUNCATE)
+ .onFieldsWithData((byte) 125, (short) 1259)
+ .andDataTypes(DataTypes.TINYINT(),
DataTypes.SMALLINT())
+ .testResult(
+ $("f0").truncate(-1),
+ "TRUNCATE(f0, -1)",
+ (byte) 120,
+ DataTypes.TINYINT())
+ .testResult(
+ $("f1").truncate(-1),
+ "TRUNCATE(f1, -1)",
+ (short) 1250,
+ DataTypes.SMALLINT())
+ .testResult(
+ $("f0").truncate(), "TRUNCATE(f0)", (byte)
125, DataTypes.TINYINT())
+ .testResult(
+ $("f1").truncate(),
+ "TRUNCATE(f1)",
+ (short) 1259,
+ DataTypes.SMALLINT()));
Review Comment:
Currently this is only targeting positive values. We should probably
consider adding negative values for both types as well just in the interest of
coverage and exercising those paths.
Something like:
```
.onFieldsWithData((byte) 125, (short) 1259, (byte) -125, (short) -1259)
.andDataTypes(DataTypes.TINYINT(), DataTypes.SMALLINT(),
DataTypes.TINYINT(), DataTypes.SMALLINT())
...
.testResult($("f2").truncate(-1), "TRUNCATE(f2, -1)", (byte) -120,
DataTypes.TINYINT())
.testResult($("f3").truncate(-1), "TRUNCATE(f3, -1)", (short) -1250,
DataTypes.SMALLINT())
```
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MathFunctionsITCase.java:
##########
@@ -176,7 +177,36 @@ private Stream<TestSetSpec> truncateTestCases() {
$("f0").truncate(2),
"TRUNCATE(f0, 2)",
new BigDecimal("123.45"),
- DataTypes.DECIMAL(6, 2).notNull()));
+ DataTypes.DECIMAL(6, 2).notNull()),
+ TestSetSpec.forFunction(BuiltInFunctionDefinitions.TRUNCATE)
+ .onFieldsWithData((byte) 125, (short) 1259)
+ .andDataTypes(DataTypes.TINYINT(),
DataTypes.SMALLINT())
+ .testResult(
+ $("f0").truncate(-1),
+ "TRUNCATE(f0, -1)",
+ (byte) 120,
+ DataTypes.TINYINT())
+ .testResult(
+ $("f1").truncate(-1),
+ "TRUNCATE(f1, -1)",
+ (short) 1250,
+ DataTypes.SMALLINT())
+ .testResult(
+ $("f0").truncate(), "TRUNCATE(f0)", (byte)
125, DataTypes.TINYINT())
+ .testResult(
+ $("f1").truncate(),
+ "TRUNCATE(f1)",
+ (short) 1259,
+ DataTypes.SMALLINT()));
+ }
+
+ private Stream<TestSetSpec> signTestCases() {
+ return Stream.of(
+ TestSetSpec.forFunction(BuiltInFunctionDefinitions.SIGN)
+ .onFieldsWithData((byte) -5, (short) -5)
+ .andDataTypes(DataTypes.TINYINT(),
DataTypes.SMALLINT())
+ .testResult($("f0").sign(), "SIGN(f0)", (byte) -1,
DataTypes.TINYINT())
+ .testResult($("f1").sign(), "SIGN(f1)", (short) -1,
DataTypes.SMALLINT()));
Review Comment:
Similar to the previous comment, probably worth adding a pair of
corresponding positive fields for both types, a zero value, and and the
associated assertions to exercise those paths.
--
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]