Github user rdblue commented on a diff in the pull request:
https://github.com/apache/spark/pull/21911#discussion_r206741523
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala
---
@@ -660,6 +660,62 @@ class PlanParserSuite extends AnalysisTest {
)
}
+ test ("insert hint syntax") {
+ assertEqual(
+ "INSERT INTO s /*+ COALESCE(10) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("COALESCE", Seq(Literal(10)),
+ table("t").select(star())), false, false))
+ assertEqual(
+ "INSERT INTO TABLE s /*+ COALESCE(50, true) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("COALESCE", Seq(Literal(50), Literal(true)),
+ table("t").select(star())), false, false))
+ assertEqual(
+ "INSERT INTO s /*+ REPARTITION(100) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("REPARTITION", Seq(Literal(100)),
+ table("t").select(star())), false, false))
+ assertEqual(
+ "INSERT INTO TABLE s /*+ REPARTITION(20, false) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("REPARTITION", Seq(Literal(20), Literal(false)),
+ table("t").select(star())), false, false))
+ assertEqual(
+ "INSERT OVERWRITE TABLE s /*+ COALESCE(10) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("COALESCE", Seq(Literal(10)),
+ table("t").select(star())), true, false))
+ assertEqual(
+ "INSERT OVERWRITE TABLE s /*+ COALESCE(50, true) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("COALESCE", Seq(Literal(50), Literal(true)),
+ table("t").select(star())), true, false))
+ assertEqual(
+ "INSERT OVERWRITE TABLE s /*+ REPARTITION(100) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("REPARTITION", Seq(Literal(100)),
+ table("t").select(star())), true, false))
+ assertEqual(
+ "INSERT OVERWRITE TABLE s /*+ REPARTITION(20, false) */ SELECT *
FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("REPARTITION", Seq(Literal(20), Literal(false)),
+ table("t").select(star())), true, false))
+
+ // Multiple hints
+ assertEqual(
+ "INSERT INTO s /*+ REPARTITION(100), COALESCE(50, true),
COALESCE(10) */ SELECT * FROM t",
+ InsertIntoTable(table("s"), Map.empty,
+ UnresolvedHint("REPARTITION", Seq(Literal(100)),
+ UnresolvedHint("COALESCE", Seq(Literal(50), Literal(true)),
+ UnresolvedHint("COALESCE", Seq(Literal(10)),
+ table("t").select(star())))), false, false))
+
+ // Wrong hint location
+ intercept("INSERT INTO /*+ COALESCE(10) */ s SELECT * FROM t",
+ "extraneous input '/*+' expecting")
--- End diff --
I don't think it is necessary to test the wrong hint location because there
are so many wrong hint locations and the error is just a generic parse error.
If there were a friendly error message, that would be worth a test case.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]