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 @@ -394,10 +394,17 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w
val casts = from.fields.zip(to.fields).map {
case (fromField, toField) => cast(fromField.dataType, toField.dataType)
}
// TODO: This is very slow!
buildCast[Row](_, row => Row(row.toSeq.zip(casts).map {
case (v, cast) => if (v == null) null else cast(v)
}: _*))
// TODO: Could be faster?
val newRow = new GenericMutableRow(from.fields.size)
buildCast[Row](_, row => {
var i = 0
while (i < row.length) {
val v = row(i)
newRow.update(i, if (v == null) null else casts(i)(v))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: newRow(i) = if (v == null) null else casts(i)(v)

i += 1
}
newRow.copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

just newRow should be OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the returned func has been called multiple times, wouldn't it cause problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

It only will be used within the Cast.eval I think, and the caller( e.g. in Join) will invoke the row.copy if necessary.

})
}

private[this] def cast(from: DataType, to: DataType): Any => Any = to match {
Expand Down