Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class IncrementalExecution(
*/
override
lazy val optimizedPlan: LogicalPlan = tracker.measurePhase(QueryPlanningTracker.OPTIMIZATION) {
sparkSession.sessionState.optimizer.execute(withCachedData) transformAllExpressions {
sparkSession.sessionState.optimizer.executeAndTrack(withCachedData,
tracker) transformAllExpressions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpit: in most cases, we do not break the function call in the middle of parameter lists. We can change it to

    val sessionState = sparkSession.sessionState
    sessionState.optimizer.executeAndTrack(withCachedData, tracker).transformAllExpressions {

or

    sparkSession.sessionState.optimizer
      .executeAndTrack(withCachedData, tracker).transformAllExpressions {

case ts @ CurrentBatchTimestamp(timestamp, _, _) =>
logInfo(s"Current batch timestamp = $timestamp")
ts.toLiteral
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package org.apache.spark.sql.execution

import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.execution.streaming.{MemoryStream, StreamExecution}
import org.apache.spark.sql.streaming.StreamTest

class QueryPlanningTrackerEndToEndSuite extends SharedSparkSession {
class QueryPlanningTrackerEndToEndSuite extends StreamTest {
import testImplicits._

test("programmatic API") {
val df = spark.range(1000).selectExpr("count(*)")
Expand All @@ -38,4 +40,22 @@ class QueryPlanningTrackerEndToEndSuite extends SharedSparkSession {
assert(tracker.rules.nonEmpty)
}

test("SPARK-29227: Track rule info in optimization phase in streaming") {
val inputData = MemoryStream[Int]
val df = inputData.toDF()

def assertStatus(stream: StreamExecution): Unit = {
stream.processAllAvailable()
val tracker = stream.lastExecution.tracker
assert(tracker.phases.keys == Set("analysis", "optimization", "planning"))
assert(tracker.rules.nonEmpty)
}

testStream(df)(
StartStream(),
AddData(inputData, 1, 2, 3),
Execute(assertStatus),
StopStream)
}

}