Skip to content

Instantly share code, notes, and snippets.

@dgadiraju
Created September 13, 2019 16:55
Show Gist options
  • Save dgadiraju/7f88e20d72fbc09b2f6b6fee1abed4ff to your computer and use it in GitHub Desktop.
Save dgadiraju/7f88e20d72fbc09b2f6b6fee1abed4ff to your computer and use it in GitHub Desktop.
def toDate(d: String) = {
val a = d.split("/")
(a(2) + "%02d".format(a(0).toInt) + "%02d".format(a(1).toInt)).toInt
}
toDate("7/3/2019")
toDate("10/3/2019")
val toDateUDF = org.apache.spark.sql.functions.udf(toDate _)
val df = Seq("7/3/2019", "10/3/2019", "10/10/2019", "3/10/2019").toDF
df.select(toDateUDF($"value")).show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment