pan3793 commented on code in PR #53625:
URL: https://github.com/apache/spark/pull/53625#discussion_r2654855499
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/SQLExecutionSuite.scala:
##########
@@ -165,6 +166,140 @@ class SQLExecutionSuite extends SparkFunSuite with
SQLConfHelper {
}
}
+ test("Concurrent query execution QPL queryId persists in thread local") {
+ SparkSession.getActiveSession.foreach(_.stop())
+ val spark =
SparkSession.builder().master("local[*]").appName("ignore").getOrCreate()
+
+ try {
+ val originalQueryId =
spark.sparkContext.getLocalProperty(SQLExecution.QUERY_ID_KEY)
+ val parentQE = new
QueryExecution(spark.asInstanceOf[classic.SparkSession], OneRowRelation())
+ val parentQueryId = parentQE.queryId.toString
+
+ var childQueryId: String = null
+ var throwable: Option[Throwable] = None
+
+ val child = new Thread {
+ override def run(): Unit = {
+ try {
+ val childQE =
+ new QueryExecution(spark.asInstanceOf[classic.SparkSession],
OneRowRelation())
+ SQLExecution.withNewExecutionId(childQE) {
+ childQueryId =
spark.sparkContext.getLocalProperty(SQLExecution.QUERY_ID_KEY)
+ }
+ } catch {
+ case t: Throwable =>
+ throwable = Some(t)
+ }
+ }
+ }
+
+ SQLExecution.withNewExecutionId(parentQE) {
+ child.start()
+ child.join()
+ }
+
+ assert(childQueryId != null)
+ assert(originalQueryId != childQueryId && parentQueryId != childQueryId)
+ // SparkContext originalQueryId should be maintained after child thread
+ assert(spark.sparkContext.getLocalProperty(SQLExecution.QUERY_ID_KEY) ==
originalQueryId)
+
+ // QPL queryIds should be monotonic (UUIDv7)
+ assert(parentQueryId < childQueryId)
Review Comment:
now, the assertion is not always true
--
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]