-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cde31de
commit 1d73104
Showing
5 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
# NameParameterizedQuery | ||
--- | ||
title: NameParameterizedQuery | ||
--- | ||
|
||
`NameParameterizedQuery` is...FIXME | ||
# NameParameterizedQuery Unary Logical Operator | ||
|
||
`NameParameterizedQuery` is a [ParameterizedQuery](ParameterizedQuery.md) logical operator that represents a parameterized query with named parameters. | ||
|
||
## Creating Instance | ||
|
||
`NameParameterizedQuery` takes the following to be created: | ||
|
||
* <span id="child"> Child [LogicalPlan](LogicalPlan.md) | ||
* <span id="args"> Arguments (`Map[String, Expression]`) | ||
|
||
`NameParameterizedQuery` is created when: | ||
|
||
* `SparkConnectPlanner` is requested to [transformSql](../connect/SparkConnectPlanner.md#transformSql) | ||
* `SparkSession` is requested to [sql](../SparkSession.md#sql) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
# ParameterizedQuery | ||
--- | ||
title: ParameterizedQuery | ||
--- | ||
|
||
`ParameterizedQuery` is...FIXME | ||
# ParameterizedQuery Unary Logical Operators | ||
|
||
`ParameterizedQuery` is a marker extension of the `UnresolvedUnaryNode` abstraction for [unary logical operators](#implementations) with the [PARAMETERIZED_QUERY](#nodePatterns) tree node pattern. | ||
|
||
## Implementations | ||
|
||
* [NameParameterizedQuery](NameParameterizedQuery.md) | ||
* `PosParameterizedQuery` | ||
|
||
## Creating Instance | ||
|
||
`ParameterizedQuery` takes the following to be created: | ||
|
||
* <span id="child"> Child [LogicalPlan](LogicalPlan.md) (_unused_) | ||
|
||
!!! note "Abstract Class" | ||
`ParameterizedQuery` is an abstract class and cannot be created directly. It is created indirectly for the [concrete ParameterizedQueries](#implementations). | ||
|
||
## Node Patterns { #nodePatterns } | ||
|
||
??? note "TreeNode" | ||
|
||
```scala | ||
nodePatterns: Seq[TreePattern] | ||
``` | ||
|
||
`nodePatterns` is part of the [TreeNode](../catalyst/TreeNode.md#nodePatterns) abstraction. | ||
|
||
`nodePatterns` is just a single [PARAMETERIZED_QUERY](../catalyst/TreePattern.md#PARAMETERIZED_QUERY). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
--- | ||
status: new | ||
--- | ||
# Parameterized Queries | ||
|
||
# Parameterized Queries :material-new-box:{ title="New in 3.5.0" } | ||
**Parameterized Queries** (_Parameterized SQL_) allows Spark SQL developers to write SQL statements with parameter markers to be bound at execution time with parameters (literals) by name or position. | ||
|
||
[BindParameters Logical Analysis Rule](../logical-analysis-rules/BindParameters.md) | ||
Parameterized Queries are supposed to improve security and reusability, and help preventing SQL injection attacks for applications that generate SQL at runtime (e.g., based on a user's selections, which is often done via a user interface). | ||
|
||
Parameterized Queries supports named and positional parameters. [SQL parser](../SessionState.md#sqlParser) can recognize them using the following: | ||
|
||
* `:` (colon) followed by name for named parameters | ||
* `?` (question mark) for positional parameters | ||
|
||
=== "Named Parameters" | ||
|
||
```sql | ||
WITH a AS (SELECT 1 c) | ||
SELECT * | ||
FROM a | ||
LIMIT :limitA | ||
``` | ||
|
||
=== "Positional Parameters" | ||
|
||
```sql | ||
WITH a AS (SELECT 1 c) | ||
SELECT * | ||
FROM a | ||
LIMIT ? | ||
``` | ||
|
||
Parameterized Queries are executed using [SparkSession.sql](../SparkSession.md#sql) operator (marked as experimental). | ||
|
||
```scala | ||
sql( | ||
sqlText: String, | ||
args: Map[String, Any]): DataFrame | ||
``` | ||
|
||
Parameterized Queries feature was introduced in [\[SPARK-41271\] Parameterized SQL]({{ spark.jira }}/SPARK-41271). | ||
|
||
## Internals | ||
|
||
* [BindParameters Logical Analysis Rule](../logical-analysis-rules/BindParameters.md) | ||
* [ParameterizedQuery](../logical-operators/ParameterizedQuery.md) logical unary nodes |