hvanhovell commented on code in PR #45701:
URL: https://github.com/apache/spark/pull/45701#discussion_r1571108161
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -1511,6 +1514,46 @@ class ClientE2ETestSuite extends RemoteSparkSession with
SQLHelper with PrivateM
(0 until 5).foreach(i => assert(row.get(i * 2) === row.get(i * 2 + 1)))
}
}
+
+ test("Observable metrics") {
+ val df = spark.range(99).withColumn("extra", col("id") - 1)
+ val ob1 = new Observation("ob1")
+ val observedDf = df.observe(ob1, min("id"), avg("id"), max("id"))
+ val observedObservedDf = observedDf.observe("ob2", min("extra"),
avg("extra"), max("extra"))
+
+ val ob1Schema = new StructType()
+ .add("min(id)", LongType)
+ .add("avg(id)", DoubleType)
+ .add("max(id)", LongType)
+ val ob2Schema = new StructType()
+ .add("min(extra)", LongType)
+ .add("avg(extra)", DoubleType)
+ .add("max(extra)", LongType)
+ val ob1Metrics = Map("ob1" -> new GenericRowWithSchema(Array(0, 49, 98),
ob1Schema))
+ val ob2Metrics = Map("ob2" -> new GenericRowWithSchema(Array(-1, 48, 97),
ob2Schema))
+
+ assert(df.collectResult().getObservedMetrics === Map.empty)
+ assert(observedDf.collectResult().getObservedMetrics === ob1Metrics)
+ assert(observedObservedDf.collectResult().getObservedMetrics ===
ob1Metrics ++ ob2Metrics)
+ }
+
+ test("Observation.get is blocked until the query is finished") {
+ val df = spark.range(99).withColumn("extra", col("id") - 1)
+ val observation = new Observation("ob1")
+ val observedDf = df.observe(observation, min("id"), avg("id"), max("id"))
+
+ // Start a new thread to get the observation
+ val future = Future(observation.get)(ExecutionContext.global)
Review Comment:
For the record. IMO the observation class should have been using a future
from the get go.
--
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]