Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

@LuciferYang LuciferYang Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Scala 2.12 the implementation of -- is

 override def --(xs: GenTraversableOnce[A]): This = clone() --= xs.seq

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff method is defined as Computes the difference of this set and another set, I haven't tested overall behavior of diff, but I think the current changes don't look complicated either

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff returns a set, so it can potentially mess up the ordering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
@hvanhovell Actually, diff returns LinkedHashSet[AttributeEquals] here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then diff looks better.

Copy link
Contributor

@hvanhovell hvanhovell Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can avoid the conversion it would be nice. The current thing would be fine in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversion seems inevitable if use diff :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the current method then :).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok ~

case _ =>
new AttributeSet(baseSet -- other.map(a => new AttributeEquals(a.toAttribute)))
new AttributeSet(baseSet.clone() --= other.map(a => new AttributeEquals(a.toAttribute)))
}
}

Expand Down