spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacek Laskowski <ja...@japila.pl>
Subject Re: Converting array of string type to datetime
Date Wed, 23 Mar 2016 21:26:23 GMT
Hi,

Why don't you use Datasets? You'd cut the number of getStrings and
it'd read nicer to your eyes. Also, doing such transformations would
*likely* be easier.

p.s. Please gist your example to fix it.

Pozdrawiam,
Jacek Laskowski
----
https://medium.com/@jaceklaskowski/
Mastering Apache Spark http://bit.ly/mastering-apache-spark
Follow me at https://twitter.com/jaceklaskowski


On Wed, Mar 23, 2016 at 10:20 PM, Mich Talebzadeh
<mich.talebzadeh@gmail.com> wrote:
>
> How can I convert the following from String to datetime
>
> scala> df.map(x => (x.getString(1), ChangeDate(x.getString(1)))).take(1)
> res60: Array[(String, String)] = Array((10/02/2014,2014-02-10))
>
> Please note that the custom UDF ChangeDate() has revered the string value
> from "dd/MM/yyyy" to "yyyy-MM-dd"
>
> Now I need to convert ChangeDate(x.getString(1)) from String to datetime?
>
> scala> df.map(x => (x.getString(1),
> ChangeDate(x.getString(1)).toDate)).take(1)
> <console>:25: error: value toDate is not a member of String
>               df.map(x => (x.getString(1),
> ChangeDate(x.getString(1)).toDate)).take(1)
>
> Or
>
> scala> df.map(x => (x.getString(1),
> ChangeDate(x.getString(1)).cast("date"))).take(1)
> <console>:25: error: value cast is not a member of String
>               df.map(x => (x.getString(1),
> ChangeDate(x.getString(1)).cast("date"))).take(1)
>
>
> Thanks,
>
>
> Dr Mich Talebzadeh
>
>
>
> LinkedIn
> https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw
>
>
>
> http://talebzadehmich.wordpress.com
>
>

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


Mime
View raw message