This is an automated email from the ASF dual-hosted git repository.
sarutak pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 4307a03f97b3 [SPARK-57262][SQL][WEBUI][4.1] Job description derived
from a query should respect `spark.sql.redaction.string.regex`
4307a03f97b3 is described below
commit 4307a03f97b3377594846908801dc9c36ace6935
Author: Kousuke Saruta <[email protected]>
AuthorDate: Tue Jun 9 16:08:23 2026 +0900
[SPARK-57262][SQL][WEBUI][4.1] Job description derived from a query should
respect `spark.sql.redaction.string.regex`
### What changes were proposed in this pull request?
This PR backports SPARK-57262 (#56361) to `branch-4.1`.
This PR changes `SparkSQLDriver.scala` to redact a query before
`setJobDescription`.
### Why are the changes needed?
In the current implementation, when a query is executed through
`SparkSQLDriver`, redaction is done in `SQLExecution.scala` so the description
in the table on the `/SQL` page is redacted.
<img width="488" height="252" alt="sql-page-4 1"
src="https://github.com/user-attachments/assets/bec6cd3d-c655-4bb2-9e95-5d0efb86999a"
/>
But the description in the table on the `/jobs` page is not redacted.
<img width="444" height="162" alt="jobs-page-before-4 1"
src="https://github.com/user-attachments/assets/a6c93c26-2a64-4d41-ae1a-23ac77e38f84"
/>
### Does this PR introduce _any_ user-facing change?
Yes.
### How was this patch tested?
Added new test and confirmed the test `SQL execution description should
respect spark.sql.redaction.string.regex` added in #56358 passed.
Also confirmed the description is redacted in UI.
```
$ bin/spark-sql --conf spark.sql.redaction.string.regex="secret.*=.*"
spark-sql (default)> CREATE TABLE test1(secret string);
spark-sql (default)> SELECT * FROM test1 WHERE secret=1;
```
<img width="601" height="205" alt="jobs-page-after-4 1"
src="https://github.com/user-attachments/assets/c21ae7cc-1089-4e3c-828a-ad022cd2492f"
/>
### Was this patch authored or co-authored using generative AI tooling?
Kiro CLI / Claude
Closes #56364 from sarutak/fix-redact-sql-description-v2-4.1.
Authored-by: Kousuke Saruta <[email protected]>
Signed-off-by: Kousuke Saruta <[email protected]>
---
.../sql/hive/thriftserver/SparkSQLDriver.scala | 4 +-
.../hive/thriftserver/SparkSQLDriverSuite.scala | 51 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git
a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLDriver.scala
b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLDriver.scala
index 8b9b7352fdca..da89203f286c 100644
---
a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLDriver.scala
+++
b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLDriver.scala
@@ -66,7 +66,9 @@ private[hive] class SparkSQLDriver(val sparkSession:
SparkSession = SparkSQLEnv.
val substitutorCommand =
SQLConf.withExistingConf(sparkSession.sessionState.conf) {
new VariableSubstitution().substitute(command)
}
- sparkSession.sparkContext.setJobDescription(substitutorCommand)
+ val redactedCommand =
+ Utils.redact(sparkSession.sessionState.conf.stringRedactionPattern,
substitutorCommand)
+ sparkSession.sparkContext.setJobDescription(redactedCommand)
val execution =
sparkSession.sessionState.executePlan(sparkSession.sql(command).logicalPlan)
// The SQL command has been executed above via `executePlan`, therefore
we don't need to
// wrap it again with a new execution ID when getting Hive result.
diff --git
a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLDriverSuite.scala
b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLDriverSuite.scala
new file mode 100644
index 000000000000..f42970ede669
--- /dev/null
+++
b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLDriverSuite.scala
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.hive.thriftserver
+
+import org.apache.spark.SparkContext
+import org.apache.spark.scheduler.{SparkListener, SparkListenerJobStart}
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.util.Utils.REDACTION_REPLACEMENT_TEXT
+
+class SparkSQLDriverSuite extends SharedSparkSession {
+
+ test("job description should be redacted by
spark.sql.redaction.string.regex") {
+ withSQLConf(SQLConf.SQL_STRING_REDACTION_PATTERN.key ->
"password=([^\\s]+)") {
+ var jobDescription: String = null
+ spark.sparkContext.addSparkListener(new SparkListener {
+ override def onJobStart(jobStart: SparkListenerJobStart): Unit = {
+ jobDescription =
+ jobStart.properties.getProperty(SparkContext.SPARK_JOB_DESCRIPTION)
+ }
+ })
+
+ val driver = new SparkSQLDriver(spark)
+ try {
+ driver.run("SELECT 'password=secret123'")
+ } finally {
+ driver.close()
+ }
+
+ spark.sparkContext.listenerBus.waitUntilEmpty()
+ assert(jobDescription != null)
+ assert(!jobDescription.contains("secret123"))
+ assert(jobDescription.contains(REDACTION_REPLACEMENT_TEXT))
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]