Composite partition key support

102 views
Skip to first unread message

TK

unread,
Apr 3, 2015, 6:23:19 PM4/3/15
to kundera...@googlegroups.com
Hi Team,

As of now Kundera has composite key support for Cassandra (https://github.com/impetus-opensource/Kundera/wiki/Using-Compound-keys-with-Kundera).  I have used it in my project.


For one of my use case I need to have composite partition key

e.g :-

CREATE TABLE Cats (
  block_id uuid,
  breed text,
  color text,
  short_hair boolean,
  PRIMARY KEY ((block_id, breed), color, short_hair)
);

Please refer http://docs.datastax.com/en/cql/3.0/cql/cql_reference/create_table_r.html?scroll=reference_ds_v3f_vfk_xj__using-a-composite-partition-key for details.

I believe this is not supported yet in Kundera?
If so do you have plans to implement the same?  

Thanks,
T K



Chhavi Gangwal

unread,
Apr 6, 2015, 3:04:39 AM4/6/15
to kundera...@googlegroups.com

TK

unread,
Apr 7, 2015, 12:22:10 AM4/7/15
to kundera...@googlegroups.com

Hi Chhavi,

Thanks for the reply.

I tried running the sample examples as referred by you but was not able to create the table as expected.  I am using cassandra 2.1.3 and kundera version 2.15.

Here is what I see :-
- The table structure doesn't get created with expected multiple partitions.

- The table gets created with partitionKey as "blob".

- As the table is not created with proper structure the data insertion fails.

Please find the snapshots of the classes I am using from your example below. Also find the snapshot of table structure created.




Here is log trace from eclipse which fails on insertion as I mentioned above.


2015-04-06 21:16:21,772 INFO main com.impetus.kundera.persistence.EntityManagerFactoryImpl - EntityManagerFactory created for persistence unit : oneplatform_pu
2015-04-06 21:16:21,775 DEBUG main com.impetus.kundera.persistence.EntityManagerImpl - Creating EntityManager for persistence unit : oneplatform_pu
2015-04-06 21:16:21,781 INFO main com.impetus.kundera.persistence.EntityManagerImpl - Returning client instance for persistence unit oneplatform_pu.
2015-04-06 21:16:21,781 DEBUG main com.impetus.kundera.loader.GenericClientFactory - Returning fresh client instance for persistence unit : oneplatform_pu
2015-04-06 21:16:21,792 DEBUG main com.impetus.kundera.persistence.EntityManagerImpl - Created EntityManager for persistence unit : oneplatform_pu
2015-04-06 21:16:21,801 DEBUG main com.impetus.kundera.persistence.PersistenceDelegator - Flushing following flush stack to database(s) (showing stack objects from top to bottom):
[[com.thomson.citation.entity.EntityWithMultiplePartitionKey$com.thomson.citation.entity.IdWithMultiplePartitionKey@1033576a]com.thomson.citation.entity.EntityWithMultiplePartitionKey$com.thomson.citation.entity.IdWithMultiplePartitionKey@1033576a]
2015-04-06 21:16:21,802 DEBUG main com.impetus.kundera.persistence.PersistenceDelegator - Data persisted successfully for entity class com.thomson.citation.entity.EntityWithMultiplePartitionKey.
2015-04-06 21:16:21,802 DEBUG main com.impetus.kundera.persistence.PersistenceDelegator - Flushing following flush stack to database(s) (showing stack objects from top to bottom):
[]
2015-04-06 21:16:21,804 INFO main com.impetus.client.cassandra.CassandraClientBase - Returning cql query  INSERT INTO "entitywithmultiplepartitionkey"("entityDiscription","action","partitionKey1","partitionKey2","clusterkey1","clusterkey2") VALUES('Entity to test composite key with multiple partition key.','Persisting','partitionKey1',1,'clusterkey1',11) .
2015-04-06 21:16:21,805 ERROR main com.impetus.client.cassandra.CassandraClientBase - Error while executing query BEGIN BATCH   INSERT INTO "entitywithmultiplepartitionkey"("entityDiscription","action","partitionKey1","partitionKey2","clusterkey1","clusterkey2") VALUES('Entity to test composite key with multiple partition key.','Persisting','partitionKey1',1,'clusterkey1',11)  APPLY BATCH
2015-04-06 21:16:21,805 ERROR main com.impetus.client.cassandra.CassandraClientBase - Error during executing query BEGIN BATCH   INSERT INTO "entitywithmultiplepartitionkey"("entityDiscription","action","partitionKey1","partitionKey2","clusterkey1","clusterkey2") VALUES('Entity to test composite key with multiple partition key.','Persisting','partitionKey1',1,'clusterkey1',11)  APPLY BATCH, Caused by: com.impetus.kundera.KunderaException: InvalidRequestException(why:Unknown identifier partitionKey1) .
2015-04-06 21:16:21,805 ERROR main com.impetus.client.cassandra.CassandraClientBase - Error while persisting record. Caused by: .
javax.persistence.PersistenceException: com.impetus.kundera.KunderaException: InvalidRequestException(why:Unknown identifier partitionKey1)
    at com.impetus.client.cassandra.CassandraClientBase.executeCQLQuery(CassandraClientBase.java:1719)
    at com.impetus.client.cassandra.CassandraClientBase.executeBatch(CassandraClientBase.java:1447)
    at com.impetus.kundera.persistence.PersistenceDelegator.execute(PersistenceDelegator.java:822)
    at com.impetus.kundera.persistence.PersistenceDelegator.doFlush(PersistenceDelegator.java:737)
    at com.impetus.kundera.persistence.PersistenceDelegator.close(PersistenceDelegator.java:571)
    at com.impetus.kundera.persistence.EntityManagerImpl.close(EntityManagerImpl.java:351)
    at com.thomson.dao.impl.CitationsDaoImpl.createMultiple(CitationsDaoImpl.java:696)
    at com.thomson.dao.impl.CitationDaoImplTest.test52CreateMultiplePartition(CitationDaoImplTest.java:256)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: com.impetus.kundera.KunderaException: InvalidRequestException(why:Unknown identifier partitionKey1)
    at com.impetus.client.cassandra.CassandraClientBase.execute(CassandraClientBase.java:2101)
    at com.impetus.client.cassandra.CassandraClientBase.executeCQLQuery(CassandraClientBase.java:1708)
    ... 32 more
Caused by: InvalidRequestException(why:Unknown identifier partitionKey1)
    at org.apache.cassandra.thrift.Cassandra$execute_cql3_query_result$execute_cql3_query_resultStandardScheme.read(Cassandra.java:49032)
    at org.apache.cassandra.thrift.Cassandra$execute_cql3_query_result$execute_cql3_query_resultStandardScheme.read(Cassandra.java:49009)
    at org.apache.cassandra.thrift.Cassandra$execute_cql3_query_result.read(Cassandra.java:48924)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_execute_cql3_query(Cassandra.java:1693)
    at org.apache.cassandra.thrift.Cassandra$Client.execute_cql3_query(Cassandra.java:1678)
    at com.impetus.client.cassandra.CassandraClientBase.execute(CassandraClientBase.java:2097)
    ... 33 more


Please suggest.

Thanks,

TK

Chhavi Gangwal

unread,
Apr 7, 2015, 2:32:38 AM4/7/15
to kundera...@googlegroups.com
 Hi TK,

  Cassandra 2.1.+ is supported from Kundera -2.15.1 release onwards with the latest tagged version being 2.16. So please update your project's dependency to kundera- cassandra 2.16. Also, please make sure you have cql3 enabled when you create EntitymanagerFactory to avoid schema creation via cql2 by default.

Map<String, Object> puProperties = new HashMap<String, Object>();
    puProperties.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu", puProperties);
    EntityManager em = emf.createEntityManager();

   
Hope that Helps !
Chhavi

TK

unread,
Apr 7, 2015, 12:00:56 PM4/7/15
to kundera...@googlegroups.com


Hi Chhavi,

I upgraded my project dependency to kundera-cassandra-2.16 and already have CQL3 enabled while creating EntitymanagerFactory. But I still see the same issue.

Here is my persistence.xml for your reference.

Thanks,

TK

karthik prasad

unread,
Apr 8, 2015, 4:03:15 AM4/8/15
to kundera...@googlegroups.com
Hi TK,

Kundera supports CRUD operations on schema with composite partition keys. But schema generation is not yet enabled and we are considering it in our next release (3.0).

Work around would be to create table manually and proceed with operations using Kundera.

You can track the issue on github: https://github.com/impetus-opensource/Kundera/issues/734

Thanks,
Karthik.

TK

unread,
Apr 8, 2015, 2:00:27 PM4/8/15
to kundera...@googlegroups.com
Thanks Karthik and Chhavi.
Reply all
Reply to author
Forward
0 new messages