-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-6326][SQL] Improve castStruct to be faster #5017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)) | ||
| i += 1 | ||
| } | ||
| newRow.copy() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It only will be used within the |
||
| }) | ||
| } | ||
|
|
||
| private[this] def cast(from: DataType, to: DataType): Any => Any = to match { | ||
|
|
||
There was a problem hiding this comment.
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)