All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.spark.connector.TupleValue.scala Maven / Gradle / Ivy

There is a newer version: 3.0.0-alpha2
Show newest version
package com.datastax.spark.connector

import scala.reflect.runtime.universe._

import org.apache.spark.sql.catalyst.ReflectionLock.SparkReflectionLock

import com.datastax.driver.core.{TupleValue => DriverTupleValue}
import com.datastax.spark.connector.types.NullableTypeConverter

final case class TupleValue(values: Any*) extends ScalaGettableByIndexData with Product {
  override def columnValues = values.toIndexedSeq.map(_.asInstanceOf[AnyRef])

  override def productArity: Int = columnValues.size

  override def productElement(n: Int): Any = getRaw(n)
}

object TupleValue {

  def fromJavaDriverTupleValue
      (value: DriverTupleValue)
      : TupleValue = {
    val values =
      for (i <- 0 until value.getType.getComponentTypes.size()) yield
        GettableData.get(value, i)
    new TupleValue(values: _*)
  }

  val TypeTag = SparkReflectionLock.synchronized(typeTag[TupleValue])
  val Symbol = SparkReflectionLock.synchronized(typeOf[TupleValue].asInstanceOf[TypeRef].sym)

  implicit object TupleValueConverter extends NullableTypeConverter[TupleValue] {
    def targetTypeTag = TypeTag
    def convertPF = {
      case x: TupleValue => x
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy