cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Check Peck <>
Subject How to extract all the user id from a single table in Cassandra?
Date Sat, 28 Feb 2015 04:24:39 GMT
I have a Cassandra table like this -

    create table user_record (user_id text, record_name text, record_value
blob, primary key (user_id, record_name));

What is the best way to extract all the user_id from this table? As of now,
I cannot change my data model to do this exercise so I need to find a way
by which I can extract all the user_id from the above table.

I am using Datastax Java driver in my project. Is there any other easy way
apart from code to extract all the user_id from the above table through
come cqlsh utility and dump it into some file?

I am thinking below code might timed out after some time -

    public class TestCassandra {

            private Session session = null;
            private Cluster cluster = null;

            private static class ConnectionHolder {
                static final TestCassandra connection = new TestCassandra();

            public static TestCassandra getInstance() {
                return ConnectionHolder.connection;

            private TestCassandra() {
                Builder builder = Cluster.builder();

                PoolingOptions opts = new PoolingOptions();

                cluster =
                        .withLoadBalancingPolicy(new TokenAwarePolicy(new
                session = cluster.connect();

        private Set<String> getRandomUsers() {
            Set<String> userList = new HashSet<String>();

            String sql = "select user_id from testkeyspace.user_record;";

            try {
                SimpleStatement query = new SimpleStatement(sql);
                ResultSet res = session.execute(query);

                Iterator<Row> rows = res.iterator();
                while (rows.hasNext()) {
                    Row r =;

                    String user_id = r.getString("user_id");
            } catch (Exception e) {
                System.out.println("error= " + e);

            return userList;

Adding java-driver group and Cassandra group as well to see whether there
is any better way to execute this?

View raw message