diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/AttributeSet.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/AttributeSet.scala index e43a9a8c46143..b059e4f849664 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/AttributeSet.scala +++ b/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) case _ => - new AttributeSet(baseSet -- other.map(a => new AttributeEquals(a.toAttribute))) + new AttributeSet(baseSet.clone() --= other.map(a => new AttributeEquals(a.toAttribute))) } }