You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Wenchen Fan (JIRA)" <ji...@apache.org> on 2019/07/22 04:55:00 UTC

[jira] [Resolved] (SPARK-28456) Add a public API `Encoder.makeCopy` to allow creating Encoder without touching Scala reflections

     [ https://issues.apache.org/jira/browse/SPARK-28456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wenchen Fan resolved SPARK-28456.
---------------------------------
       Resolution: Fixed
    Fix Version/s: 3.0.0

Issue resolved by pull request 25209
[https://github.com/apache/spark/pull/25209]

> Add a public API `Encoder.makeCopy` to allow creating Encoder without touching Scala reflections
> ------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-28456
>                 URL: https://issues.apache.org/jira/browse/SPARK-28456
>             Project: Spark
>          Issue Type: New Feature
>          Components: SQL
>    Affects Versions: 2.4.3
>            Reporter: Shixiong Zhu
>            Assignee: Shixiong Zhu
>            Priority: Major
>             Fix For: 3.0.0
>
>
> Because `Encoder` is not thread safe, the user cannot reuse an `Encoder` in multiple `Dataset`s. However, creating an `Encoder` for a complicated class is slow due to Scala reflections. To reduce the cost of Encoder creation, right now I usually use the private API `ExpressionEncoder.copy` as follows:
> {code:java}
> object FooEncoder {
>  private lazy val _encoder: ExpressionEncoder[Foo] = ExpressionEncoder[Foo]()
>  implicit def encoder: ExpressionEncoder[Foo] = _encoder.copy()
> }
> {code}
> This PR proposes a new method `makeCopy` in `Encoder` so that the above codes can be rewritten using public APIs.
> {code:java}
> object FooEncoder {
>  private lazy val _encoder: Encoder[Foo] = Encoders.product[Foo]()
>  implicit def encoder: Encoder[Foo] = _encoder.makeCopy
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org