I am parsing some dates in this format: 2009-01-23 18:15:05
using the following function
def loadTransactions (sqlContext: SQLContext, path: String): DataFrame = {
val rowRdd = sqlContext.sparkContext.textFile(path).map { line =>
val tokens = line.split(',')
val dt = new DateTime(tokens(0))
Row(new Timestamp(dt.getMillis))
}
val fields = Seq(
StructField("timestamp", TimestampType, true)
)
val schema = StructType(fields)
sqlContext.createDataFrame(rowRdd, schema)
}
Spark is throwing an error:
java.lang.IllegalArgumentException: Invalid format: "2009-01-23 18:15:05" is malformed at " 18:15:05" at org.joda.time.format.DateTimeParserBucket.doParseMillis
I presume that it is due to the fact that the milliseconds are missing