HyukjinKwon commented on a change in pull request #33422:
URL: https://github.com/apache/spark/pull/33422#discussion_r672980755
##########
File path:
sql/core/src/test/java/test/org/apache/spark/sql/JavaDataFrameSuite.java
##########
@@ -523,4 +523,55 @@ public void testUDF() {
.map(row -> row.get(0).toString() +
row.getString(1)).toArray(String[]::new);
Assert.assertArrayEquals(expected, result);
}
+
+ /**
+ * Tests the Java API of Observation and Dataset.observe(Observation,
Column, Column*).
+ */
+ @Test
+ public void testObservation() {
+ Observation namedObservation = new Observation("named");
+ Observation unnamedObservation = new Observation();
+
+ Dataset<Long> df = spark
+ .range(100)
+ .observe(
+ namedObservation,
+ min(col("id")).as("min_val"),
+
scala.collection.JavaConverters.asScalaBuffer(Arrays.asList(
+ max(col("id")).as("max_val"),
+ sum(col("id")).as("sum_val"),
+ count(when(pmod(col("id"), lit(2)).$eq$eq$eq(0),
1)).as("num_even")
+ ))
+ )
+ .observe(
+ unnamedObservation,
+ avg(col("id")).cast("int").as("avg_val"),
+
scala.collection.JavaConverters.asScalaBuffer(Arrays.asList())
+ );
+
+ df.collect();
+ Row namedMetrics = null;
+ Row unnamedMetrics = null;
+
+ try {
+ // we can get the result multiple times
+ namedMetrics = namedObservation.get();
+ unnamedMetrics = unnamedObservation.get();
+ } catch (InterruptedException e) {
+ Assert.fail();
+ }
+ Assert.assertEquals(Arrays.asList(0L, 99L, 4950L, 50L),
scala.collection.JavaConverters.seqAsJavaList(namedMetrics.toSeq()));
Review comment:
I think the current way is fine.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]