Skip to content

Commit d577cc7

Browse files
committed
Scaladoc
1 parent cae5d22 commit d577cc7

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/AttributeSet.scala

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.sql.catalyst.expressions
1919

20-
class AttributeEquals(val a: Attribute) {
20+
protected class AttributeEquals(val a: Attribute) {
2121
override def hashCode() = a.exprId.hashCode()
2222
override def equals(other: Any) = other match {
2323
case otherReference: AttributeEquals => a.exprId == otherReference.a.exprId
@@ -26,47 +26,71 @@ class AttributeEquals(val a: Attribute) {
2626
}
2727

2828
object AttributeSet {
29+
/** Constructs a new [[AttributeSet]] given a sequence of [[Attribute Attributes]]. */
2930
def apply(baseSet: Seq[Attribute]) = {
3031
new AttributeSet(baseSet.map(new AttributeEquals(_)).toSet)
3132
}
32-
33-
// def apply(baseSet: Set[Attribute]) = {
34-
// new AttributeSet(baseSet.map(new AttributeEquals(_)))
35-
// }
3633
}
3734

38-
class AttributeSet(val baseSet: Set[AttributeEquals]) extends Traversable[Attribute] {
35+
/**
36+
* A Set designed to hold [[AttributeReference]] objects, that performs equality checking using
37+
* expression id instead of standard java equality. Using expression id means that these
38+
* sets will correctly test for membership, even when the AttributeReferences in question differ
39+
* cosmetically (e.g., the names have different capitalizations).
40+
*/
41+
class AttributeSet protected (val baseSet: Set[AttributeEquals]) extends Traversable[Attribute] {
3942

43+
/** Returns true if the members of this AttributeSet and other are the same. */
4044
override def equals(other: Any) = other match {
4145
case otherSet: AttributeSet => baseSet.map(_.a).forall(otherSet.contains)
4246
case _ => false
4347
}
4448

49+
/** Returns true if this set contains an Attribute with the same expression id as `elem` */
4550
def contains(elem: NamedExpression): Boolean =
4651
baseSet.contains(new AttributeEquals(elem.toAttribute))
4752

53+
/** Returns a new [[AttributeSet]] that contains `elem` in addition to the current elements. */
4854
def +(elem: Attribute): AttributeSet =
4955
new AttributeSet(baseSet + new AttributeEquals(elem))
5056

57+
/** Returns a new [[AttributeSet]] that does not contain `elem`. */
5158
def -(elem: Attribute): AttributeSet =
5259
new AttributeSet(baseSet - new AttributeEquals(elem))
5360

61+
/** Returns an iterator containing all of the attributes in the set. */
5462
def iterator: Iterator[Attribute] = baseSet.map(_.a).iterator
5563

64+
/**
65+
* Returns true if the [[Attribute Attributes]] in this set are a subset of the Attributes in
66+
* `other`.
67+
*/
5668
def subsetOf(other: AttributeSet) = baseSet.subsetOf(other.baseSet)
5769

70+
/**
71+
* Returns a new [[AttributeSet]] that does not contain any of the [[Attribute Attributes]] found
72+
* in `other`.
73+
*/
5874
def --(other: Traversable[NamedExpression]) =
5975
new AttributeSet(baseSet -- other.map(a => new AttributeEquals(a.toAttribute)))
6076

77+
/**
78+
* Returns a new [[AttributeSet]] that contains all of the [[Attribute Attributes]] found
79+
* in `other`.
80+
*/
6181
def ++(other: AttributeSet) = new AttributeSet(baseSet ++ other.baseSet)
6282

83+
/**
84+
* Returns a new [[AttributeSet]] contain only the [[Attribute Attributes]] where `f` evaluates to
85+
* true.
86+
*/
6387
override def filter(f: Attribute => Boolean) = new AttributeSet(baseSet.filter(ae => f(ae.a)))
6488

89+
/**
90+
* Returns a new [[AttributeSet]] that only contains [[Attribute Attributes]] that are found in
91+
* `this` and `other`.
92+
*/
6593
def intersect(other: AttributeSet) = new AttributeSet(baseSet.intersect(other.baseSet))
6694

67-
override def nonEmpty = baseSet.nonEmpty
68-
69-
override def toSeq = baseSet.toSeq.map(_.a)
70-
7195
override def foreach[U](f: (Attribute) => U): Unit = baseSet.map(_.a).foreach(f)
72-
}
96+
}

0 commit comments

Comments
 (0)