I would advise you not to use raw thrift. It's just a low-level transport as far as CQL3 is concerned, and what you will get is binary encoded data that you will have to decode manually. Use a client library (like https://github.com/datastax/java-driver) that will do that for you.
Though to answer your initial question, the binary format used by map (that you will have to decode yourself) is described in https://git-wip-us.apache.org/repos/asf?p=cassandra.git;a=blob;f=doc/native_protocol.spec(Section 6). -- Sylvain On Mon, Mar 25, 2013 at 2:30 PM, Szárnyas Gábor <[email protected]> wrote: > Hello! > > I got stuck when trying to query CQL3 collections from Java. > I'm using Cassandra 1.2.3 with CQL3. I created a column family to store a > property graph's edges with the following command: > > CREATE TABLE vertices ( > id text PRIMARY KEY, > properties map<text, text> > ) > > I can access the data from the cqlsh, however, I couldn't figure out how > to iterate through the map entries in Java. > The following code iterates through the rows and columns, but does not > retrieve the key-value pairs of the "properties" map. > > String query = "SELECT * FROM vertices"; > CqlResult cqlResult = > client.execute_cql3_query(ByteBuffer.wrap(query.getBytes()), > COMPRESSION_LEVEL.NONE, CONSISTENCY_LEVEL.ALL); > > Iterator<CqlRow> rowsIterator = cqlResult.getRowsIterator(); > while (rowsIterator.hasNext()) { > CqlRow cqlRow = rowsIterator.next(); > Iterator<Column> columnsIterator = cqlRow.getColumnsIterator(); > while (columnsIterator.hasNext()) { > Column cqlColumn = columnsIterator.next(); > > byte[] name = cqlColumn.getName(); > String nameString = new String(name); > System.out.print(nameString + ": "); > > byte[] value = cqlColumn.getValue(); > String string = new String(value); > System.out.println(string); > } > } > > The cqlResult.getSchema() method shows the column with the type > "org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.UTF8Type,org.apache.cassandra.db.marshal.UTF8Type)". > How can I create a HashMap<String, String> from each row's properties cell? > > Thanks, > Gabor >
