Skip to content

Commit 9f637b5

Browse files
belieferdongjoon-hyun
authored andcommitted
[SPARK-51305][SQL][CONNECT] Improve SparkConnectPlanExecution.createObservedMetricsResponse
### What changes were proposed in this pull request? This PR proposes to improve the code for `createObservedMetricsResponse`. ### Why are the changes needed? There exists a duplicate judgement in loop, we should eliminate it. ### Does this PR introduce _any_ user-facing change? 'No'. ### How was this patch tested? GA. ### Was this patch authored or co-authored using generative AI tooling? 'No'. Closes apache#50066 from beliefer/SPARK-51305. Authored-by: beliefer <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 9de3b7c commit 9f637b5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sql/connect/server/src/main/scala/org/apache/spark/sql/connect/execution/SparkConnectPlanExecution.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ private[execution] class SparkConnectPlanExecution(executeHolder: ExecuteHolder)
266266
dataframe: DataFrame): Option[ExecutePlanResponse] = {
267267
val observedMetrics = dataframe.queryExecution.observedMetrics.collect {
268268
case (name, row) if !executeHolder.observations.contains(name) =>
269-
val values = (0 until row.length).map { i =>
270-
(if (row.schema != null) Some(row.schema.fieldNames(i)) else None, row(i))
269+
val values = if (row.schema == null) {
270+
(0 until row.length).map { i => (None, row(i)) }
271+
} else {
272+
(0 until row.length).map { i => (Some(row.schema.fieldNames(i)), row(i)) }
271273
}
272274
name -> values
273275
}

0 commit comments

Comments
 (0)