spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mich Talebzadeh <mich.talebza...@gmail.com>
Subject Converting array of string type to datetime
Date Wed, 23 Mar 2016 21:20:49 GMT
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
<https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw>*



http://talebzadehmich.wordpress.com

Mime
View raw message