Skip to content

Fix DataWritingCommand callback naver be called on withListener method#7362

Open
wForget wants to merge 1 commit intoapache:masterfrom
wForget:fix_test
Open

Fix DataWritingCommand callback naver be called on withListener method#7362
wForget wants to merge 1 commit intoapache:masterfrom
wForget:fix_test

Conversation

@wForget
Copy link
Member

@wForget wForget commented Mar 17, 2026

Why are the changes needed?

The DataWritingCommand callback naver be called on withListener method

How was this patch tested?

Was this patch authored or co-authored using generative AI tooling?

No

@wForget
Copy link
Member Author

wForget commented Mar 17, 2026

Duplicate #6793

override def onSuccess(funcName: String, qe: QueryExecution, duration: Long): Unit = {
qe.executedPlan match {
case write: DataWritingCommandExec => callback(write.cmd)
collect(qe.executedPlan) {
Copy link
Member Author

Choose a reason for hiding this comment

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

DataWritingCommandExec is wrapped by AdaptiveSparkPlanExec, so we should use AdaptiveSparkPlanHelper#collect

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a test utility (withListener) used by Spark SQL extension test suites to reliably observe DataWritingCommandExec by traversing the executed physical plan, and adds an option to allow queries that legitimately have no write command.

Changes:

  • Update withListener to search the whole executed plan for DataWritingCommandExec and track whether the callback ran.
  • Add a mustBeCalled flag (default true) to assert callback execution when expected.
  • Update one rebalance-related test to opt out of the callback-must-run assertion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
extensions/spark/kyuubi-extension-spark-4-1/src/test/scala/org/apache/spark/sql/KyuubiSparkSQLExtensionTest.scala Makes withListener robust by scanning the executed plan and asserting callback execution by default.
extensions/spark/kyuubi-extension-spark-4-1/src/test/scala/org/apache/spark/sql/RebalanceBeforeWritingSuite.scala Uses the new mustBeCalled=false mode in a test that includes non-write queries.
Comments suppressed due to low confidence (1)

extensions/spark/kyuubi-extension-spark-4-1/src/test/scala/org/apache/spark/sql/RebalanceBeforeWritingSuite.scala:116

  • Setting mustBeCalled = false inside the shared check helper means this test will still pass even if the listener never finds a DataWritingCommandExec for INSERT queries (the callback won’t run, so the rebalance assertion won’t execute). To avoid masking regressions, consider using mustBeCalled=false only for the SELECT/COUNT cases that intentionally have no write command, and keep the default mustBeCalled=true for INSERT statements.
  test("check rebalance does not exists") {
    def check(df: DataFrame): Unit = {
      withListener(df, false) { write =>
        assert(write.collect {
          case r: RebalancePartitions => r
        }.isEmpty)
      }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

case write: DataWritingCommandExec =>
called.set(true)
callback(write.cmd)
case _ =>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants