LuciferYang commented on a change in pull request #29689:
URL: https://github.com/apache/spark/pull/29689#discussion_r485380596



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/AttributeSet.scala
##########
@@ -105,10 +105,12 @@ class AttributeSet private (private val baseSet: 
mutable.LinkedHashSet[Attribute
    */
   def --(other: Iterable[NamedExpression]): AttributeSet = {
     other match {
+      // SPARK-32755: `--` method behave differently under scala 2.12 and 2.13,
+      // use a Scala 2.12 based code to maintains the insertion order in Scala 
2.13
       case otherSet: AttributeSet =>
-        new AttributeSet(baseSet -- otherSet.baseSet)
+        new AttributeSet(baseSet.clone() --= otherSet.baseSet)

Review comment:
       In Scala 2.13 
   ```
   def diff(that: collection.Set[A]): C =
       toIterable.foldLeft(empty)((result, elem) => if (that contains elem) 
result else result += elem)
   ```
   
   In Scala 2.12
   ```
   def diff(that: GenSet[A]): This = this -- that
   ```
   
   It looks like they're maintains ordered, but the input parameter needs to be 
a `Set`, so 
   
   ```
   other.map(a => new AttributeEquals(a.toAttribute))
   ```
   
   part need call `toSet`。。。




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to