Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/7982#discussion_r36374004
--- Diff:
sql/hive/src/test/java/test/org/apache/spark/sql/hive/JavaDataFrameSuite.java
---
@@ -77,4 +81,26 @@ public void saveTableAndQueryIt() {
" ROWS BETWEEN 1 preceding and 1 following) " +
"FROM window_table").collectAsList());
}
+
+ @Test
+ public void testUDAF() {
+ DataFrame df = hc.range(0, 100).unionAll(hc.range(0,
100)).select(col("id").as("value"));
+ UserDefinedAggregateFunction udaf = new MyDoubleSum();
+ UserDefinedAggregateFunction registeredUDAF =
hc.udf().register("mydoublesum", udaf);
+ // Create Columns for the UDAF. For now, callUDF does not take an
argument to specific if
+ // we want to use distinct aggregation.
+ DataFrame aggregatedDF =
+ df.groupBy()
+ .agg(
+ udaf.apply(true, col("value")),
+ udaf.apply(col("value")),
+ registeredUDAF.apply(col("value")),
+ callUDF("mydoublesum", col("value")));
+
+ List<Row> expectedResult = new ArrayList<Row>();
+ expectedResult.add(RowFactory.create(4950.0, 9900.0, 9900.0, 9900.0));
+ checkAnswer(
+ aggregatedDF,
+ expectedResult);
+ }
--- End diff --
@rxin This is how we call a UDAF in java.
---
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]