Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 511
Aaron O'Donnell Avatar asked Aug 06 '16 13:08

Aaron O'Donnell


People also ask

How to use classes and objects in Scala programming?

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.

How to get the date object in Scala?

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.

What is the difference between constructor and fields 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.

How to instantiate a class in Scala?

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.


1 Answers

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
like image 157
bluenote10 Avatar answered Sep 20 '22 04:09

bluenote10