我正在尝试读取包含名称的文件,并使用Spark和Scala将名称和时间戳数据一起插入到cassandra表中。以下是我的代码
CREATE TABLE practice.names (
name text PRIMARY KEY,
insert_date timestamp
)
cassandra表详情见下文
Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Columns not found in com.sample.practice.Names: [insert_date]
at scala.Predef$.require(Predef.scala:233)
at com.datastax.spark.connector.mapper.DefaultColumnMapper.columnMapForWriting(DefaultColumnMapper.scala:108)
at com.datastax.spark.connector.writer.MappedToGettableDataConverter$$anon$1.<init>(MappedToGettableDataConverter.scala:29)
at com.datastax.spark.connector.writer.MappedToGettableDataConverter$.apply(MappedToGettableDataConverter.scala:20)
at com.datastax.spark.connector.writer.DefaultRowWriter.<init>(DefaultRowWriter.scala:17)
at com.datastax.spark.connector.writer.DefaultRowWriter$$anon$1.rowWriter(DefaultRowWriter.scala:31)
at com.datastax.spark.connector.writer.DefaultRowWriter$$anon$1.rowWriter(DefaultRowWriter.scala:29)
at com.datastax.spark.connector.writer.TableWriter$.apply(TableWriter.scala:271)
at com.datastax.spark.connector.RDDFunctions.saveToCassandra(RDDFunctions.scala:36)
at com.sample.practice.CqlInsertDate$.main(CqlInsertDate.scala:30)
at com.sample.practice.CqlInsertDate.main(CqlInsertDate.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
当我尝试执行代码时,我收到以下错误
Names(Frank,2017-01-30T14:03:16.911+05:30)
Names(Jean,2017-01-30T14:03:17.115+05:30)
Names(Joe,2017-01-30T14:03:17.116+05:30)
当我尝试打印RDD而不是保存到cassandra时,我得到以下输出
version := "1.0"
scalaVersion := "2.10.6"
libraryDependencies += "com.datastax.spark" % "spark-cassandra-connector_2.10" % "2.0.0-M3"
libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "2.0.2"
libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "2.0.2"
libraryDependencies += "org.apache.spark" % "spark-hive_2.10" % "2.0.2"
以下是我的SBT档案详情
{{1}}
我正在使用Cassandra 2.1。请帮忙。提前谢谢。
答案 0 :(得分:2)
尝试将您的类字段更改为insert_date,反之亦然更改为auditDate