Powered By Blogger

Sunday, October 6, 2019

Converting String field to Date in Dataframe


val sourceDF = spark.createDF(
  List(
    (1, "2013-01-30"),
    (2, "2012-01-01")
  ), List(
    ("person_id", IntegerType, true),
    ("birth_date", StringType, true)
  )
).withColumn(
  "birth_date",
  col("birth_date").cast("date")
)

sourceDF.show()
sourceDF.printSchema()


https://mungingdata.com/apache-spark/dates-times/

No comments:

Post a Comment