https://github.com/findinpath/cassandra-select-distinct-partition-keys
Demo on how to select the distinct partition keys of a Cassandra table
https://github.com/findinpath/cassandra-select-distinct-partition-keys
cassandra distinct-partition-keys testcontainers
Last synced: about 1 month ago
JSON representation
Demo on how to select the distinct partition keys of a Cassandra table
- Host: GitHub
- URL: https://github.com/findinpath/cassandra-select-distinct-partition-keys
- Owner: findinpath
- Created: 2019-11-04T23:36:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-05T23:15:24.000Z (over 6 years ago)
- Last Synced: 2025-03-24T13:27:22.106Z (about 1 year ago)
- Topics: cassandra, distinct-partition-keys, testcontainers
- Language: Java
- Homepage: https://www.findinpath.com/distinct-cassandra-partition-keys/
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Demo on how to select the distinct partition keys of a table
============================================================
This is a simple showcase on how to select all the distinct partition keys
from a Cassandra table.
There is also a corresponding [blog](https://www.findinpath.com/distinct-cassandra-partition-keys/)
post for this project.
The way to select a page of distinct partition keys is summarized in the following code snippet:
```java
private ResultSet getDistinctUserIdsBatch(Session session, Optional lastUserIdProcessed,
int batchSize) {
var batchedDistinctUserSelect = QueryBuilder.select(USER_ID_COLUMN_NAME)
.distinct()
.from(DEMO_KEYSPACE_NAME, USER_BOOKMARKS_TABLE_NAME);
lastUserIdProcessed.ifPresent(
uuid -> batchedDistinctUserSelect.where(gt(token(USER_ID_COLUMN_NAME), token(uuid))));
batchedDistinctUserSelect.limit(batchSize);
return session.execute(batchedDistinctUserSelect);
}
```
The project contains a unit test which spawns a Cassandra
container (via [testcontainers](https://www.testcontainers.org/) library)
, fills it with data (user bookmarks) and then selects all the distinct user ids
from the table in a page fashion.