case class ExpressionEncoder[T](objSerializer: Expression, objDeserializer: Expression, clsTag: ClassTag[T]) extends Encoder[T] with Product with Serializable
A generic encoder for JVM objects that uses Catalyst Expressions for a serializer
and a deserializer.
- objSerializer
An expression that can be used to encode a raw object to corresponding Spark SQL representation that can be a primitive column, array, map or a struct. This represents how Spark SQL generally serializes an object of type
T.- objDeserializer
An expression that will construct an object given a Spark SQL representation. This represents how Spark SQL generally deserializes a serialized value in Spark SQL representation back to an object of type
T.- clsTag
A classtag for
T.
- Alphabetic
- By Inheritance
- ExpressionEncoder
- Product
- Equals
- Encoder
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
ExpressionEncoder(objSerializer: Expression, objDeserializer: Expression, clsTag: ClassTag[T])
- objSerializer
An expression that can be used to encode a raw object to corresponding Spark SQL representation that can be a primitive column, array, map or a struct. This represents how Spark SQL generally serializes an object of type
T.- objDeserializer
An expression that will construct an object given a Spark SQL representation. This represents how Spark SQL generally deserializes a serialized value in Spark SQL representation back to an object of type
T.- clsTag
A classtag for
T.
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
assertUnresolved(): Unit
The process of resolution to a given schema throws away information about where a given field is being bound by ordinal instead of by name.
The process of resolution to a given schema throws away information about where a given field is being bound by ordinal instead of by name. This method checks to make sure this process has not been done already in places where we plan to do later composition of encoders.
-
val
attrs: Seq[String]
- Attributes
- protected
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
val
clsTag: ClassTag[T]
A ClassTag that can be used to construct an Array to contain a collection of
T.A ClassTag that can be used to construct an Array to contain a collection of
T.- Definition Classes
- ExpressionEncoder → Encoder
-
def
createDeserializer(): Deserializer[T]
Create a deserializer that can convert a Spark SQL Row into an object of type
T.Create a deserializer that can convert a Spark SQL Row into an object of type
T.Note that you must
resolveAndBindan encoder to a specific schema before you can create a deserializer. -
def
createSerializer(): Serializer[T]
Create a serializer that can convert an object of type
Tto a Spark SQL Row.Create a serializer that can convert an object of type
Tto a Spark SQL Row.Note that the returned Serializer is not thread safe. Multiple calls to
serializer.apply(..)are allowed to return the same actual InternalRow object. Thus, the caller should copy the result before making another call if required. -
val
deserializer: Expression
Returns an expression that can be used to deserialize an input row to an object of type
Twith a compatible schema.Returns an expression that can be used to deserialize an input row to an object of type
Twith a compatible schema. Fields of the row will be extracted usingUnresolvedAttribute. of the same name as the constructor arguments.For complex objects that are encoded to structs, Fields of the struct will be extracted using
GetColumnByOrdinalwith corresponding ordinal. -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isSerializedAsStruct: Boolean
Returns true if the type
Tis serialized as a struct byobjSerializer. -
def
isSerializedAsStructForTopLevel: Boolean
If the type
Tis serialized as a struct, when it is encoded to a Spark SQL row, fields in the struct are naturally mapped to top-level columns in a row.If the type
Tis serialized as a struct, when it is encoded to a Spark SQL row, fields in the struct are naturally mapped to top-level columns in a row. In other words, the serialized struct is flattened to row. But in case of theTis also anOptiontype, it can't be flattened to top-level row, because in Spark SQL top-level row can't be null. This method returns true ifTis serialized as struct and is notOptiontype. -
def
namedExpressions: Seq[NamedExpression]
Returns a new set (with unique ids) of NamedExpression that represent the serialized form of this object.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- val objDeserializer: Expression
- val objSerializer: Expression
-
def
resolveAndBind(attrs: Seq[Attribute] = schema.toAttributes, analyzer: Analyzer = SimpleAnalyzer): ExpressionEncoder[T]
Returns a new copy of this encoder, where the
deserializeris resolved and bound to the given schema.Returns a new copy of this encoder, where the
deserializeris resolved and bound to the given schema.Note that, ideally encoder is used as a container of serde expressions, the resolution and binding stuff should happen inside query framework. However, in some cases we need to use encoder as a function to do serialization directly(e.g. Dataset.collect), then we can use this method to do resolution and binding outside of query framework.
-
val
schema: StructType
Returns the schema of encoding this type of object as a Row.
Returns the schema of encoding this type of object as a Row.
- Definition Classes
- ExpressionEncoder → Encoder
-
val
schemaString: String
- Attributes
- protected
-
val
serializer: Seq[NamedExpression]
A sequence of expressions, one for each top-level field that can be used to extract the values from a raw object into an InternalRow: 1.
A sequence of expressions, one for each top-level field that can be used to extract the values from a raw object into an InternalRow: 1. If
serializerencodes a raw object to a struct, strip the outer If-IsNull and get theCreateNamedStruct. 2. For other cases, wrap the single serializer withCreateNamedStruct. -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- ExpressionEncoder → AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()