在scala case类中列出[String]对象
我使用的是dse 5.1.0(与spark 2.0.2.6和scala 2.11.8一起打包)。 阅读卡桑德拉表格如下在scala case类中列出[String]对象,scala,apache-spark,cassandra,Scala,Apache Spark,Cassandra,我使用的是dse 5.1.0(与spark 2.0.2.6和scala 2.11.8一起打包)。 阅读卡桑德拉表格如下 val sparkSession = ... val rdd1 = sparkSession.table("keyspace.table") java.lang.UnsupportedOperationException: Cannot infer type for class scala.collection.immutable.List because it is not
val sparkSession = ...
val rdd1 = sparkSession.table("keyspace.table")
java.lang.UnsupportedOperationException: Cannot infer type for class scala.collection.immutable.List because it is not bean-compliant
这个表包含一个List[String]
列,比如list1,我在scala rdd中读到它,比如rdd1。但当我尝试使用编码器时,它会抛出错误
val myVoEncoder = Encoders.bean(classOf[myVo])
val dataSet = rdd1.as(myVoEncoder)
我试过了
scala.collection.mutable.list
,
scala.collection.immutable.list
,
scala.collection.list
,
Seq
,
WrappedArray
。所有人都给出了如下相同的错误
val sparkSession = ...
val rdd1 = sparkSession.table("keyspace.table")
java.lang.UnsupportedOperationException: Cannot infer type for class scala.collection.immutable.List because it is not bean-compliant
鳞状粘虫
case class MyVo(
@BeanProperty var id: String,
@BeanProperty var duration: Int,
@BeanProperty var list1: List[String],
) {
def this() = this("", 0, null)
}
任何帮助都将收到通知。您应该使用
数组[字符串]
:
case class MyVo(
@BeanProperty var id: String,
@BeanProperty var duration: Int,
@BeanProperty var list1: Array[String]
) {
def this() = this("", 0, null)
}
尽管强调这一点很重要,但更惯用的方法是:
import sparkSession.implicits._
case class MyVo(
id: String,
duration: Int,
list1: Seq[String]
)
rdd1.as[MyVo]
您应该使用
数组[字符串]
:
case class MyVo(
@BeanProperty var id: String,
@BeanProperty var duration: Int,
@BeanProperty var list1: Array[String]
) {
def this() = this("", 0, null)
}
尽管强调这一点很重要,但更惯用的方法是:
import sparkSession.implicits._
case class MyVo(
id: String,
duration: Int,
list1: Seq[String]
)
rdd1.as[MyVo]
您可以包括表的模式吗?您可以包括表的模式吗?谢谢@user10758343
Seq
和importing implicits给出了相同的错误,但是Array[String]
起了作用。简单问一下,为什么Array与case类一起工作,而我在问题中列出的其他选项都没有?谢谢@user10758343Seq
和importing implicits给出了相同的错误,但是Array[String]
起作用了。只是一个简单的问题,为什么Array与case类一起工作,而我在问题中列出的其他选项都没有?