You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Jakub Dubovsky <sp...@gmail.com> on 2016/10/14 20:42:50 UTC

import sql.implicits._

Hey community,

I would like to *educate* myself about why all *sql implicits* (most
notably conversion to Dataset API) are imported from *instance* of
SparkSession and not using static imports.

Having this design one runs into problems like this
<http://stackoverflow.com/questions/32453886/spark-sql-dataframe-import-sqlcontext-implicits>.
It requires the presence of SparkSession instance (the only one we have) in
many parts of code. This makes code structuring harder.

I assume that there is a *reason* why this design was *chosen*. Can
somebody please point me to a resource or explain why is this?
What is an advantage of this approach?
Or why it is not possible to implement it with static imports?

Thanks a lot!

Jakub

Re: import sql.implicits._

Posted by Jakub Dubovsky <sp...@gmail.com>.
Hey Koert,

thanks for explanation. I did not recall that every rdd/df/dataset has a
"parent" context/sqlContext. When I think about this it kinda make sense.

J.

On Fri, Oct 14, 2016 at 11:54 PM, Koert Kuipers <ko...@tresata.com> wrote:

> about the stackoverflow question, do this:
>
> def validateAndTransform(df: DataFrame) : DataFrame = {
>
>   import df.sparkSession.implicits._
>
>   ...
> }
>
>
>
> On Fri, Oct 14, 2016 at 5:51 PM, Koert Kuipers <ko...@tresata.com> wrote:
>
>> b
>> ​asically the implicit conversiosn that need it are rdd => dataset and
>> seq => dataset​
>>
>> On Fri, Oct 14, 2016 at 5:47 PM, Koert Kuipers <ko...@tresata.com> wrote:
>>
>>> for example when do you Seq(1,2,3).toDF("a") it needs to get the
>>> SparkSession from somewhere. by importing the implicits from
>>> spark.implicits._ they have access to a SparkSession for operations like
>>> this.
>>>
>>> On Fri, Oct 14, 2016 at 4:42 PM, Jakub Dubovsky <
>>> spark.dubovsky.jakub@gmail.com> wrote:
>>>
>>>> Hey community,
>>>>
>>>> I would like to *educate* myself about why all *sql implicits* (most
>>>> notably conversion to Dataset API) are imported from *instance* of
>>>> SparkSession and not using static imports.
>>>>
>>>> Having this design one runs into problems like this
>>>> <http://stackoverflow.com/questions/32453886/spark-sql-dataframe-import-sqlcontext-implicits>.
>>>> It requires the presence of SparkSession instance (the only one we have) in
>>>> many parts of code. This makes code structuring harder.
>>>>
>>>> I assume that there is a *reason* why this design was *chosen*. Can
>>>> somebody please point me to a resource or explain why is this?
>>>> What is an advantage of this approach?
>>>> Or why it is not possible to implement it with static imports?
>>>>
>>>> Thanks a lot!
>>>>
>>>> Jakub
>>>>
>>>>
>>>
>>
>

Re: import sql.implicits._

Posted by Koert Kuipers <ko...@tresata.com>.
about the stackoverflow question, do this:

def validateAndTransform(df: DataFrame) : DataFrame = {

  import df.sparkSession.implicits._

  ...
}



On Fri, Oct 14, 2016 at 5:51 PM, Koert Kuipers <ko...@tresata.com> wrote:

> b
> ​asically the implicit conversiosn that need it are rdd => dataset and seq
> => dataset​
>
> On Fri, Oct 14, 2016 at 5:47 PM, Koert Kuipers <ko...@tresata.com> wrote:
>
>> for example when do you Seq(1,2,3).toDF("a") it needs to get the
>> SparkSession from somewhere. by importing the implicits from
>> spark.implicits._ they have access to a SparkSession for operations like
>> this.
>>
>> On Fri, Oct 14, 2016 at 4:42 PM, Jakub Dubovsky <
>> spark.dubovsky.jakub@gmail.com> wrote:
>>
>>> Hey community,
>>>
>>> I would like to *educate* myself about why all *sql implicits* (most
>>> notably conversion to Dataset API) are imported from *instance* of
>>> SparkSession and not using static imports.
>>>
>>> Having this design one runs into problems like this
>>> <http://stackoverflow.com/questions/32453886/spark-sql-dataframe-import-sqlcontext-implicits>.
>>> It requires the presence of SparkSession instance (the only one we have) in
>>> many parts of code. This makes code structuring harder.
>>>
>>> I assume that there is a *reason* why this design was *chosen*. Can
>>> somebody please point me to a resource or explain why is this?
>>> What is an advantage of this approach?
>>> Or why it is not possible to implement it with static imports?
>>>
>>> Thanks a lot!
>>>
>>> Jakub
>>>
>>>
>>
>

Re: import sql.implicits._

Posted by Koert Kuipers <ko...@tresata.com>.
b
​asically the implicit conversiosn that need it are rdd => dataset and seq
=> dataset​

On Fri, Oct 14, 2016 at 5:47 PM, Koert Kuipers <ko...@tresata.com> wrote:

> for example when do you Seq(1,2,3).toDF("a") it needs to get the
> SparkSession from somewhere. by importing the implicits from
> spark.implicits._ they have access to a SparkSession for operations like
> this.
>
> On Fri, Oct 14, 2016 at 4:42 PM, Jakub Dubovsky <
> spark.dubovsky.jakub@gmail.com> wrote:
>
>> Hey community,
>>
>> I would like to *educate* myself about why all *sql implicits* (most
>> notably conversion to Dataset API) are imported from *instance* of
>> SparkSession and not using static imports.
>>
>> Having this design one runs into problems like this
>> <http://stackoverflow.com/questions/32453886/spark-sql-dataframe-import-sqlcontext-implicits>.
>> It requires the presence of SparkSession instance (the only one we have) in
>> many parts of code. This makes code structuring harder.
>>
>> I assume that there is a *reason* why this design was *chosen*. Can
>> somebody please point me to a resource or explain why is this?
>> What is an advantage of this approach?
>> Or why it is not possible to implement it with static imports?
>>
>> Thanks a lot!
>>
>> Jakub
>>
>>
>

Re: import sql.implicits._

Posted by Koert Kuipers <ko...@tresata.com>.
for example when do you Seq(1,2,3).toDF("a") it needs to get the
SparkSession from somewhere. by importing the implicits from
spark.implicits._ they have access to a SparkSession for operations like
this.

On Fri, Oct 14, 2016 at 4:42 PM, Jakub Dubovsky <
spark.dubovsky.jakub@gmail.com> wrote:

> Hey community,
>
> I would like to *educate* myself about why all *sql implicits* (most
> notably conversion to Dataset API) are imported from *instance* of
> SparkSession and not using static imports.
>
> Having this design one runs into problems like this
> <http://stackoverflow.com/questions/32453886/spark-sql-dataframe-import-sqlcontext-implicits>.
> It requires the presence of SparkSession instance (the only one we have) in
> many parts of code. This makes code structuring harder.
>
> I assume that there is a *reason* why this design was *chosen*. Can
> somebody please point me to a resource or explain why is this?
> What is an advantage of this approach?
> Or why it is not possible to implement it with static imports?
>
> Thanks a lot!
>
> Jakub
>
>