Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ trait Encoder[T] extends Serializable {
* A ClassTag that can be used to construct an Array to contain a collection of `T`.
*/
def clsTag: ClassTag[T]

/**
* Create a copied [[Encoder]]. The implementation may just copy internal reusable fields to speed
* up the [[Encoder]] creation.
*/
def makeCopy: Encoder[T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ case class ExpressionEncoder[T](
.map { case(f, a) => s"${f.name}$a: ${f.dataType.simpleString}"}.mkString(", ")

override def toString: String = s"class[$schemaString]"

override def makeCopy: ExpressionEncoder[T] = copy()
}

// A dummy logical plan that can hold expressions and go through optimizer rules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ class ExpressionEncoderSuite extends CodegenInterpretedPlanTest with AnalysisTes
testOverflowingBigNumeric(BigInt("9" * 100), "scala very large big int")
testOverflowingBigNumeric(new BigInteger("9" * 100), "java very big int")

encodeDecodeTest("foo" -> 1L, "makeCopy") {
Encoders.product[(String, Long)].makeCopy.asInstanceOf[ExpressionEncoder[(String, Long)]]
}

private def testOverflowingBigNumeric[T: TypeTag](bigNumeric: T, testName: String): Unit = {
Seq(true, false).foreach { allowNullOnOverflow =>
testAndVerifyNotLeakingReflectionObjects(
Expand Down