GP
Size: a a a
GP
ПФ
GP
GP
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.catalyst.ScalaReflection
val encoder = ExpressionEncoder[Arity1]
val attrs = ScalaReflection.schemaFor[Arity1].dataType.asInstanceOf[StructType].map(f => AttributeReference(f.name, f.dataType, f.nullable, f.metadata)())
val bound = encoder.resolveAndBind(attrs)
bound.fromRow(InternalRow(1.asInstanceOf[java.lang.Integer]))
try {
bound.fromRow(InternalRow(null.asInstanceOf[java.lang.Integer]))
} catch {
case e => println(e.getMessage)
}
GP
GP
GP
ScalaReflection.schemaFor[Arity1].dataType.asInstanceOf[StructType].map(f => AttributeReference(f.name, f.dataType, f.nullable, f.metadata)())
GP
ПФ
GP
val attrs: Seq[Attribute] = 'value.int :: Nil
GP
ПФ
GP
ПФ
GP
bound.fromRow(InternalRow(1.asInstanceOf[java.lang.Integer]))
должен вернуть нормальный Arity1 (т.е. декодит из интернал роу)GP
val attrs: Seq[Attribute] = 'value.int :: Nil
val attrs = List(AttributeReference("value”, IntegerType, nullable = true)())
ПФ
GP
ПФ
ПФ