0
votes

Good Day

I have this table created on my cassandra 2.0 im trying to read and write with it using astyanax but unfortunately im really new to cassandra and java

create table requestformatlist (
    usedbyid text,          // rowkey
    rfid text , //  rfid 
    keystoadd Set<text>,
    keystoremove Set<text>,
primary key (usedbyid, rfid) );

table contents

gid  | rfid | keystoadd                        | keystoremove
------+------+----------------------------------+----------------------------
1111 | 1111 |             {'AddMe1', 'AddMe2'} | {'RemoveMe1', 'RemoveMe2'}
0003 | 0003 |     {'address', 'name', 'state'} |         {'z1', 'z2', 'z3'}

I have read this but unfortunately Im confused why do we need two writes if we want to add just one row

http://brianoneill.blogspot.com/2012/09/composite-keys-connecting-dots-between.html http://brianoneill.blogspot.com/2012/10/cql-astyanax-and-compoundcomposite-keys.html

i have the astyanaxdao and i could connect with it but cannot read and write to it

i have the following code

public void testRead() throws Exception {
 RequestFormatDAO dao = new RequestFormatDAO("localhost:9160", "l2");
 log(dao.read("0003"));
}


public ColumnList<RequestFormatListEntry> read(String rowKey) throws ConnectionException {
    OperationResult<ColumnList<RequestFormatListEntry>> result = this.getKeyspace().prepareQuery(COLUMN_FAMILY).getKey(rowKey)
            .execute();
    ColumnList<RequestFormatListEntry> requestFormat = result.getResult();
    LOG.debug("Read list [" + rowKey + "]");
    return requestFormat;
}


public class RequestFormatListEntry {
  @Component(ordinal = 0)
  public String rfid;
  @Component(ordinal = 1)
  public String field1;

  public RequestFormatListEntry(){}
}

Results that I have on Read:

Read list [0003]
listEntry.rfid=>[0003]
listEntry.keystoremove=>[null]
listEntry.rfid=>[0003]
listEntry.keystoremove=>[keystoadd]
listEntry.rfid=>[0003]
listEntry.keystoremove=>[keystoadd]
listEntry.rfid=>[0003]
listEntry.keystoremove=>[keystoadd]
listEntry.rfid=>[0003]
listEntry.keystoremove=>[keystoremove]
listEntry.rfid=>[0003]
listEntry.keystoremove=>[keystoremove]
listEntry.rfid=>[0003]
listEntry.keystoremove=>[keystoremove]
1

1 Answers

0
votes

Your problem is that you're trying to access your CQL ("high-level" API) table using Thrift ("low-level" API).

Your shiny CQL table (and you even use CQL3 collections) looks like the sample below, if you're using Thrift.

[default@test] list requestformatlist;
Using default limit of 100
Using default cell limit of 100
-------------------
RowKey: 1111
=> (name=1111:, value=, timestamp=1396662079753000)
=> (name=1111:keystoadd:4164646d6531, value=, timestamp=1396662079753000)
=> (name=1111:keystoadd:4164646d6532, value=, timestamp=1396662079753000)
=> (name=1111:keystoremove:52656d6f766531, value=, timestamp=1396662079753000)
=> (name=1111:keystoremove:52656d6f766532, value=, timestamp=1396662079753000)
-------------------
RowKey: 0003
=> (name=0003:, value=, timestamp=1396662495503000)
=> (name=0003:keystoadd:61646472657373, value=, timestamp=1396662495503000)
=> (name=0003:keystoadd:6e616d65, value=, timestamp=1396662495503000)
=> (name=0003:keystoadd:7374617465, value=, timestamp=1396662495503000)
=> (name=0003:keystoremove:7a31, value=, timestamp=1396662495503000)
=> (name=0003:keystoremove:7a32, value=, timestamp=1396662495503000)
=> (name=0003:keystoremove:7a33, value=, timestamp=1396662495503000)

2 Rows Returned.
Elapsed time: 26 msec(s).
[default@test]

And that explains the results you get from your DAO.

I'm not an Astyanax expert, but probably you should take a look at https://github.com/Netflix/astyanax/wiki/Cql-and-cql3 and don't mess up CQL and Thrift.

A couple of links for further reading: http://www.datastax.com/dev/blog/thrift-to-cql3 http://thelastpickle.com/blog/2013/01/11/primary-keys-in-cql.html