Skip to content

Commit cfb76f5

Browse files
committed
address comment
1 parent cf75856 commit cfb76f5

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/SQLExecution.scala

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,22 @@ object SQLExecution {
106106
}
107107

108108
def withSQLConfPropagated[T](sparkSession: SparkSession)(body: => T): T = {
109+
val sc = sparkSession.sparkContext
109110
// Set all the specified SQL configs to local properties, so that they can be available at
110111
// the executor side.
111112
val allConfigs = sparkSession.sessionState.conf.getAllConfs
112-
val originalLocalProps = scala.collection.mutable.HashMap.empty[String, String]
113-
for ((key, value) <- allConfigs) {
114-
// Excludes external configs defined by users.
115-
if (key.startsWith("spark")) {
116-
Option(sparkSession.sparkContext.getLocalProperty(key)).foreach {
117-
// If users already set a value in local properties, keep it and restore it at the end.
118-
origin => originalLocalProps(key) = origin
119-
}
120-
sparkSession.sparkContext.setLocalProperty(key, value)
121-
}
113+
val originalLocalProps = allConfigs.collect {
114+
case (key, value) if key.startsWith("spark") =>
115+
val originalValue = sc.getLocalProperty(key)
116+
sc.setLocalProperty(key, value)
117+
(key, originalValue)
122118
}
119+
123120
try {
124121
body
125122
} finally {
126-
allConfigs.foreach {
127-
case (key, _) =>
128-
val origin = originalLocalProps.getOrElse(key, null)
129-
sparkSession.sparkContext.setLocalProperty(key, origin)
123+
for ((key, value) <- originalLocalProps) {
124+
sc.setLocalProperty(key, value)
130125
}
131126
}
132127
}

0 commit comments

Comments
 (0)