【问题标题】:Partition key predicate must include all partition key columns分区键谓词必须包括所有分区键列
【发布时间】:2017-11-13 15:01:36
【问题描述】:

我正在尝试使用 scala 语言在 spark 中创建查询,数据在 cassandra 数据库中以表格形式提供。在 Cassandra 表中,我有两个键,1)主键 2) 分区键

Cassandra DDL 将是这样的:

CREATE TABLE A.B (
    id1 text,
    id2 text,
    timing timestamp,
    value float,
    PRIMARY KEY ((id1, id2), timing)
) WITH CLUSTERING ORDER BY (timing DESC)

我的 Spark 编程:

val conf = new SparkConf(true).set("spark.cassandra.connection.host","192.168.xx.xxx").set("spark.cassandra.auth.username","test").set("spark.cassandra.auth.password","test")
val sc = new SparkContext(conf)
var ctable = sc.cassandraTable("A", "B").select("id1","id2","timing","value").where("id1=?","1001")

当我查询相同的“值”时,我得到了结果,但是当我查询 id1 或 id2 时,我收到一个错误。

错误获得: java.lang.UnsupportedOperationException: 分区键谓词必须包括所有分区键列或需要索引的分区键列。缺少列:id2

我正在使用 spark-2.2.0-bin-hadoop2.7、Cassandra 3.9、scala 2.11.8。

提前致谢。

【问题讨论】:

    标签: spark-cassandra-connector


    【解决方案1】:

    我需要的输出是通过使用以下程序获得的。

    val conf = new SparkConf(true).set("spark.cassandra.connection.host","192.168.xx.xxx").set("spark.cassandra.auth.username","test").set("spark.cassandra.auth.password","test")
    val sc = new SparkContext(conf)
    var ctable = sc.cassandraTable("A", "B").select("id1","id2","timing","value").where("id1=?","1001").where("id2=?","1002")
    

    这就是我们如何通过 Spark 访问 cassandra 数据库中的分区键。

    【讨论】:

      猜你喜欢
      • 2018-09-09
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多