File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
main/scala/org/apache/spark/sql
test/scala/org/apache/spark/sql/catalyst/encoders Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,12 @@ object Encoders {
157
157
*/
158
158
def TIMESTAMP : Encoder [java.sql.Timestamp ] = ExpressionEncoder ()
159
159
160
+ /**
161
+ * An encoder for arrays of bytes.
162
+ * @since 1.6.1
163
+ */
164
+ def BINARY : Encoder [Array [Byte ]] = ExpressionEncoder ()
165
+
160
166
/**
161
167
* Creates an encoder for Java Bean of type T.
162
168
*
Original file line number Diff line number Diff line change @@ -198,6 +198,15 @@ case class ExpressionEncoder[T](
198
198
@ transient
199
199
private lazy val constructProjection = GenerateSafeProjection .generate(fromRowExpression :: Nil )
200
200
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
+
201
210
/**
202
211
* Returns an encoded version of `t` as a Spark SQL row. Note that multiple calls to
203
212
* 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 {
77
77
}
78
78
79
79
class ExpressionEncoderSuite extends SparkFunSuite {
80
+ OuterScopes .outerScopes.put(getClass.getName, this )
81
+
80
82
implicit def encoder [T : TypeTag ]: ExpressionEncoder [T ] = ExpressionEncoder ()
81
83
82
84
// test flat encoders
@@ -278,16 +280,14 @@ class ExpressionEncoderSuite extends SparkFunSuite {
278
280
}
279
281
}
280
282
281
- private val outers : ConcurrentMap [String , AnyRef ] = new MapMaker ().weakValues().makeMap()
282
- outers.put(getClass.getName, this )
283
283
private def encodeDecodeTest [T : ExpressionEncoder ](
284
284
input : T ,
285
285
testName : String ): Unit = {
286
286
test(s " encode/decode for $testName: $input" ) {
287
287
val encoder = implicitly[ExpressionEncoder [T ]]
288
288
val row = encoder.toRow(input)
289
289
val schema = encoder.schema.toAttributes
290
- val boundEncoder = encoder.resolve(schema, outers).bind(schema)
290
+ val boundEncoder = encoder.defaultBinding
291
291
val convertedBack = try boundEncoder.fromRow(row) catch {
292
292
case e : Exception =>
293
293
fail(
You can’t perform that action at this time.
0 commit comments