tdas commented on a change in pull request #27265: [SPARK-30555][SQL] MERGE
INTO insert action should only access columns from source table
URL: https://github.com/apache/spark/pull/27265#discussion_r369277343
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala
##########
@@ -1055,6 +1060,49 @@ class PlanResolutionSuite extends AnalysisTest {
}
test("MERGE INTO TABLE") {
+ def checkResolution(
+ target: LogicalPlan,
+ source: LogicalPlan,
+ mergeCondition: Expression,
+ deleteCondAttr: Option[AttributeReference],
+ updateCondAttr: Option[AttributeReference],
+ insertCondAttr: Option[AttributeReference],
+ updateAssigns: Seq[Assignment],
+ insertAssigns: Seq[Assignment],
+ starInUpdate: Boolean = false): Unit = {
+ val ti = target.output.find(_.name ==
"i").get.asInstanceOf[AttributeReference]
+ val ts = target.output.find(_.name ==
"s").get.asInstanceOf[AttributeReference]
+ val si = source.output.find(_.name ==
"i").get.asInstanceOf[AttributeReference]
+ val ss = source.output.find(_.name ==
"s").get.asInstanceOf[AttributeReference]
+
+ mergeCondition match {
+ case EqualTo(l: AttributeReference, r: AttributeReference) =>
+ assert(l.sameRef(ti) && r.sameRef(si))
+ case other => fail("unexpected merge condition" + other)
+ }
+
+ deleteCondAttr.foreach(a => assert(a.sameRef(ts)))
+ updateCondAttr.foreach(a => assert(a.sameRef(ts)))
+ insertCondAttr.foreach(a => assert(a.sameRef(ss)))
+
+ if (starInUpdate) {
+ assert(updateAssigns.size == 2)
+
assert(updateAssigns(0).key.asInstanceOf[AttributeReference].sameRef(ti))
Review comment:
super nit: I suggest making these tests a bit more robust by not depending
on the order of columns. Changes in the resolving of the star can easily change
the order of columns and expressions, and will unnecessarily fail the tests.
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]