简体   繁体   中英

What type should I declare a DateTime object in a scala class constructor?

Im trying to map rows from a cassandra table to a custom class but keep getting an IllegalArgumentException for the DateTime values. I've tried every type I can think of and they all throw the same exception. Help would be greatly appreciated. I'm a scala noob btw.

case class ClickData(Uuid: String, Tile: String, Latestclick: Long, OriginalTimestamp: Long, Rating: Int)

----------------------------

val data = sc.cassandraTable[ClickData]("test", "user_data")

data.foreach((i: ClickData) =>

  println("CASSIE ROW: "+i)


)

table row example:

uuid: 4hgfyt24854grh3fg34u3re47ff, tile: blah-blah, latest_click_timestamp: 2016-08-05 16:17:53+0100, original_timestamp: 2016-08-05 16:17:53+0100, rating: 1

You can find the default Java/Scala data types in Spark here . Depending on what your data base actually contains you may want to try:

  • java.sql.Date for a DateType column
  • java.sql.Timestamp for a TimestampType column

My parameter names did not match up with the column names, copying them out properly fixed my issue. They were of type Long as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM