scala.ScalaReflectionException : <none> is not a term

标签 scala apache-spark cassandra spark-cassandra-connector

我在 Spark 中有以下代码:

rdd
  .map(processFunction(_))
  .saveToCassandra("keyspace", "tableName")

哪里

def processFunction(src: String): Seq[Any] =
  src match {
   case "a" => List(A("a", 123112, "b"), A("b", 142342, "c"))
   case "b" => List(B("d", 12312, "e", "f"), B("g", 12312, "h", "i"))
  }

地点:

case class A(entity: String, time: Long, value: String)
case class B(entity: String, time: Long, value1: String, value2: String)

saveToCassandra需要一个对象集合并使用 Seq[Any]作为包含 Seq[A] 的返回类型和Seq[B]休息saveToCassandra异常(exception) - scala.ScalaReflectionException: <none>不是一个术语。造成这种行为的原因是什么?

最佳答案

def processFunction(src: String): (Any, Any) = {
  src match {
   case "a" => (A("a", 123112, "b"), A("b", 142342, "c"))
   case "b" => (B("d", 12312, "e", "f"), B("g", 12312, "h", "i"))
  }
}

类似的东西可能会起作用。不过,我还没有过多地尝试在 cassandra 中保存对象。也不将任何内容与 cassandra 一起使用。然而,上面没有案例类和任何问题的解决方案是我最近解决这个问题的方法。例如,下面的代码就可以工作。

def processFunction(src: String): (String, Int, String) = {
   src match {
     case "a" => ("a", 123112, "b")
     case "b" => ("d", 12312, "e")
   }
}

但是,这并不完全是您想要的。所以是的,随你便吧。

关于scala.ScalaReflectionException : <none> is not a term,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33811881/

相关文章:

scala - 可以在对的 Seq 上更快地实现 reduceByKey 吗?

scala - Spark : FlatMap and CountVectorizer pipeline

hadoop - Spark 上的 Apache pig

scala - Spark+Scala App如何对云对象存储进行认证授权?

scala - 如何用scala + play + sbt复制资源

apache-spark - 重新启动 Spark 结构化流作业会消耗数百万条 Kafka 消息并死掉

python - PySpark运行时错误: Set changed size during iteration

cassandra - Cassandra 中的复制计时

cassandra - Cassandra工具cassandra-stress的使用

Scala Redis 驱动程序 - 使用 blpop 命令