views:

357

answers:

1

I am using Erlang to interface with Cassandra and I cannot get the get_slice command to return a list of all the columns of a row. I use:

    X = thrift_client:call( C,
           'get_slice',
           [ "Keyspace1",
             K,
             #columnParent{column_family="KeyValue"},
             #slicePredicate{},
             1
             ] ),

: but I get back :

invalidRequestException,<<"predicate column_names and slice_range may not both be null">>

: However, using the cassandra-cli interface this works fine. Any ideas?

Updated:

I amended the Erlang example to reflect the Java exmaple given to :

get_props(K) -> {ok, C} = thrift_client:start_link("127.0.0.1",9160, cassandra_thrift),

        S = #sliceRange{start="",finish="",reversed=false,count=100},
        X = thrift_client:call( C,
               'get_slice',
               [ "Keyspace1",
                 K,
                 #columnParent{column_family="KeyValue"},
                 #slicePredicate{slice_range=S},
                 1
                 ] ),
        X.

:and it now works. Notice the addition of the line:

S = #sliceRange{start="",finish="",reversed=false,count=100}

+1  A: 

You are default initializing your SlicePredicate object. This will default construct a SlicePredicate with reversed set to false (compare with SQL syntax: "ORDER by DESC"), count set to 100 (compare with SQL syntax: LIMIT 100) and both slice_range and column_names set to null (unspecified in Erlang, because the "lack" of null).

Hopefully my Java code snippet could assist you (the example fetches all columns). I want to emphasize the creation and usage of the SlicePredicate.

private static void get_slice(Cassandra.Client client, String keyspace,
            byte[] userI1, ColumnParent parent)  {

        SlicePredicate predicate = new SlicePredicate();
        SliceRange sliceRange = new SliceRange();
        sliceRange.setStart(new byte[0]);
        sliceRange.setFinish(new byte[0]);

        predicate.setSlice_range(sliceRange);

        List<ColumnOrSuperColumn> results =
            client.get_slice(   
                keyspace, 
                userI1, 
                parent, 
                predicate, 
                ConsistencyLevel.ONE
        );

        for (ColumnOrSuperColumn cosc : results) {
            System.out.println("column name:      " + new String(cosc.column.name));
            System.out.println("column value:     " + new String(cosc.column.value));
            System.out.println("column timestamp: " + cosc.column.timestamp);
        }
    }
Schildmeijer
Thanks. I have updated the question. Anyway, I tried it again but it still doesn't work.
Zubair
timeout...how many columns (for key 'K') do you expect to get back? millions?
Schildmeijer
2 columns. In cassandra-cli I get back:cassandra> get Keyspace1.KeyValue['name'] => (column=value, value=zubair2, timestamp=1)=> (column=user, value=root, timestamp=1272193083806000)
Zubair
I finally got it working. Needed "reversed=true" AND the count to be present though
Zubair
Does thrift_client:call(C, "describe_version") work as intended?
Schildmeijer
Oh excellent...
Schildmeijer
In Erlang it is : thrift_client:call(C, 'describe_version',[]). : and it returns : {ok,<<"2.1.0">>}
Zubair
know what, it would be kick ass if you updated the wiki (http://wiki.apache.org/cassandra/ThriftExamples) with some Erlang examples. A simple insert/get is more than we currently have.
Schildmeijer
I do plan on adding some examples there at some point, if only I can get the full thrift API working myself :) Now I'm having problems with batch_mutate
Zubair