Skip to content

Commit 5200ef0

Browse files
committed
Simplify dictionary initialization and remove unused method.
1 parent 13c1559 commit 5200ef0

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/ColumnAccessor.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ private[columnar] abstract class BasicColumnAccessor[JvmType](
6363
}
6464

6565
protected def underlyingBuffer = buffer
66-
67-
def getByteBuffer: ByteBuffer =
68-
buffer.duplicate.order(ByteOrder.nativeOrder())
6966
}
7067

7168
private[columnar] class NullColumnAccessor(buffer: ByteBuffer)

sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/compression/compressionSchemes.scala

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -452,31 +452,10 @@ private[columnar] case object DictionaryEncoding extends CompressionScheme {
452452

453453
class Decoder[T <: AtomicType](buffer: ByteBuffer, columnType: NativeColumnType[T])
454454
extends compression.Decoder[T] {
455-
val elementNum = ByteBufferHelper.getInt(buffer)
456-
private val dictionary: Array[Any] = new Array[Any](elementNum)
457-
private var intDictionary: Array[Int] = null
458-
private var longDictionary: Array[Long] = null
459-
460-
columnType.dataType match {
461-
case _: IntegerType =>
462-
intDictionary = new Array[Int](elementNum)
463-
for (i <- 0 until elementNum) {
464-
val v = columnType.extract(buffer).asInstanceOf[Int]
465-
intDictionary(i) = v
466-
dictionary(i) = v
467-
}
468-
case _: LongType =>
469-
longDictionary = new Array[Long](elementNum)
470-
for (i <- 0 until elementNum) {
471-
val v = columnType.extract(buffer).asInstanceOf[Long]
472-
longDictionary(i) = v
473-
dictionary(i) = v
474-
}
475-
case _: StringType =>
476-
for (i <- 0 until elementNum) {
477-
val v = columnType.extract(buffer).asInstanceOf[Any]
478-
dictionary(i) = v
479-
}
455+
456+
private val dictionary: Array[Any] = {
457+
val elementNum = ByteBufferHelper.getInt(buffer)
458+
Array.fill[Any](elementNum)(columnType.extract(buffer).asInstanceOf[Any])
480459
}
481460

482461
override def next(row: InternalRow, ordinal: Int): Unit = {
@@ -495,6 +474,8 @@ private[columnar] case object DictionaryEncoding extends CompressionScheme {
495474
columnType.dataType match {
496475
case _: IntegerType =>
497476
val dictionaryIds = columnVector.reserveDictionaryIds(capacity)
477+
val intDictionary = dictionary.map(_.asInstanceOf[Int])
478+
498479
columnVector.setDictionary(new ColumnDictionary(intDictionary))
499480
while (pos < capacity) {
500481
if (pos != nextNullIndex) {
@@ -508,6 +489,8 @@ private[columnar] case object DictionaryEncoding extends CompressionScheme {
508489
}
509490
case _: LongType =>
510491
val dictionaryIds = columnVector.reserveDictionaryIds(capacity)
492+
val longDictionary = dictionary.map(_.asInstanceOf[Long])
493+
511494
columnVector.setDictionary(new ColumnDictionary(longDictionary))
512495
while (pos < capacity) {
513496
if (pos != nextNullIndex) {

0 commit comments

Comments
 (0)