MaxGekk commented on code in PR #49442:
URL: https://github.com/apache/spark/pull/49442#discussion_r1914719145
##########
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala:
##########
@@ -769,4 +769,33 @@ class ParametersSuite extends QueryTest with
SharedSparkSession with PlanTest {
checkAnswer(spark.sql(query(":cte"), args = Map("cte" -> "t1")), Row(1))
checkAnswer(spark.sql(query("?"), args = Array("t1")), Row(1))
}
+
+ test("SPARK-50403: parameterized execute immediate") {
+ checkAnswer(spark.sql("execute immediate 'select ?' using ?", Array(1)),
Row(1))
+ checkAnswer(spark.sql("execute immediate 'select ?, ?' using ?, 2",
Array(1)), Row(1, 2))
+ checkError(
+ exception = intercept[AnalysisException] {
+ spark.sql("execute immediate 'select ?, ?' using 1", Array(2))
+ },
+ condition = "UNBOUND_SQL_PARAMETER",
+ parameters = Map("name" -> "_10"),
+ context = ExpectedContext("?", 10, 10))
+
+ checkAnswer(spark.sql("execute immediate 'select :param1' using :param2 as
param1",
+ Map("param2" -> 42)), Row(42))
+ checkAnswer(spark.sql(
+ "execute immediate 'select :param1, :param2' using :param2 as param1, 43
as param2",
+ Map("param2" -> 42)), Row(42, 43))
+ checkError(
+ exception = intercept[AnalysisException] {
+ spark.sql("execute immediate 'select :param1, :param2' using 1 as
param1",
+ Map("param2" -> 2))
+ },
+ condition = "UNBOUND_SQL_PARAMETER",
+ parameters = Map("name" -> "param2"),
+ context = ExpectedContext(":param2", 16, 22))
+
+ checkAnswer(spark.sql("execute immediate 'select ?' using :param",
Map("param" -> 2)), Row(2))
+ checkAnswer(spark.sql("execute immediate 'select :param' using ? as
param", Array(3)), Row(3))
Review Comment:
Just in case, going to add the test cases:
```scala
checkAnswer(spark.sql("execute immediate 'select :param' using 0 as
param",
Map("param" -> 42)), Row(0))
checkAnswer(spark.sql("execute immediate 'select ?' using 1",
Map("param1" -> "1")), Row(1))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]