CQL 3 Inserting Data w/ Composite Keys

56 views
Skip to first unread message

Paul Monday

unread,
May 10, 2013, 2:52:20 PM5/10/13
to hector...@googlegroups.com
I am trying to use CQL3 through the Hector API.  I've had some limited successes, but they are matched and exceeded by failures :(  Some successes include:  Insertion of data with UUID keys through the Mutator, limited query successes.

Right now I'm trying to insert to a CQL3 table with a composite key, am I pushing CQL3 through Hector too hard?  I'm using
   <dependency>
  <groupId>org.hectorclient</groupId>
  <artifactId>hector-core</artifactId>
  <version>1.1-3</version>
  </dependency>

Here is the table created in cqlsh -3
CREATE TABLE providers (providerid uuid, providername text, providertype text, active int, data text, primary key (providerid, providername, providertype, active)) WITH COMPACT STORAGE;

And here is an insert off the command line:
cqlsh:consumerinformation_3_0> insert into providers (providerid, providername, providertype, active, data) values (603db8fa-a2b7-4744-b568-11a2722f2042, 'M', 'Z', 0, 'data');
cqlsh:consumerinformation_3_0> select * from providers;

 providerid                           | providername | providertype | active | data
--------------------------------------+--------------+--------------+--------+------
 603db8fa-a2b7-4744-b568-11a2722f2042 |            M |            Z |      0 | data

cqlsh:consumerinformation_3_0> 

Yay, it works in cqlsh.

But, translating this to the Hector Client has proven to be a bit of a mess.  I've tried a CqlQuery, but this results in a 
12:45:56,115 DEBUG HomeTemplate:68 - Query String: insert into providers (providername, providertype, active, providerid) VALUES('M', 'C', 0, efde8f8a-9c3e-4547-99a8-b33eccdd7b2b)
Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:Expected key 'PROVIDERID' to be present in WHERE clause for 'providers')

Here is the code:

CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(keyspace, se, se, se);
cqlQuery.setQuery(getInsertQuery(newProvider));
QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();
return newProvider;

So, I went to the Mutator Approach, but this gave me

Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:UUIDs must be exactly 16 bytes)

 Mutator<Composite> providerMutator = HFactory.createMutator(keyspace,

                CompositeSerializer.get());

        Composite rowKey = new Composite();

        rowKey.add(0, newProvider.getProviderName());

        rowKey.add(1, newProvider.getProviderType());

        rowKey.add(2, newProvider.getActive());

        rowKey.add(3, newProvider.getProviderId());

        providerMutator.addInsertion(rowKey, columnFamily

HFactory.createColumn("data", "Data",

StringSerializer.get(), StringSerializer.get()));


        logger.debug("Saving Provider: "

                + newProvider.toString() + " to " 

        + keyspaceId + ", " + columnFamily);

        // insertColumns(providerMutator, rowKey, columnFamily, newProvider);

        providerMutator.execute();

        return newProvider;


Reply all
Reply to author
Forward
0 new messages