[
https://issues.apache.org/jira/browse/BEAM-5103?focusedWorklogId=132702&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-132702
]
ASF GitHub Bot logged work on BEAM-5103:
----------------------------------------
Author: ASF GitHub Bot
Created on: 08/Aug/18 22:03
Start Date: 08/Aug/18 22:03
Worklog Time Spent: 10m
Work Description: akedin commented on a change in pull request #6175:
[BEAM-5103][SQL]test aggregation functions at DSL level
URL: https://github.com/apache/beam/pull/6175#discussion_r208749328
##########
File path:
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/integrationtest/BeamSqlBuiltinFunctionsIntegrationTestBase.java
##########
@@ -180,13 +264,27 @@ public void buildRunAndCheck() {
PCollection<Row> output =
inputCollection.apply(testCase.toString(),
SqlTransform.query(sql));
-
- PAssert.that(output)
-
.containsInAnyOrder(TestUtils.RowsBuilder.of(schema).addRows(expectedValue).getRows());
+ if (testCase.isCompareNonExactNumber()) {
+ PAssert.that(output).satisfies(matchesScalar((double) expectedValue,
PRECISION));
+ } else {
+ PAssert.that(output)
+ .containsInAnyOrder(
+
TestUtils.RowsBuilder.of(schema).addRows(expectedValue).getRows());
+ }
Review comment:
If we know that expression returns `double`, can we just hide the `nonExact`
stuff and decide to use `PRECISION` version ourselves without having to call
`addExprWithNonExactExpectedValue`?
If all current expressions are scalar, I would try implementing another
method similar to `matchesScalar()`, e.g.:
```
public static SerializableFunction<Iterable<Row>, Void>
matchesScalar(Object expected) {
return records -> {
Row row = Iterables.getOnlyElement(records);
assertNotNull(row);
Object actual = row.getValue(0)
// For doubles and floats we need to allow some precision delta,
// other values can use regular equality check
if (!(expected instanceof Double || expected instanceof Float)) {
assertEquals(expected, actual);
} else {
assertEquals(toDouble(expected), toDouble(actual), PRECISION);
}
return null;
};
}
private static double toDouble(Object value) {
return (value instanceof Double)
? (Double) value
: (Float) value; // not sure if this cast works correctly though
}
```
Then it should be sufficient to just call
`PAssert...satisfies(matchesScalar(expectedValue))`.
Alternatively you probably can do the `if (!(expected instanceof
Double)...)` check and calling correct assertion right here in
`buildRunAndCheck` instead of implementing another `matchesScalar`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 132702)
Time Spent: 2.5h (was: 2h 20m)
> Test aggregation functions at DSL levels
> ----------------------------------------
>
> Key: BEAM-5103
> URL: https://issues.apache.org/jira/browse/BEAM-5103
> Project: Beam
> Issue Type: Sub-task
> Components: dsl-sql
> Reporter: Rui Wang
> Assignee: Rui Wang
> Priority: Major
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
> Typical aggregation functions include COUNT, SUM, MAX, MIN, etc.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)