kundera icon indicating copy to clipboard operation
kundera copied to clipboard

i can not excute native batch CQL !

Open zhouhero opened this issue 13 years ago • 28 comments

i try to excute batch cql by using kundera2.2's native Query in cassandra 1.1.5 , it failed. Is kundera2.2 not support btach cql ?

[MY BTACH CQL3]

BEGIN BATCH USING CONSISTENCY QUORUM INSERT INTO users (userid, password, name) VALUES ('user2', 'ch@ngem3b', 'second user'); UPDATE users SET password = 'ps22dhds' WHERE userid = 'user3'; INSERT INTO users (userid, password) VALUES ('user4', 'ch@ngem3c'); DELETE name FROM users WHERE userid = 'user1'; APPLY BATCH;

[MY CODE] Query query = entityManager.createNativeQuery(strCql, clazz); query.executeUpdate();

zhouhero avatar Dec 25 '12 10:12 zhouhero

I did not try it yet. But i guess executing these as seperate cql3 statements should work!

There is another alternative(JPA Way) to execute this.

setConsistencyLevel() => QUORUM

define batch.size in persistence.xml

Perform your INSERT/UPDATE/DELETE via em over Objects. And then invoke em.flush() for explicit flush, else depending upon batch size it will implicitly flush them down.

-Vivek

mevivs avatar Dec 25 '12 10:12 mevivs

I need to look into, but i guess cassandra java driver must be wrapping this up into addBatch() and executeBatch() jdbc calls!

-Vivek

mevivs avatar Dec 25 '12 10:12 mevivs

I guess, you need to try it without ";" Here it is:

BEGIN BATCH USING CONSISTENCY QUORUM
  INSERT INTO users (KEY, password, name) VALUES ('user2', 'ch@ngem3b', 'second user')
  UPDATE users SET password = 'ps22dhds' WHERE KEY = 'user2'
  INSERT INTO users (KEY, password) VALUES ('user3', 'ch@ngem3c')
  DELETE name FROM users WHERE key = 'user2'
  INSERT INTO users (KEY, password, name) VALUES ('user4', 'ch@ngem3c', 'Andrew')
APPLY BATCH;

http://www.datastax.com/docs/1.0/references/cql/BATCH

mevivs avatar Dec 25 '12 10:12 mevivs

i tried it. the error happend.

[Error Msg] javax.persistence.PersistenceException: InvalidRequestException(why:line 4:0 no viable alternative at input 'APPLY') at com.impetus.client.cassandra.CassandraClientBase.executeQuery(CassandraClientBase.java:710) at com.impetus.client.cassandra.pelops.PelopsClient.executeQuery(PelopsClient.java:597) at com.impetus.client.cassandra.query.CassQuery.onExecuteUpdate(CassQuery.java:209) at com.impetus.kundera.query.QueryImpl.executeUpdate(QueryImpl.java:134) at pokemon.common.base.BaseService.exeNativeUpdate(BaseService.java:287) at pokemon.common.service.Test1Service.doBatch(Test1Service.java:126) at pokemon.common.service.Test1Service$$FastClassByCGLIB$$e6f45817.invoke() at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)

zhouhero avatar Dec 25 '12 10:12 zhouhero

Just now a test case is added demonstrate the same, have a look at commit ada7cacf9aa48f27de6c02463bff0689171e7513 for reference.

A new test case " testCQLBatch()" added.

mevivs avatar Dec 25 '12 11:12 mevivs

thank you very much! it is working well now!

zhouhero avatar Dec 25 '12 11:12 zhouhero

Great! 1 question:

Using/Analyzing kundera for ?

-Vivek

mevivs avatar Dec 25 '12 11:12 mevivs

it's kundera 2.2

zhouhero avatar Dec 25 '12 11:12 zhouhero

Ok . I mean using Kundera for developing any application or creating a case study?

-Vivek

mevivs avatar Dec 25 '12 11:12 mevivs

i am using kundera2.2(2.3) + cassandra1.2(cql3/jpql/jdbc) developing a big application. thank you for your support!!!

zhouhero avatar Dec 25 '12 11:12 zhouhero

when there are more than one table to update/delete/insert, how can i do the batch? you know that only one entity "CassandraBatchEntity " can be set in the createNativeQuery().

Query q = em.createNativeQuery(useNativeSql, CassandraBatchEntity.class);

zhouhero avatar Dec 26 '12 01:12 zhouhero

it did not work when update/insert two different tables in the batch !

zhouhero avatar Dec 26 '12 01:12 zhouhero

please share what are you trying to execute? Entity class is required only to map with database and will wrap into that entity in case of select.(q.getresultList()) . Hence it should work on multiple tables.

-Vivek

mevivs avatar Dec 26 '12 03:12 mevivs

[MY CQL] BEGIN BATCH USING CONSISTENCY QUORUM INSERT INTO test1(id, url) VALUES ('64907b40-29a1-11e2-93fa-90b11c71b811','w') INSERT INTO test2(key, count) VALUES ('key1',12)
APPLY BATCH;

[MY CODE] ... Query q = em.createNativeQuery(useNativeSql, Test1Entity.class); q.executeUpdate ...

[ERROR MSG] javax.persistence.PersistenceException: InvalidRequestException(why:Unknown identifier key) at com.impetus.client.cassandra.CassandraClientBase.executeQuery(CassandraClientBase.java:710) at com.impetus.client.cassandra.pelops.PelopsClient.executeQuery(PelopsClient.java:597) at com.impetus.client.cassandra.query.CassQuery.onExecuteUpdate(CassQuery.java:209) at com.impetus.kundera.query.QueryImpl.executeUpdate(QueryImpl.java:134)

zhouhero avatar Dec 26 '12 03:12 zhouhero

As per error message:

[ERROR MSG]
javax.persistence.PersistenceException: InvalidRequestException(why:Unknown identifier key)
at com.impetus.client.cassandra.CassandraClientBase.executeQuery(CassandraClientBase.java:710)
at com.impetus.client.cassandra.pelops.PelopsClient.executeQuery(PelopsClient.java:597)
at com.impetus.client.cassandra.query.CassQuery.onExecuteUpdate(CassQuery.java:209)
at com.impetus.kundera.query.QueryImpl.executeUpdate(QueryImpl.java:134)

Looks like column family "test2" does not have a column with name "key" ! It has nothing to do Kundera.

mevivs avatar Dec 26 '12 06:12 mevivs

i have confirmed that there is a column in the "test2" table!

zhouhero avatar Dec 26 '12 06:12 zhouhero

"InvalidRequestException(why:Unknown identifier key)" is thrown by Cassandra itself. Which means it is not able to find that identifier.

-Vivek

mevivs avatar Dec 26 '12 06:12 mevivs

Are you able to execute:

BEGIN BATCH USING CONSISTENCY QUORUM INSERT INTO test1(id, url) VALUES ('64907b40-29a1-11e2-93fa-90b11c71b811','w') INSERT INTO test2(key, count) VALUES ('key1',12)

APPLY BATCH;

from CQL shell?

-Vivek

mevivs avatar Dec 26 '12 06:12 mevivs

yes, it can work well in CQL shell;

zhouhero avatar Dec 26 '12 06:12 zhouhero

Ok. Please share column family creation script with "test1" and "test2"

-Vivek

mevivs avatar Dec 26 '12 06:12 mevivs