cloud-fan 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_r369399023
##########
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:
on the other hand, this test also verifies the column order after resolving
the star. Maybe good to keep it?
----------------------------------------------------------------
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]