Skip to content

Commit a906647

Browse files
viiryahvanhovell
authored andcommitted
[SPARK-23875][SQL][FOLLOWUP] Add IndexedSeq wrapper for ArrayData
## What changes were proposed in this pull request? Use specified accessor in `ArrayData.foreach` and `toArray`. ## How was this patch tested? Existing tests. Author: Liang-Chi Hsieh <[email protected]> Closes apache#21099 from viirya/SPARK-23875-followup.
1 parent f09a9e9 commit a906647

File tree

1 file changed

+4
-3
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util

1 file changed

+4
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/ArrayData.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,29 @@ abstract class ArrayData extends SpecializedGetters with Serializable {
141141

142142
def toArray[T: ClassTag](elementType: DataType): Array[T] = {
143143
val size = numElements()
144+
val accessor = InternalRow.getAccessor(elementType)
144145
val values = new Array[T](size)
145146
var i = 0
146147
while (i < size) {
147148
if (isNullAt(i)) {
148149
values(i) = null.asInstanceOf[T]
149150
} else {
150-
values(i) = get(i, elementType).asInstanceOf[T]
151+
values(i) = accessor(this, i).asInstanceOf[T]
151152
}
152153
i += 1
153154
}
154155
values
155156
}
156157

157-
// todo: specialize this.
158158
def foreach(elementType: DataType, f: (Int, Any) => Unit): Unit = {
159159
val size = numElements()
160+
val accessor = InternalRow.getAccessor(elementType)
160161
var i = 0
161162
while (i < size) {
162163
if (isNullAt(i)) {
163164
f(i, null)
164165
} else {
165-
f(i, get(i, elementType))
166+
f(i, accessor(this, i))
166167
}
167168
i += 1
168169
}

0 commit comments

Comments
 (0)