You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ur...@apache.org on 2026/09/28 12:13:55 UTC
(spark) branch branch-4.x updated: [SPARK-57128][SQL][TEST] Preserve commas in SQL test settings
This is an automated email from the ASF dual-hosted git repository.
uros-b pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 0809a4c8489a [SPARK-57128][SQL][TEST] Preserve commas in SQL test settings
0809a4c8489a is described below
commit 0809a4c8489abb2bd1ef5a3ee2af2431b654683c
Author: Xinyao Zhang <43...@users.noreply.github.com>
AuthorDate: Mon Sep 28 12:13:29 2026 +0000
[SPARK-57128][SQL][TEST] Preserve commas in SQL test settings
### What changes were proposed in this pull request?
Update `SQLQueryTestHelper.getSparkSettings` so that a comma is treated as a setting separator only when it is followed by another configuration key. This preserves commas inside configuration values.
### Why are the changes needed?
`--SET` directives can contain values with commas, such as `spark.sql.optimizer.excludedRules`. The previous parser split those values incorrectly.
### Related issue
[SPARK-57128: SQLQueryTestHelper --SET parser cannot handle config values containing commas](https://issues.apache.org/jira/browse/SPARK-57128)
### Does this PR introduce any user-facing change?
No.
### How was this patch tested?
Added focused unit coverage for single and multiple settings, multiple directives, comma-containing values, and unrelated comments.
Ran:
```text
build/sbt 'sql/testOnly org.apache.spark.sql.SQLQueryTestHelperSuite'\n```\n\nAll 6 tests passed.
Closes #58556 from zhangxinyao88/codex/issue-57128-set-parser.
Authored-by: Xinyao Zhang <43...@users.noreply.github.com>
Signed-off-by: Uros Bojanic <22...@users.noreply.github.com>
(cherry picked from commit 56a654d739044d1fbd61bc284fb321d175b340b2)
Signed-off-by: Uros Bojanic <22...@users.noreply.github.com>
---
.../org/apache/spark/sql/SQLQueryTestHelper.scala | 2 +-
.../apache/spark/sql/SQLQueryTestHelperSuite.scala | 64 ++++++++++++++++++++++
2 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala
index 8028970193ac..e4782b7fd41e 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala
@@ -474,7 +474,7 @@ trait SQLQueryTestHelper extends SQLConfHelper with Logging {
protected def getSparkSettings(comments: Array[String]): Array[(String, String)] = {
val settingLines = comments.filter(_.startsWith("--SET ")).map(_.substring(6))
- settingLines.flatMap(_.split(",").map { kv =>
+ settingLines.flatMap(_.split(",(?=\\s*[^,=]+\\s*=)").map { kv =>
val (conf, value) = kv.span(_ != '=')
conf.trim -> value.substring(1).trim
})
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelperSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelperSuite.scala
new file mode 100644
index 000000000000..b3796ea02dbd
--- /dev/null
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelperSuite.scala
@@ -0,0 +1,64 @@
+/*
+ * 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
+
+import org.apache.spark.SparkFunSuite
+
+class SQLQueryTestHelperSuite extends SparkFunSuite with SQLQueryTestHelper {
+
+ test("getSparkSettings: single key=value with spaces around the separator") {
+ val result = getSparkSettings(Array("--SET spark.sql.foo = 1"))
+ assert(result.toSeq === Seq("spark.sql.foo" -> "1"))
+ }
+
+ test("getSparkSettings: multiple key=value pairs with spaces in one --SET") {
+ val result = getSparkSettings(Array("--SET spark.sql.foo = 1, spark.sql.bar = 2"))
+ assert(result.toSeq === Seq("spark.sql.foo" -> "1", "spark.sql.bar" -> "2"))
+ }
+
+ test("getSparkSettings: multiple --SET statements") {
+ val result = getSparkSettings(
+ Array("--SET spark.sql.foo=1", "--SET spark.sql.bar=2"))
+ assert(result.toSeq === Seq("spark.sql.foo" -> "1", "spark.sql.bar" -> "2"))
+ }
+
+ test("getSparkSettings: value containing commas") {
+ val excludedRules =
+ "org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation," +
+ "org.apache.spark.sql.catalyst.optimizer.ConstantFolding"
+ val result = getSparkSettings(
+ Array(s"--SET spark.sql.optimizer.excludedRules=$excludedRules"))
+ assert(result.toSeq === Seq("spark.sql.optimizer.excludedRules" -> excludedRules))
+ }
+
+ test("getSparkSettings: mixed settings with a comma-containing value and spaces") {
+ val excludedRules =
+ "org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation," +
+ "org.apache.spark.sql.catalyst.optimizer.ConstantFolding"
+ val result = getSparkSettings(
+ Array(s"--SET spark.sql.optimizer.excludedRules = $excludedRules, spark.sql.foo = 1"))
+ assert(result.toSeq === Seq(
+ "spark.sql.optimizer.excludedRules" -> excludedRules,
+ "spark.sql.foo" -> "1"))
+ }
+
+ test("getSparkSettings: ignores non --SET comments") {
+ val result = getSparkSettings(
+ Array("-- a comment", "--SET spark.sql.foo=1", "-- another"))
+ assert(result.toSeq === Seq("spark.sql.foo" -> "1"))
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org