首页 文章

分区键谓词必须包括所有分区键列

提问于
浏览
1

我正在尝试使用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 .

提前致谢 .

1 回答

  • 0

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

    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数据库中的分区键 .

相关问题