ganeshashree commented on code in PR #60303:
URL: https://github.com/apache/spark/pull/60303#discussion_r4534301847


##########
sql/core/src/test/scala/org/apache/spark/sql/JsonArraySuite.scala:
##########
@@ -386,6 +387,32 @@ class JsonArraySuite extends QueryTest with 
SharedSparkSession {
       "JSON_ARRAY(CAST(JSON_ARRAY(1 RETURNING STRING) AS STRING) RETURNING 
STRING)")
   }
 
+  test("SPARK-59243: SQL of a spliced aliased child drops the alias") {
+    val inner = JsonArray(
+      Seq(Literal(1)), Seq(false), Seq(false), 
JsonConstructorNullBehavior.Absent, StringType)
+    val aliased = JsonArray(
+      Seq(Alias(inner, "x")()), Seq(true), Seq(false), 
JsonConstructorNullBehavior.Absent,
+      StringType)
+    assert(aliased.sql == "JSON_ARRAY(JSON_ARRAY(1 RETURNING STRING) RETURNING 
STRING)")
+    checkAnswer(sql(s"SELECT ${aliased.sql}"), Row("[[1]]"))
+    val literal = JsonArray(
+      Seq(Alias(Literal("[1]"), "x")()), Seq(true), Seq(true), 
JsonConstructorNullBehavior.Absent,
+      StringType)
+    assert(literal.sql == "JSON_ARRAY('[1]' FORMAT JSON)")
+    val collated = JsonArray(
+      Seq(Collate(Alias(inner, "x")(), ResolvedCollation("UTF8_LCASE"))), 
Seq(true), Seq(false),
+      JsonConstructorNullBehavior.Absent, StringType)
+    assert(collated.sql ==
+      "JSON_ARRAY(collate(JSON_ARRAY(1 RETURNING STRING), UTF8_LCASE) FORMAT 
JSON)")
+    // The column name drops the alias too; a user cast still quotes and keeps 
it.
+    val df = spark.range(1).select(call_function("json_array", 
expr("json_array(1)").as("x")))
+    assert(df.columns.toSeq == Seq("JSON_ARRAY(JSON_ARRAY(1))"))
+    checkAnswer(

Review Comment:
   Thanks, done in bbcb15c1df6. The user-cast case in `JsonArraySuite` now 
asserts the column name is `JSON_ARRAY(CAST(JSON_ARRAY(1) AS STRING) AS x)`, 
and the one in `JsonObjectSuite` asserts it contains `" AS x"`. With the 
spliced-only condition removed from both renderers, both tests fail on these 
assertions; with it restored, they pass.



-- 
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]

Reply via email to