Skip to content

Commit 991a7ec

Browse files
committed
separate sql confs
1 parent 9324ba9 commit 991a7ec

File tree

6 files changed

+70
-16
lines changed

6 files changed

+70
-16
lines changed

docs/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sql-configs.html
1+
*sql-configs.html

docs/configuration.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,16 +2622,31 @@ Please refer to the [Security](security.html) page for available options on how
26222622
Spark subsystems.
26232623

26242624

2625-
{% for static_file in site.static_files %}
2626-
{% if static_file.name == 'sql-configs.html' %}
26272625
### Spark SQL
26282626

2629-
{% include_relative sql-configs.html %}
2627+
#### Runtime SQL Configuration
2628+
2629+
Runtime SQL configurations inner-session, mutable Spark SQL configurations. They can be set and queried by SET commands and rest by RESET command, or by `SparkSession.conf`'s setter and getter methods.
2630+
2631+
{% for static_file in site.static_files %}
2632+
{% if static_file.name == 'runtime-sql-configs.html' %}
2633+
{% include_relative runtime-sql-configs.html %}
26302634
{% break %}
26312635
{% endif %}
26322636
{% endfor %}
26332637

26342638

2639+
#### Static SQL Configuration
2640+
2641+
Static SQL configurations are cross-session, immutable Spark SQL configurations. External users can query the static sql configs value via `SparkSession.conf` or via set command, e.g. `SET spark.sql.extensions;`, but cannot set/unset them.
2642+
2643+
{% for static_file in site.static_files %}
2644+
{% if static_file.name == 'static-sql-configs.html' %}
2645+
{% include_relative static-sql-configs.html %}
2646+
{% break %}
2647+
{% endif %}
2648+
{% endfor %}
2649+
26352650
### Spark Streaming
26362651

26372652
<table class="table">

sql/core/src/main/scala/org/apache/spark/sql/api/python/PythonSQLUtils.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import org.apache.spark.sql.catalyst.expressions.ExpressionInfo
2929
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser
3030
import org.apache.spark.sql.execution.{ExplainMode, QueryExecution}
3131
import org.apache.spark.sql.execution.arrow.ArrowConverters
32-
import org.apache.spark.sql.internal.SQLConf
32+
import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf}
3333
import org.apache.spark.sql.types.DataType
3434

3535
private[sql] object PythonSQLUtils {
@@ -42,12 +42,17 @@ private[sql] object PythonSQLUtils {
4242

4343
def listSQLConfigs(): Array[(String, String, String, String)] = {
4444
val conf = new SQLConf()
45-
// Force to build StaticSQLConf, which is a little bit hacky here
46-
conf.warehousePath
4745
// Py4J doesn't seem to translate Seq well, so we convert to an Array.
4846
conf.getAllDefinedConfs.toArray
4947
}
5048

49+
def listStaticSQLConfigs(): Array[(String, String, String, String)] = {
50+
val conf = new SQLConf()
51+
// Force to build static SQL configurations
52+
StaticSQLConf.WAREHOUSE_PATH.key -> ()
53+
conf.getAllDefinedConfs.filter(p => SQLConf.staticConfKeys.contains(p._1)).toArray
54+
}
55+
5156
/**
5257
* Python callable function to read a file in Arrow stream format and create a [[RDD]]
5358
* using each serialized ArrowRecordBatch as a partition.

sql/core/src/test/scala/org/apache/spark/sql/api/python/PythonSQLUtilsSuite.scala

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf}
2222

2323
class PythonSQLUtilsSuite extends SparkFunSuite {
2424

25-
test("list sql configurations should include all public one") {
25+
test("listing sql configurations contains runtime ones only") {
2626
val configs = PythonSQLUtils.listSQLConfigs()
2727

2828
// static sql configurations
29-
assert(configs.exists(entry => entry._1 == StaticSQLConf.SPARK_SESSION_EXTENSIONS.key),
29+
assert(!configs.exists(entry => entry._1 == StaticSQLConf.SPARK_SESSION_EXTENSIONS.key),
3030
"listSQLConfigs should contain public static sql configuration")
3131
assert(!configs.exists(entry => entry._1 == StaticSQLConf.DEBUG_MODE.key),
3232
"listSQLConfigs should not contain internal static sql configuration")
@@ -39,6 +39,26 @@ class PythonSQLUtilsSuite extends SparkFunSuite {
3939

4040
// spark core configurations
4141
assert(!configs.exists(entry => entry._1 == "spark.master"),
42-
"listSQLConfigs should not contain internal dynamic sql configuration")
42+
"listSQLConfigs should not contain core configuration")
43+
}
44+
45+
test("listing static sql configurations contains public static ones only") {
46+
val configs = PythonSQLUtils.listStaticSQLConfigs()
47+
48+
// static sql configurations
49+
assert(configs.exists(entry => entry._1 == StaticSQLConf.SPARK_SESSION_EXTENSIONS.key),
50+
"listStaticSQLConfigs should contain public static sql configuration")
51+
assert(!configs.exists(entry => entry._1 == StaticSQLConf.DEBUG_MODE.key),
52+
"listStaticSQLConfigs should not contain internal static sql configuration")
53+
54+
// dynamic sql configurations
55+
assert(!configs.exists(entry => entry._1 == SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED.key),
56+
"listStaticSQLConfigs should not contain dynamic sql configuration")
57+
assert(!configs.exists(entry => entry._1 == SQLConf.ANALYZER_MAX_ITERATIONS.key),
58+
"listStaticSQLConfigs should not contain internal dynamic sql configuration")
59+
60+
// spark core configurations
61+
assert(!configs.exists(entry => entry._1 == "spark.master"),
62+
"listStaticSQLConfigs should not contain core configuration")
4363
}
4464
}

sql/create-docs.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ mkdir docs
4545
echo "Generating SQL API Markdown files."
4646
"$SPARK_HOME/bin/spark-submit" gen-sql-api-docs.py
4747

48-
echo "Generating SQL configuration table HTML file."
49-
"$SPARK_HOME/bin/spark-submit" gen-sql-config-docs.py
48+
echo "Generating runtime SQL runtime configuration table HTML file."
49+
"$SPARK_HOME/bin/spark-submit" gen-sql-config-docs.py runtime
50+
51+
echo "Generating static SQL configuration table HTML file."
52+
"$SPARK_HOME/bin/spark-submit" gen-sql-config-docs.py static
5053

5154
echo "Generating HTML files for SQL API documentation."
5255
mkdocs build --clean

sql/gen-sql-config-docs.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import os
1919
import re
20+
import sys
2021
from collections import namedtuple
2122
from textwrap import dedent
2223

@@ -28,15 +29,19 @@
2829
"SQLConfEntry", ["name", "default", "description", "version"])
2930

3031

31-
def get_public_sql_configs(jvm):
32+
def get_public_sql_configs(jvm, group):
33+
if group == "static":
34+
config_set = jvm.org.apache.spark.sql.api.python.PythonSQLUtils.listStaticSQLConfigs()
35+
else:
36+
config_set = jvm.org.apache.spark.sql.api.python.PythonSQLUtils.listSQLConfigs()
3237
sql_configs = [
3338
SQLConfEntry(
3439
name=_sql_config._1(),
3540
default=_sql_config._2(),
3641
description=_sql_config._3(),
3742
version=_sql_config._4()
3843
)
39-
for _sql_config in jvm.org.apache.spark.sql.api.python.PythonSQLUtils.listSQLConfigs()
44+
for _sql_config in config_set
4045
]
4146
return sql_configs
4247

@@ -112,10 +117,16 @@ def generate_sql_configs_table(sql_configs, path):
112117

113118

114119
if __name__ == "__main__":
120+
if len(sys.argv) != 2:
121+
print("Usage: ./bin/spark-submit sql/gen-sql-config-docs.py <static|runtime>")
122+
sys.exit(-1)
123+
else:
124+
group = sys.argv[1]
125+
115126
jvm = launch_gateway().jvm
116-
sql_configs = get_public_sql_configs(jvm)
127+
sql_configs = get_public_sql_configs(jvm, group)
117128

118129
spark_root_dir = os.path.dirname(os.path.dirname(__file__))
119-
sql_configs_table_path = os.path.join(spark_root_dir, "docs/sql-configs.html")
130+
sql_configs_table_path = os.path.join(spark_root_dir, "docs", group + "-sql-configs.html")
120131

121132
generate_sql_configs_table(sql_configs, path=sql_configs_table_path)

0 commit comments

Comments
 (0)