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_r368078637
########## File path: sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala ########## @@ -1127,128 +1130,150 @@ class PlanResolutionSuite extends AnalysisTest { parsed1 match { case MergeIntoTable( - SubqueryAlias(AliasIdentifier("target", None), _: DataSourceV2Relation), - SubqueryAlias(AliasIdentifier("source", None), _: DataSourceV2Relation), - EqualTo(l: UnresolvedAttribute, r: UnresolvedAttribute), - Seq(DeleteAction(Some(EqualTo(dl: UnresolvedAttribute, StringLiteral("delete")))), - UpdateAction(Some(EqualTo(ul: UnresolvedAttribute, StringLiteral("update"))), + SubqueryAlias(AliasIdentifier("target", None), target: DataSourceV2Relation), + SubqueryAlias(AliasIdentifier("source", None), source: DataSourceV2Relation), + EqualTo(l: AttributeReference, r: AttributeReference), + Seq(DeleteAction(Some(EqualTo(dl: AttributeReference, StringLiteral("delete")))), + UpdateAction(Some(EqualTo(ul: AttributeReference, StringLiteral("update"))), updateAssigns)), - Seq(InsertAction(Some(EqualTo(il: UnresolvedAttribute, StringLiteral("insert"))), + Seq(InsertAction(Some(EqualTo(il: AttributeReference, StringLiteral("insert"))), insertAssigns))) => - assert(l.name == "target.i" && r.name == "source.i") - assert(dl.name == "target.s") - assert(ul.name == "target.s") - assert(il.name == "target.s") + val ti = target.output.find(_.name == "i").get + val ts = target.output.find(_.name == "s").get + val si = source.output.find(_.name == "i").get + val ss = source.output.find(_.name == "s").get + + assert(l.sameRef(ti) && r.sameRef(si)) + assert(dl.sameRef(ts)) + assert(ul.sameRef(ts)) + assert(il.sameRef(ts)) assert(updateAssigns.size == 1) - assert(updateAssigns.head.key.isInstanceOf[UnresolvedAttribute] && - updateAssigns.head.key.asInstanceOf[UnresolvedAttribute].name == "target.s") - assert(updateAssigns.head.value.isInstanceOf[UnresolvedAttribute] && - updateAssigns.head.value.asInstanceOf[UnresolvedAttribute].name == "source.s") + assert(updateAssigns.head.key.asInstanceOf[AttributeReference].sameRef(ts)) + assert(updateAssigns.head.value.asInstanceOf[AttributeReference].sameRef(ss)) assert(insertAssigns.size == 2) - assert(insertAssigns.head.key.isInstanceOf[UnresolvedAttribute] && - insertAssigns.head.key.asInstanceOf[UnresolvedAttribute].name == "target.i") - assert(insertAssigns.head.value.isInstanceOf[UnresolvedAttribute] && - insertAssigns.head.value.asInstanceOf[UnresolvedAttribute].name == "source.i") + assert(insertAssigns(0).key.asInstanceOf[AttributeReference].sameRef(ti)) Review comment: nit: there is a lot of code that can be deduped here. Would improve the readability a lot. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org