I just solved it. It was my mistake with using ByteBuffer.. the array() method returns the entire array without considering the index offset into the array. It works using String rowName = Charset.forName(UTF_8).decode(entry.getKey()).toString();
Ross On 1 February 2012 22:42, Ross Black <ross.w.bl...@gmail.com> wrote: > Hi, > > I am trying to get multiget_slice working with the raw thrift client, but > am having problems interpreting the returned keys. > I assume I am doing something wrong but figure what. > > Here is the test program... > > import org.apache.cassandra.thrift.*; > import org.apache.thrift.protocol.TBinaryProtocol; > import org.apache.thrift.protocol.TProtocol; > import org.apache.thrift.transport.TFramedTransport; > import org.apache.thrift.transport.TSocket; > import org.apache.thrift.transport.TTransport; > > import java.nio.ByteBuffer; > import java.util.Arrays; > import java.util.Collections; > import java.util.List; > import java.util.Map; > > public class TestMultiGet { > > private static final String KEYSPACE = "junk"; > private static final String COLUMN_FAMILY = "blah"; > > public static void main(String[] args) throws Exception { > TTransport transport = new TFramedTransport(new > TSocket("localhost", 9160, 30 * 1000)); > transport.open(); > TProtocol protocol = new TBinaryProtocol(transport); > Cassandra.Client client = new Cassandra.Client(protocol); > > ByteBuffer rowKey = ByteBuffer.wrap("row111".getBytes()); > ByteBuffer colKey = ByteBuffer.wrap("BBB".getBytes()); > ByteBuffer value = ByteBuffer.wrap("datadata".getBytes()); > long timestamp = System.currentTimeMillis(); > ColumnParent columnParent = new ColumnParent(COLUMN_FAMILY); > Column column = new > Column().setName(colKey).setValue(value).setTimestamp(timestamp); > > client.set_keyspace(KEYSPACE); > client.insert(rowKey, columnParent, column, ConsistencyLevel.ONE); > > SlicePredicate predicate = new > SlicePredicate().setColumn_names(Collections.singletonList(colKey)); > Map<ByteBuffer, List<ColumnOrSuperColumn>> sliceMap = > client.multiget_slice(Collections.singletonList(rowKey), columnParent, > predicate, ConsistencyLevel.QUORUM); > for (Map.Entry<ByteBuffer, List<ColumnOrSuperColumn>> entry : > sliceMap.entrySet()) { > byte[] key = entry.getKey().array(); > System.err.println("Row bytes = " + Arrays.toString(key)); > System.err.println("Row = ###\n" + new String(key) + "###"); > > List<ColumnOrSuperColumn> columns = entry.getValue(); > for (ColumnOrSuperColumn col : columns) { > byte[] name = col.getColumn().getName(); > System.err.println("Column = " + new String(name)); > } > } > } > } > > > And here is the output I get when I run it... > Row bytes = [-128, 1, 0, 2, 0, 0, 0, 14, 109, 117, 108, 116, 105, 103, > 101, 116, 95, 115, 108, 105, 99, 101, 0, 0, 0, 3, 13, 0, 0, 11, 15, 0, 0, > 0, 1, 0, 0, 0, 6, 114, 111, 119, 49, 49, 49, 12, 0, 0, 0, 1, 12, 0, 1, 11, > 0, 1, 0, 0, 0, 3, 66, 66, 66, 11, 0, 2, 0, 0, 0, 8, 100, 97, 116, 97, 100, > 97, 116, 97, 10, 0, 3, 0, 0, 1, 53, 56, -84, 0, 87, 0, 0, 0] > Row = ###@row111@BBB@datadata@### > Column = BBB > > where the @ represents unprintable chars. > > I assumed that the keys in the returned Map would be the same as the keys > passed in, but they instead seem to contain the entire result. > I have tried this with 0.8.x and 1.0.7 with the same result. > > Should the returned keys be the same as the requested keys, or do they > need to be interpreted as some other data structure? > What do I need to do to fix this? > > > Thanks, > Ross > >