org.apache.spark.sql.catalyst.expressions.SpecializedGetters Scala Examples
The following examples show how to use org.apache.spark.sql.catalyst.expressions.SpecializedGetters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: ArrayData.scala From XSQL with Apache License 2.0 | 5 votes |
package org.apache.spark.sql.catalyst.util import scala.reflect.ClassTag import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.expressions.{SpecializedGetters, UnsafeArrayData} import org.apache.spark.sql.types._ import org.apache.spark.unsafe.Platform import org.apache.spark.unsafe.array.ByteArrayMethods object ArrayData { def toArrayData(input: Any): ArrayData = input match { case a: Array[Boolean] => UnsafeArrayData.fromPrimitiveArray(a) case a: Array[Byte] => UnsafeArrayData.fromPrimitiveArray(a) case a: Array[Short] => UnsafeArrayData.fromPrimitiveArray(a) case a: Array[Int] => UnsafeArrayData.fromPrimitiveArray(a) case a: Array[Long] => UnsafeArrayData.fromPrimitiveArray(a) case a: Array[Float] => UnsafeArrayData.fromPrimitiveArray(a) case a: Array[Double] => UnsafeArrayData.fromPrimitiveArray(a) case other => new GenericArrayData(other) } class ArrayDataIndexedSeq[T](arrayData: ArrayData, dataType: DataType) extends IndexedSeq[T] { private val accessor: (SpecializedGetters, Int) => Any = InternalRow.getAccessor(dataType) override def apply(idx: Int): T = if (0 <= idx && idx < arrayData.numElements()) { if (arrayData.isNullAt(idx)) { null.asInstanceOf[T] } else { accessor(arrayData, idx).asInstanceOf[T] } } else { throw new IndexOutOfBoundsException( s"Index $idx must be between 0 and the length of the ArrayData.") } override def length: Int = arrayData.numElements() }