Skip to content
Closed
Changes from 1 commit
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 @@ -84,17 +84,27 @@ object BindReferences extends Logging {
expression: A,
input: Seq[Attribute],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder whether we can push the map construction up one level so that we can amortize its cost across multiple bindReference calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, yeah: in GenerateMutableProjection we use the same InputSchema for every expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should add an overload which takes a sequence of expressions and binds all of their references. We should then replace the call sites in the various projection operators.

allowFailures: Boolean = false): A = {
val inputArr = input.toArray
val inputToOrdinal = {
val map = new java.util.HashMap[ExprId, Int](inputArr.length * 2)
var index = 0
input.foreach { attr =>
map.putIfAbsent(attr.exprId, index)
index += 1
}
map
}
expression.transform { case a: AttributeReference =>
attachTree(a, "Binding attribute") {
val ordinal = input.indexWhere(_.exprId == a.exprId)
val ordinal = inputToOrdinal.getOrDefault(a.exprId, -1)
if (ordinal == -1) {
if (allowFailures) {
a
} else {
sys.error(s"Couldn't find $a in ${input.mkString("[", ",", "]")}")
}
} else {
BoundReference(ordinal, a.dataType, input(ordinal).nullable)
BoundReference(ordinal, a.dataType, inputArr(ordinal).nullable)
}
}
}.asInstanceOf[A] // Kind of a hack, but safe. TODO: Tighten return type when possible.
Expand Down