File tree Expand file tree Collapse file tree
main/scala/org/apache/spark/sql
test/scala/org/apache/spark/sql/catalyst/encoders Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -157,6 +157,12 @@ object Encoders {
157157 */
158158 def TIMESTAMP : Encoder [java.sql.Timestamp ] = ExpressionEncoder ()
159159
160+ /**
161+ * An encoder for arrays of bytes.
162+ * @since 1.6.1
163+ */
164+ def BINARY : Encoder [Array [Byte ]] = ExpressionEncoder ()
165+
160166 /**
161167 * Creates an encoder for Java Bean of type T.
162168 *
Original file line number Diff line number Diff line change @@ -198,6 +198,15 @@ case class ExpressionEncoder[T](
198198 @ transient
199199 private lazy val constructProjection = GenerateSafeProjection .generate(fromRowExpression :: Nil )
200200
201+ /**
202+ * Returns this encoder where it has been bound to its own output (i.e. no remaping of columns
203+ * is performed).
204+ */
205+ def defaultBinding : ExpressionEncoder [T ] = {
206+ val attrs = schema.toAttributes
207+ resolve(attrs, OuterScopes .outerScopes).bind(attrs)
208+ }
209+
201210 /**
202211 * Returns an encoded version of `t` as a Spark SQL row. Note that multiple calls to
203212 * toRow are allowed to return the same actual [[InternalRow ]] object. Thus, the caller should
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ class JavaSerializable(val value: Int) extends Serializable {
7777}
7878
7979class ExpressionEncoderSuite extends SparkFunSuite {
80+ OuterScopes .outerScopes.put(getClass.getName, this )
81+
8082 implicit def encoder [T : TypeTag ]: ExpressionEncoder [T ] = ExpressionEncoder ()
8183
8284 // test flat encoders
@@ -278,16 +280,14 @@ class ExpressionEncoderSuite extends SparkFunSuite {
278280 }
279281 }
280282
281- private val outers : ConcurrentMap [String , AnyRef ] = new MapMaker ().weakValues().makeMap()
282- outers.put(getClass.getName, this )
283283 private def encodeDecodeTest [T : ExpressionEncoder ](
284284 input : T ,
285285 testName : String ): Unit = {
286286 test(s " encode/decode for $testName: $input" ) {
287287 val encoder = implicitly[ExpressionEncoder [T ]]
288288 val row = encoder.toRow(input)
289289 val schema = encoder.schema.toAttributes
290- val boundEncoder = encoder.resolve(schema, outers).bind(schema)
290+ val boundEncoder = encoder.defaultBinding
291291 val convertedBack = try boundEncoder.fromRow(row) catch {
292292 case e : Exception =>
293293 fail(
You can’t perform that action at this time.
0 commit comments