trait Encoder[T] extends Serializable
Used to convert a JVM object of type T
to and from the internal Spark SQL representation.
Scala
Encoders are generally created automatically through implicits from a SparkSession
, or can be
explicitly created by calling static methods on Encoders.
import spark.implicits._ val ds = Seq(1, 2, 3).toDS() // implicitly provided (spark.implicits.newIntEncoder)
Java
Encoders are specified by calling static methods on Encoders.
List<String> data = Arrays.asList("abc", "abc", "xyz"); Dataset<String> ds = context.createDataset(data, Encoders.STRING());
Encoders can be composed into tuples:
Encoder<Tuple2<Integer, String>> encoder2 = Encoders.tuple(Encoders.INT(), Encoders.STRING()); List<Tuple2<Integer, String>> data2 = Arrays.asList(new scala.Tuple2(1, "a"); Dataset<Tuple2<Integer, String>> ds2 = context.createDataset(data2, encoder2);
Or constructed from Java Beans:
Encoders.bean(MyClass.class);
Implementation
- Encoders should be thread-safe.
- Annotations
- @implicitNotFound()
- Source
- Encoder.scala
- Since
1.6.0
- Alphabetic
- By Inheritance
- Encoder
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- î
abstract def clsTag: ClassTag[T]
A ClassTag that can be used to construct an Array to contain a collection of
T
. - î
abstract def schema: StructType
Returns the schema of encoding this type of object as a Row.
Concrete Value Members
- î
final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef â Any
- î
final def ##: Int
- Definition Classes
- AnyRef â Any
- î
final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef â Any
- î
final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- î
def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- î
final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- î
def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef â Any
- î
final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef â Any
- Annotations
- @IntrinsicCandidate() @native()
- î
def hashCode(): Int
- Definition Classes
- AnyRef â Any
- Annotations
- @IntrinsicCandidate() @native()
- î
final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- î
final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- î
final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- î
final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- î
final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- î
def toString(): String
- Definition Classes
- AnyRef â Any
- î
final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- î
final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- î
final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- î
def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)