【发布时间】:2017-07-29 12:54:27
【问题描述】:
我在 cassandra 3.9 中有一个柜台
create table counter_table ( id text, hour_no int, platform text, type text, title text,
count_time counter,
PRIMARY KEY (id, hour_no, platform, type , title));
我的 spark (2.1.0) scala (2.11) 代码是
import com.datastax.driver.core.{ConsistencyLevel, DataType}
import com.datastax.spark.connector.writer.WriteConf
val writeConf = WriteConf(consistencyLevel = ConsistencyLevel.ONE, ifNotExists = true)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val df = sqlContext.read.format("com.databricks.spark.csv").option("header", "false").option("inferSchema", "true").load("csv_file_path")
val newNames = Seq("id" , "hour_no" , "platform" , "type" , "title" , "count_time")
val dfRenamed = df.toDF(newNames: _*)
dfRenamed.write.format("org.apache.spark.sql.cassandra").
mode(SaveMode.Append).options(Map( "table" -> "counter_table", "keyspace" -> "key1",
"output.consistency.level" -> "LOCAL_ONE", "output.ifNotExists" -> "true" )).save()
火花代码给出一致性错误
Caused by: com.datastax.driver.core.exceptions.WriteFailureException:
Cassandra failure during write query at consistency LOCAL_QUORUM (2 responses were required but only 1 replica responded, 1 failed)
我们如何在 DataFrame 中指定 ONE 的一致性
【问题讨论】:
标签: scala apache-spark cassandra spark-dataframe spark-cassandra-connector