Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/9591#discussion_r44468965
--- Diff:
sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java ---
@@ -366,4 +368,52 @@ public void testNestedTupleEncoder() {
context.createDataset(data3, encoder3);
Assert.assertEquals(data3, ds3.collectAsList());
}
+
+ @Test
+ public void testTypedAggregation() {
+ Encoder<Tuple2<String, Integer>> encoder = e.tuple(e.STRING(),
e.INT());
+ List<Tuple2<String, Integer>> data =
+ Arrays.asList(tuple2("a", 1), tuple2("a", 2), tuple2("b", 3));
+ Dataset<Tuple2<String, Integer>> ds = context.createDataset(data,
encoder);
+
+ GroupedDataset<String, Tuple2<String, Integer>> grouped = ds.groupBy(
+ new MapFunction<Tuple2<String, Integer>, String>() {
+ @Override
+ public String call(Tuple2<String, Integer> value) throws Exception
{
+ return value._1();
+ }
+ },
+ e.STRING());
+
+ Dataset<Tuple2<String, Integer>> agged = grouped.agg(new
IntSumOf().toColumn(e.INT(), e.INT()));
+ Assert.assertEquals(Arrays.asList(tuple2("a", 3), tuple2("b", 3)),
agged.collectAsList());
+
+ Dataset<Tuple4<String, Integer, Long, Long>> agged2 = grouped.agg(
+ new IntSumOf().toColumn(e.INT(), e.INT()),
+ (TypedColumn<Tuple2<String, Integer>, Long>) (Object)
expr("sum(_2)").as(e.LONG()),
+ (TypedColumn<Tuple2<String, Integer>, Long>) (Object) count("*"));
--- End diff --
Yeah, this is unfortunate. I think that the only thing we can do is use
the `DataFrame` version of `agg` and then cast afterwards.
```java
Dataset<Tuple4<String, Integer, Long, Long>> agged2 = grouped.agg(
new IntSumOf().toColumn(e.INT(), e.INT()),
expr("sum(_2)"),
count("*")).as(e.tuple(e.STRING(), e.INT(), e.LONG(),
e.LONG()));
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]