You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Daniel Barclay <da...@gmail.com> on 2016/07/15 19:21:42 UTC
How to convert from DataFrame to Dataset[Row]?
In Spark 1.6.1, how can I convert a DataFrame to a Dataset[Row]?
Is there a direct conversion? (Trying <someDataframe>.as[Row] doesn't work,
even after importing <my sqlContext>.implicits._ .)
Is there some way to map the Rows from the Dataframe into the Dataset[Row]?
(DataFrame.map would just make another Dataframe, right?)
Thanks,
Daniel
---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscribe@spark.apache.org
Re: How to convert from DataFrame to Dataset[Row]?
Posted by Mich Talebzadeh <mi...@gmail.com>.
can't you create a temp table from DF say df.registerTempTable("tmp") and
use that instead?
Dr Mich Talebzadeh
LinkedIn * https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw
<https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw>*
http://talebzadehmich.wordpress.com
*Disclaimer:* Use it at your own risk. Any and all responsibility for any
loss, damage or destruction of data or any other property which may arise
from relying on this email's technical content is explicitly disclaimed.
The author will in no case be liable for any monetary damages arising from
such loss, damage or destruction.
On 15 July 2016 at 20:21, Daniel Barclay <da...@gmail.com>
wrote:
> In Spark 1.6.1, how can I convert a DataFrame to a Dataset[Row]?
>
> Is there a direct conversion? (Trying <someDataframe>.as[Row] doesn't
> work,
> even after importing <my sqlContext>.implicits._ .)
>
> Is there some way to map the Rows from the Dataframe into the Dataset[Row]?
> (DataFrame.map would just make another Dataframe, right?)
>
>
> Thanks,
> Daniel
>
> ---------------------------------------------------------------------
> To unsubscribe e-mail: user-unsubscribe@spark.apache.org
>
>
Re: How to convert from DataFrame to Dataset[Row]?
Posted by Sun Rui <su...@163.com>.
For Spark 1.6.x, a DataFrame can't be directly converted to a Dataset[Row], but can done indirectly as follows:
import org.apache.spark.sql.catalyst.encoders.RowEncoder
// assume df is a DataFrame
implicit val encoder: ExpressionEncoder[Row] = RowEncoder(df.schema)
val ds = df.as[Row]
However, it may be more convenient to convert a DataFrame to a Dataset of Tuple or case class corresponding to the row schema.
> On Jul 16, 2016, at 03:21, Daniel Barclay <da...@gmail.com> wrote:
>
> In Spark 1.6.1, how can I convert a DataFrame to a Dataset[Row]?
>
> Is there a direct conversion? (Trying <someDataframe>.as[Row] doesn't work,
> even after importing <my sqlContext>.implicits._ .)
>
> Is there some way to map the Rows from the Dataframe into the Dataset[Row]?
> (DataFrame.map would just make another Dataframe, right?)
>
>
> Thanks,
> Daniel
>
> ---------------------------------------------------------------------
> To unsubscribe e-mail: user-unsubscribe@spark.apache.org
>