无法使用分区键、主键和聚类顺序创建 Cassandra table
Can't create Cassandra table with PartitionKey, PrimaryKey and ClusteringOrder
我正在尝试使用 Phantom
创建以下 Cassandra table
object itemId extends StringColumn(this) with PartitionKey[String]
object anotherItemId extends StringColumn(this) with PrimaryKey[String]
object similarity extends DoubleColumn(this) with ClusteringOrder[Double] with Descending
所以我希望能够通过itemId
获取所有记录。我希望它们按 similarity
排序。我将 anotherItemId
设置为 PrimaryKey
因为 itemId, similarity
组合键不是唯一的。但是我收到以下错误:
com.websudos.phantom.exceptions.InvalidClusteringKeyException: Table similarities: When using CLUSTERING ORDER all PrimaryKey definitions must become a ClusteringKey definition and specify order.
这个example表明使用PartitionKey
、PrimaryKey
和ClusteringOrder
是可能的。我做错了什么?
如错误所述,当您指定聚簇顺序时,您需要为聚簇键的每个部分指定一个。如果示例有其他提示,则示例错误,我现在将更新它。
object itemId extends StringColumn(this) with PartitionKey[String]
object anotherItemId extends StringColumn(this) with ClusteringOrder[String] with Ascending
object similarity extends DoubleColumn(this) with ClusteringOrder[Double] with Descending
请记住,PRIMARY_KEY = PARTITION_KEYS + CLUSTERING_KEYS
,所以当您要定义排序时,所有聚类键,或幻影调用的 PrimaryKey
,都需要变为 ClusteringOrder
。
这是 Cassandra 强加的限制,幻影只是比 Cassandra 更快地给你一个错误。
我正在尝试使用 Phantom
创建以下 Cassandra table object itemId extends StringColumn(this) with PartitionKey[String]
object anotherItemId extends StringColumn(this) with PrimaryKey[String]
object similarity extends DoubleColumn(this) with ClusteringOrder[Double] with Descending
所以我希望能够通过itemId
获取所有记录。我希望它们按 similarity
排序。我将 anotherItemId
设置为 PrimaryKey
因为 itemId, similarity
组合键不是唯一的。但是我收到以下错误:
com.websudos.phantom.exceptions.InvalidClusteringKeyException: Table similarities: When using CLUSTERING ORDER all PrimaryKey definitions must become a ClusteringKey definition and specify order.
这个example表明使用PartitionKey
、PrimaryKey
和ClusteringOrder
是可能的。我做错了什么?
如错误所述,当您指定聚簇顺序时,您需要为聚簇键的每个部分指定一个。如果示例有其他提示,则示例错误,我现在将更新它。
object itemId extends StringColumn(this) with PartitionKey[String]
object anotherItemId extends StringColumn(this) with ClusteringOrder[String] with Ascending
object similarity extends DoubleColumn(this) with ClusteringOrder[Double] with Descending
请记住,PRIMARY_KEY = PARTITION_KEYS + CLUSTERING_KEYS
,所以当您要定义排序时,所有聚类键,或幻影调用的 PrimaryKey
,都需要变为 ClusteringOrder
。
这是 Cassandra 强加的限制,幻影只是比 Cassandra 更快地给你一个错误。