Skip to content

Commit c55c7ea

Browse files
committed
[SPARK-42924][SQL][CONNECT][PYTHON] Clarify the comment of parameterized SQL args
### What changes were proposed in this pull request? In the PR, I propose to clarify the comment of `args` in parameterized `sql()`. ### Why are the changes needed? To make the comment more clear and highlight that input strings are parsed (not evaluated), and considered as SQL literal expressions. Also while parsing the fragments w/ SQL comments in the string values are skipped. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By checking coding style: ``` $ ./dev/lint-python $ ./dev/scalastyle ``` Closes apache#40508 from MaxGekk/parameterized-sql-doc. Authored-by: Max Gekk <[email protected]> Signed-off-by: Max Gekk <[email protected]>
1 parent 62b9763 commit c55c7ea

File tree

8 files changed

+42
-12
lines changed

8 files changed

+42
-12
lines changed

connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/SparkSession.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ class SparkSession private[sql] (
213213
* @param sqlText
214214
* A SQL statement with named parameters to execute.
215215
* @param args
216-
* A map of parameter names to literal values.
216+
* A map of parameter names to string values that are parsed as SQL literal expressions. For
217+
* example, map keys: "rank", "name", "birthdate"; map values: "1", "'Steven'",
218+
* "DATE'2023-03-21'". The fragments of string values belonged to SQL comments are skipped
219+
* while parsing.
217220
*
218221
* @since 3.4.0
219222
*/
@@ -229,7 +232,10 @@ class SparkSession private[sql] (
229232
* @param sqlText
230233
* A SQL statement with named parameters to execute.
231234
* @param args
232-
* A map of parameter names to literal values.
235+
* A map of parameter names to string values that are parsed as SQL literal expressions. For
236+
* example, map keys: "rank", "name", "birthdate"; map values: "1", "'Steven'",
237+
* "DATE'2023-03-21'". The fragments of string values belonged to SQL comments are skipped
238+
* while parsing.
233239
*
234240
* @since 3.4.0
235241
*/

connector/connect/common/src/main/protobuf/spark/connect/commands.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ message SqlCommand {
5353
// (Required) SQL Query.
5454
string sql = 1;
5555

56-
// (Optional) A map of parameter names to literal values.
56+
// (Optional) A map of parameter names to string values that are parsed as
57+
// SQL literal expressions. For example, map keys: "rank", "name", "birthdate";
58+
// map values: "1", "'Steven'", "DATE'2023-03-21'". The fragments of string values
59+
// belonged to SQL comments are skipped while parsing.
5760
map<string, string> args = 2;
5861
}
5962

connector/connect/common/src/main/protobuf/spark/connect/relations.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ message SQL {
108108
// (Required) The SQL query.
109109
string query = 1;
110110

111-
// (Optional) A map of parameter names to literal values.
111+
// (Optional) A map of parameter names to string values that are parsed as
112+
// SQL literal expressions. For example, map keys: "rank", "name", "birthdate";
113+
// map values: "1", "'Steven'", "DATE'2023-03-21'". The fragments of string values
114+
// belonged to SQL comments are skipped while parsing.
112115
map<string, string> args = 2;
113116
}
114117

python/pyspark/pandas/sql_formatter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ def sql(
103103
104104
Also note that the index name(s) should be matched to the existing name.
105105
args : dict
106-
A dictionary of named parameters that begin from the `:` marker and
107-
their SQL literals for substituting.
106+
A dictionary of parameter names to string values that are parsed as SQL literal
107+
expressions. For example, dict keys: "rank", "name", "birthdate"; dict values:
108+
"1", "'Steven'", "DATE'2023-03-21'". The fragments of string values belonged to SQL
109+
comments are skipped while parsing.
108110
109111
.. versionadded:: 3.4.0
110112

python/pyspark/sql/connect/proto/commands_pb2.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ class SqlCommand(google.protobuf.message.Message):
178178
"""(Required) SQL Query."""
179179
@property
180180
def args(self) -> google.protobuf.internal.containers.ScalarMap[builtins.str, builtins.str]:
181-
"""(Optional) A map of parameter names to literal values."""
181+
"""(Optional) A map of parameter names to string values that are parsed as
182+
SQL literal expressions. For example, map keys: "rank", "name", "birthdate";
183+
map values: "1", "'Steven'", "DATE'2023-03-21'". The fragments of string values
184+
belonged to SQL comments are skipped while parsing.
185+
"""
182186
def __init__(
183187
self,
184188
*,

python/pyspark/sql/connect/proto/relations_pb2.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,11 @@ class SQL(google.protobuf.message.Message):
577577
"""(Required) The SQL query."""
578578
@property
579579
def args(self) -> google.protobuf.internal.containers.ScalarMap[builtins.str, builtins.str]:
580-
"""(Optional) A map of parameter names to literal values."""
580+
"""(Optional) A map of parameter names to string values that are parsed as
581+
SQL literal expressions. For example, map keys: "rank", "name", "birthdate";
582+
map values: "1", "'Steven'", "DATE'2023-03-21'". The fragments of string values
583+
belonged to SQL comments are skipped while parsing.
584+
"""
581585
def __init__(
582586
self,
583587
*,

python/pyspark/sql/session.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,10 @@ def sql(self, sqlQuery: str, args: Optional[Dict[str, str]] = None, **kwargs: An
13361336
sqlQuery : str
13371337
SQL query string.
13381338
args : dict
1339-
A dictionary of named parameters that begin from the `:` marker and
1340-
their SQL literals for substituting.
1339+
A dictionary of parameter names to string values that are parsed as SQL literal
1340+
expressions. For example, dict keys: "rank", "name", "birthdate"; dict values:
1341+
"1", "'Steven'", "DATE'2023-03-21'". The fragments of string values belonged to
1342+
SQL comments are skipped while parsing.
13411343
13421344
.. versionadded:: 3.4.0
13431345

sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,10 @@ class SparkSession private(
612612
* This API eagerly runs DDL/DML commands, but not for SELECT queries.
613613
*
614614
* @param sqlText A SQL statement with named parameters to execute.
615-
* @param args A map of parameter names to literal values.
615+
* @param args A map of parameter names to string values that are parsed as
616+
* SQL literal expressions. For example, map keys: "rank", "name", "birthdate";
617+
* map values: "1", "'Steven'", "DATE'2023-03-21'". The fragments of string values
618+
* belonged to SQL comments are skipped while parsing.
616619
*
617620
* @since 3.4.0
618621
*/
@@ -637,7 +640,10 @@ class SparkSession private(
637640
* This API eagerly runs DDL/DML commands, but not for SELECT queries.
638641
*
639642
* @param sqlText A SQL statement with named parameters to execute.
640-
* @param args A map of parameter names to literal values.
643+
* @param args A map of parameter names to string values that are parsed as
644+
* SQL literal expressions. For example, map keys: "rank", "name", "birthdate";
645+
* map values: "1", "'Steven'", "DATE'2023-03-21'". The fragments of string values
646+
* belonged to SQL comments are skipped while parsing.
641647
*
642648
* @since 3.4.0
643649
*/

0 commit comments

Comments
 (0)