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_r368077732
 
 

 ##########
 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))
+            
assert(insertAssigns(0).value.asInstanceOf[AttributeReference].sameRef(si))
+            
assert(insertAssigns(1).key.asInstanceOf[AttributeReference].sameRef(ts))
+            
assert(insertAssigns(1).value.asInstanceOf[AttributeReference].sameRef(ss))
 
           case _ => fail("Expect MergeIntoTable, but got:\n" + 
parsed1.treeString)
         }
 
         parsed2 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"))), Seq())),
-              Seq(InsertAction(Some(EqualTo(il: UnresolvedAttribute, 
StringLiteral("insert"))),
-                Seq()))) =>
-            assert(l.name == "target.i" && r.name == "source.i")
-            assert(dl.name == "target.s")
-            assert(ul.name == "target.s")
-            assert(il.name == "target.s")
+              SubqueryAlias(AliasIdentifier("target", None), target: 
DataSourceV2Relation),
 
 Review comment:
   nit: It is generally much easier to read the test code when the test input 
is colocated with the asserts. Its not convenient to jump back and forth 
between this test code and the input SQL statement 80 lines above.

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

Reply via email to