AngersZhuuuu commented on a change in pull request #29414:
URL: https://github.com/apache/spark/pull/29414#discussion_r469772903



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala
##########
@@ -1031,4 +1031,115 @@ class PlanParserSuite extends AnalysisTest {
     assertEqual("select a, b from db.c;;;", table("db", "c").select('a, 'b))
     assertEqual("select a, b from db.c; ;;  ;", table("db", "c").select('a, 
'b))
   }
+
+  test("SPARK-32106: TRANSFORM plan") {
+    // verify schema less
+    assertEqual(
+      """
+        |SELECT TRANSFORM(a, b, c)
+        |USING 'cat'
+        |FROM testData
+      """.stripMargin,
+      ScriptTransformation(
+        Seq('a, 'b, 'c),
+        "cat",
+        Seq(AttributeReference("key", StringType)(),
+          AttributeReference("value", StringType)()),
+        UnresolvedRelation(TableIdentifier("testData")),
+        ScriptInputOutputSchema(List.empty, List.empty, None, None,
+          List.empty, List.empty, None, None, true))
+    )
+
+    // verify without output schema
+    assertEqual(
+      """
+        |SELECT TRANSFORM(a, b, c)
+        |USING 'cat' AS (a, b, c)
+        |FROM testData
+      """.stripMargin,
+      ScriptTransformation(
+        Seq('a, 'b, 'c),
+        "cat",
+        Seq(AttributeReference("a", StringType)(),
+          AttributeReference("b", StringType)(),
+          AttributeReference("c", StringType)()),
+        UnresolvedRelation(TableIdentifier("testData")),
+        ScriptInputOutputSchema(List.empty, List.empty, None, None,
+          List.empty, List.empty, None, None, false)))
+
+    // verify with output schema
+    assertEqual(
+      """
+        |SELECT TRANSFORM(a, b, c)
+        |USING 'cat' AS (a int, b string, c long)
+        |FROM testData
+      """.stripMargin,
+      ScriptTransformation(
+        Seq('a, 'b, 'c),
+        "cat",
+        Seq(AttributeReference("a", IntegerType)(),
+          AttributeReference("b", StringType)(),
+          AttributeReference("c", LongType)()),
+        UnresolvedRelation(TableIdentifier("testData")),
+        ScriptInputOutputSchema(List.empty, List.empty, None, None,
+          List.empty, List.empty, None, None, false)))
+
+    // verify with ROW FORMAT DELIMETED
+    assertEqual(
+      """
+        |SELECT TRANSFORM(a, b, c)
+        |ROW FORMAT DELIMITED
+        |FIELDS TERMINATED BY '\t'
+        |COLLECTION ITEMS TERMINATED BY '\u0002'
+        |MAP KEYS TERMINATED BY '\u0003'
+        |LINES TERMINATED BY '\n'
+        |NULL DEFINED AS 'null'
+        |USING 'cat' AS (a, b, c)
+        |ROW FORMAT DELIMITED
+        |FIELDS TERMINATED BY '\t'
+        |COLLECTION ITEMS TERMINATED BY '\u0004'
+        |MAP KEYS TERMINATED BY '\u0005'
+        |LINES TERMINATED BY '\n'
+        |NULL DEFINED AS 'NULL'
+        |FROM testData
+      """.stripMargin,

Review comment:
       > SELECT TRANSFORM(a, b, c)
   >   ROW FORMAT DELIMITED
   >   FIELDS TERMINATED BY '\t'
   >   COLLECTION ITEMS TERMINATED BY '\u0002'
   >   MAP KEYS TERMINATED BY '\u0003'
   >   LINES TERMINATED BY '\n'
   >   NULL DEFINED AS 'null'
   >   USING 'cat' AS (a, b, c)
   >   ROW FORMAT DELIMITED
   >   FIELDS TERMINATED BY '\t'
   >   COLLECTION ITEMS TERMINATED BY '\u0004'
   >   MAP KEYS TERMINATED BY '\u0005'
   >   LINES TERMINATED BY '\n'
   >   NULL DEFINED AS 'NULL'
   > FROM testData
   
   How about make `USING` clause without indents?
   ```
   SELECT TRANSFORM(a, b, c)
     ROW FORMAT DELIMITED
     FIELDS TERMINATED BY '\t'
     COLLECTION ITEMS TERMINATED BY '\u0002'
     MAP KEYS TERMINATED BY '\u0003'
     LINES TERMINATED BY '\n'
     NULL DEFINED AS 'null'
   USING 'cat' AS (a, b, c)
     ROW FORMAT DELIMITED
     FIELDS TERMINATED BY '\t'
     COLLECTION ITEMS TERMINATED BY '\u0004'
     MAP KEYS TERMINATED BY '\u0005'
     LINES TERMINATED BY '\n'
     NULL DEFINED AS 'NULL'
   FROM testData
   ```




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

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