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
This chapter takes you through how to use classes and objects in Scala programming. A class is a blueprint for objects. Once you define a class, you can create objects from the class blueprint with the keyword new.
Date (int year, int month, int date): This takes three parameters as the input here. At first, we can pass the year, the second parameter accepts month and the last parameter accepts the date. After this, it will return us the date object in Scala.
Basically, in a class constructor is used for initializing new objects, fields are variables that provide the state of the class and its objects, and methods are used to implement the behavior of the class and its objects. In Scala, a class declaration contains the class keyword, followed by an identifier (name) of the class.
When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and the behavior of the class. But the values of those attributes, i.e. the state are unique for each object. A single class may have any number of instances. In Scala, an object of a class is created using the new keyword.
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
columnjava.sql.Timestamp
for a TimestampType
columnIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With