Skip to content
Closed
Show file tree
Hide file tree
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 @@ -23,6 +23,10 @@ package org.apache.spark.sql.catalyst.expressions
* of the name, or the expected nullability).
*/
object AttributeMap {
def apply[A](kvs: Map[Attribute, A]): AttributeMap[A] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of adding a new API, can the caller side just do AttributeMap(map.toSeq)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would work as well, but AttributeMap(kvs = map.toSeq) will end up calling .toMap down the line.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah got it, this is more efficient

new AttributeMap(kvs.map(kv => (kv._1.exprId, kv)))
}

def apply[A](kvs: Seq[(Attribute, A)]): AttributeMap[A] = {
new AttributeMap(kvs.map(kv => (kv._1.exprId, kv)).toMap)
}
Expand All @@ -37,6 +41,8 @@ class AttributeMap[A](val baseMap: Map[ExprId, (Attribute, A)])

override def get(k: Attribute): Option[A] = baseMap.get(k.exprId).map(_._2)

override def getOrElse[B1 >: A](k: Attribute, default: => B1): B1 = get(k).getOrElse(default)

override def contains(k: Attribute): Boolean = get(k).isDefined

override def + [B1 >: A](kv: (Attribute, B1)): Map[Attribute, B1] = baseMap.values.toMap + kv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ package org.apache.spark.sql.catalyst.expressions
* of the name, or the expected nullability).
*/
object AttributeMap {
def apply[A](kvs: Map[Attribute, A]): AttributeMap[A] = {
new AttributeMap(kvs.map(kv => (kv._1.exprId, kv)))
}

def apply[A](kvs: Seq[(Attribute, A)]): AttributeMap[A] = {
new AttributeMap(kvs.map(kv => (kv._1.exprId, kv)).toMap)
}
Expand All @@ -37,6 +41,8 @@ class AttributeMap[A](val baseMap: Map[ExprId, (Attribute, A)])

override def get(k: Attribute): Option[A] = baseMap.get(k.exprId).map(_._2)

override def getOrElse[B1 >: A](k: Attribute, default: => B1): B1 = get(k).getOrElse(default)

override def contains(k: Attribute): Boolean = get(k).isDefined

override def updated[B1 >: A](key: Attribute, value: B1): Map[Attribute, B1] =
Expand Down
Loading