Re: How to convert from DataFrame to Dataset[Row]?

2016-07-16 Thread Sun Rui
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  wrote:
> 
> In Spark 1.6.1, how can I convert a DataFrame to a Dataset[Row]?
> 
> Is there a direct conversion?  (Trying .as[Row] doesn't work,
> even after importing  .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-unsubscr...@spark.apache.org
> 



Re: How to convert from DataFrame to Dataset[Row]?

2016-07-15 Thread Mich Talebzadeh
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=AAEWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw
*



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 
wrote:

> In Spark 1.6.1, how can I convert a DataFrame to a Dataset[Row]?
>
> Is there a direct conversion?  (Trying .as[Row] doesn't
> work,
> even after importing  .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-unsubscr...@spark.apache.org
>
>


How to convert from DataFrame to Dataset[Row]?

2016-07-15 Thread Daniel Barclay

In Spark 1.6.1, how can I convert a DataFrame to a Dataset[Row]?

Is there a direct conversion?  (Trying .as[Row] doesn't work,
even after importing  .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-unsubscr...@spark.apache.org