简体   繁体   English

我应该在scala类构造函数中声明什么类型的DateTime对象?

[英]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. 我试图将行从cassandra表映射到自定义类,但不断获得DateTime值的IllegalArgumentException。 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. 我是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 . 您可以在此处找到Spark中的默认Java / Scala数据类型。 Depending on what your data base actually contains you may want to try: 根据您的数据库实际包含的内容,您可能需要尝试:

  • java.sql.Date for a DateType column 用于DateType列的java.sql.Date
  • java.sql.Timestamp for a TimestampType column java.sql.TimestampTimestampType

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. 他们也是Long类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Scala中为“对象”类类型声明构造函数? 即,单身人士的一次性操作 - How do I declare a constructor for an 'object' class type in Scala? I.e., a one time operation for the singleton 我可以在Scala中声明其伴随对象中的类吗? - Can I in Scala declare the class inside its companion object? 什么是类型,什么是scala中的类型构造函数 - What is type and what is type constructor in scala 如何在scala构造函数中声明类型别名? - How do you declare a type alias in a scala constructor? 什么时候应该在Scala的通用类中使用类型绑定? - When should I use type bound in generic class in scala? Scala - 我应该为一组深度的树使用什么类型? - Scala - What type should I use for trees of a set depth? 我应该为我的案例类使用什么日期时间类? - What datetime class should I use for my case classes? Scala:找不到适合类型 [简单类型,类事物] 的构造函数:无法从 JSON 对象实例化 - Scala:No suitable constructor found for type [simple type, class Thing]: can not instantiate from JSON object 如何在Scala中使用类型参数获取Class的类对象? - How do I get the class object of Class with type parameters in Scala? 是否可以在Scala中实现类构造函数类型转换器 - Is it possible to implement a class constructor type converter in Scala
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM