Dataframe scala.MatchError:从包含22个以上字段的;进一步写入RDBMS

Dataframe scala.MatchError:从包含22个以上字段的;进一步写入RDBMS,dataframe,apache-kafka,apache-spark-sql,spark-streaming,Dataframe,Apache Kafka,Apache Spark Sql,Spark Streaming,首先,我解析kafka消息,然后将模式应用于该消息。它按预期打印模式,我在foreach循环中使用rdd.toDF().printSchema。。但是,当我尝试使用JDBC连接保存数据时,会出现一个错误: scala.MatchError: Enrich.Streaming.Samples$Person@7d7904f6 (of class Enrich.Streaming.Samples$Person class Person ( name : Str

首先,我解析kafka消息,然后将模式应用于该消息。它按预期打印模式,我在foreach循环中使用rdd.toDF().printSchema。。但是,当我尝试使用JDBC连接保存数据时,会出现一个错误:

scala.MatchError: Enrich.Streaming.Samples$Person@7d7904f6 (of class Enrich.Streaming.Samples$Person

class Person (
             name        : String,
             id       : String,
             type: String,
             .....,
             .....,
             .....,
             .....,
             32 of them
            )
extends Product {

@throws(classOf[IndexOutOfBoundsException])
override def productElement(n: Int): Any = n match {
  case 0 => name
  case 1 => id
  case 2 => type
  ....
  ....
  case 31 => ...
  case _ => throw new IndexOutOfBoundsException(n.toString())
}

override def productArity: Int = 32

override def canEqual(that: Any): Boolean = that.isInstanceOf[Person]

}

object Person extends Serializable {

def parse(str: String): Option[Person] = {
  val paramArray = str.split("\\|")
  Try(
    new Person(paramArray(0),
      paramArray(1),
      paramArray(2)
      .....
      .....
      .....
      ......

    )) match {
    case Success(trimarc) => Some(trimarc)
    case Failure(throwable) => {
      println (throwable.getMessage())
      None
    }
  }

}

}




val messages = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](
  ssc, kafkaParams, topicsSet)

val sqlContext = new SQLContext(sc)
import sqlContext.implicits._

 val data = messages.map(_._2).map(Person.parse)

data.foreachRDD(rdd =>
    rdd.toDF().write.mode("append").jdbc(url,table,prop)
    )
如果有人能帮我解决这个问题,我将不胜感激


谢谢

您是否自己创建了
类人员
?为什么不使用
案例类
?此外,有没有任何一行信息可以指出问题出现的地方?您好,maasg,我在类Person中有32个以上的特性&在scala 2.10.4中,case类只支持22个特性,因此我不得不创建一个类。当im字符串用于解析kafka消息时,错误出现在val data=messages.map(u._2).map(Person.parse)处。也许这是升级到Scala 2.11的一个好参数?