Last active
January 12, 2023 17:30
-
-
Save GrigorievNick/e7cf9ec5584b417d9719e2812722e6d3 to your computer and use it in GitHub Desktop.
Spark Observation API Bug, reproduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.spark.sql.Observation | |
import org.apache.spark.sql.SparkSession | |
import org.apache.spark.sql.functions._ | |
import org.scalatest.FunSuite | |
class TestObservationWithForeach extends FunSuite { | |
test("observation") { | |
implicit val spark: SparkSession = SparkSession.builder() | |
.master("local") | |
.getOrCreate() | |
import spark.implicits._ | |
spark.listenerManager.register(new QueryExecutionListener { | |
override def onSuccess(funcName: String, qe: QueryExecution, durationNs: Long): Unit = | |
println(qe) | |
override def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = | |
println(qe) | |
}) | |
val observation = Observation.apply("test") | |
spark | |
.range(200) | |
.repartition(5) | |
.observe(observation, count($"id")) | |
.foreach(println(_)) | |
// .foreachPartition { it: Iterator[lang.Long] => it.foreach(println) } | |
// .count() | |
println(observation.get) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
uncomment
count
and test will pass, but withforeach
andforeachPartition
it will stuck.Because these two actions do not trigger
QueryExecutionListener
.