From c106c7760ea672edc62c5f497bdf975646f3efdf Mon Sep 17 00:00:00 2001 From: Mihailo Milosevic Date: Tue, 27 Aug 2024 13:52:12 +0200 Subject: [PATCH] [SPARK-49017][SQL][TESTS][FOLLOW-UP] Add testing for CreateTableAs with parameters ### What changes were proposed in this pull request? Addition of a test for `CreateTableAsSelect`. ### Why are the changes needed? While looking through parameter marker support in statements it was noticed that CacheTableAsSelect actually should not work with parameter markers, but returns UNBOUND_SQL_PARAMETER. (https://issues.apache.org/jira/browse/SPARK-49398 ticket which should solve this issue). Because of this, I suggest adding additional test for `CreateTableAsSelect` to make sure all paths work as expected. ### Does this PR introduce _any_ user-facing change? No, only tests added. ### How was this patch tested? N/A ### Was this patch authored or co-authored using generative AI tooling? No. Closes #47886 from mihailom-db/follow-up-parameters. Authored-by: Mihailo Milosevic Signed-off-by: Max Gekk --- .../org/apache/spark/sql/ParametersSuite.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala index fcab4a7580445..be3669cc62023 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala @@ -682,6 +682,22 @@ class ParametersSuite extends QueryTest with SharedSparkSession with PlanTest { } } + test("SPARK-49017: bind named parameters with IDENTIFIER clause in create table as") { + withTable("testtab", "testtab1") { + + sql("create table testtab (id int, name string)") + sql("insert into testtab values(1, 'test1')") + + // create table with parameters in query + spark.sql( + """create table identifier(:tab) as + | select * from testtab where identifier(:col) == 1""".stripMargin, + Map("tab" -> "testtab1", "col" -> "id")) + + checkAnswer(sql("select * from testtab1"), Seq(Row(1, "test1"))) + } + } + test("SPARK-46999: bind parameters for nested IDENTIFIER clause") { val query = sql( """