Thank you for bringing it up. Looks like there is some difference in spark version 2.3 and before it.
You can try this using spark 2.3 which you can launch by: /usr/spark2.3/bin/spark-shell
I tested this:
var df = Seq(("06-03-2009"),("07-24-2009")).toDF("Date")
df.select(
col("Date"),
to_date(col("Date"),"MM-dd-yyyy").as("to_date")
).show()
It gave following results:
+----------+----------+
| Date| to_date|
+----------+----------+
|06-03-2009|2009-06-03|
|07-24-2009|2009-07-24|
+----------+----------+
Please note that the same code did not work in spark 2.1. Also, I have to import col and to_date explicitly
import org.apache.spark.sql.functions.{col, to_date}
var df = Seq(("06-03-2009"),("07-24-2009")).toDF("Date")
df.select(
col("Date"),
to_date(col("Date"),"MM-dd-yyyy").as("to_date")
).show()
it showed:
:29: error: too many arguments for method to_date: (e:org.apache.spark.sql.Column)org.apache.spark.sql.Column to_date(col(“Date”),“MM-dd-yyyy”).as(“to_date”)