miland-db commented on code in PR #52334:
URL: https://github.com/apache/spark/pull/52334#discussion_r2407241112
##########
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala:
##########
@@ -833,4 +820,867 @@ class ParametersSuite extends QueryTest with
SharedSparkSession {
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))
}
+
+ test("named parameters in DDL data type specifications") {
+ withTable("ddl_datatype_named") {
+ // Test VARCHAR length parameter
+ spark.sql("CREATE TABLE ddl_datatype_named (name VARCHAR(:length)) USING
PARQUET",
+ Map("length" -> 100))
+ val schema = spark.table("ddl_datatype_named").schema
+ checkColType(schema("name"), VarcharType(100))
+ }
+
+ withTable("ddl_decimal_named") {
+ // Test DECIMAL precision and scale parameters
+ spark.sql(
+ "CREATE TABLE ddl_decimal_named (amount DECIMAL(:precision, :scale))
USING PARQUET",
+ Map("precision" -> 10, "scale" -> 2))
+ val schema = spark.table("ddl_decimal_named").schema
+ assert(schema("amount").dataType == DecimalType(10, 2))
+ }
+
+ withTable("ddl_char_named") {
+ // Test CHAR length parameter
+ spark.sql("CREATE TABLE ddl_char_named (code CHAR(:length)) USING
PARQUET",
+ Map("length" -> 5))
+ val schema = spark.table("ddl_char_named").schema
+ checkColType(schema("code"), CharType(5))
+ }
+ }
+
+ test("positional parameters in DDL data type specifications") {
+ withTable("ddl_datatype_pos") {
+ // Test VARCHAR length parameter
+ spark.sql("CREATE TABLE ddl_datatype_pos (name VARCHAR(?)) USING
PARQUET",
+ Array(150))
+ val schema = spark.table("ddl_datatype_pos").schema
+ checkColType(schema("name"), VarcharType(150))
+ }
+
+ withTable("ddl_decimal_pos") {
+ // Test DECIMAL precision and scale parameters
+ spark.sql(
+ "CREATE TABLE ddl_decimal_pos (amount DECIMAL(?, ?)) USING PARQUET",
+ Array(12, 3))
+ val schema = spark.table("ddl_decimal_pos").schema
+ assert(schema("amount").dataType == DecimalType(12, 3))
+ }
+
+ withTable("ddl_char_pos") {
+ // Test CHAR length parameter
+ spark.sql("CREATE TABLE ddl_char_pos (code CHAR(?)) USING PARQUET",
+ Array(8))
+ val schema = spark.table("ddl_char_pos").schema
+ checkColType(schema("code"), CharType(8))
+ }
+ }
+
+
Review Comment:
nit: empty lines
--
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]