2012-10-17 3 views
0
내가 CQL3 콘솔에서 테이블을 만든

키 (단 하나의 기본 키 구성이 고유하지, 그들은 함께있을 것입니다) :카산드라/헥터 :에 카운터를 추가 복합 차

CREATE TABLE aggregate_logs (
    bpid varchar, 
    jid int, 
    month int, 
    year int, 
    value counter, 
PRIMARY KEY (bpid, jid, month, year)); 
다음

할 수 있었다 업데이트 및 쿼리를 사용하여 :

UPDATE aggregate_logs SET value = value + 1 WHERE bpid='1' and jid=1 and month=1 and year=2000; 

이 예상대로 작동합니다. 나는 (스칼라) 헥터에서 동일한 업데이트하고 싶었던 :

val aggregateMutator:Mutator[Composite] = HFactory.createMutator(keyspace, compositeSerializer) 

    val compKey = new Composite() 
    compKey.addComponent(bpid, stringSerializer) 
    compKey.addComponent(new Integer(jid), intSerializer) 
    compKey.addComponent(new Integer(month), intSerializer) 
    compKey.addComponent(new Integer(year), intSerializer) 

    aggregateMutator.incrementCounter(compKey, LogsAggregateFamily, "value", 1) 

을하지만 메시지와 함께 오류가 :

val query = new me.prettyprint.cassandra.model.CqlQuery(keyspace, compositeSerializer, stringSerializer, new IntegerSerializer()) 
query.setQuery("UPDATE aggregate_logs SET value = value + 1 WHERE 'bpid'=1 and jid=1 and month=1 and year=2000") 
query.execute() 
:
...HInvalidRequestException: InvalidRequestException(why:String didn't validate.) 

이와 헥터에서 직접 쿼리를 실행

이 오류를 제공합니다 :

InvalidRequestException(why:line 1:59 mismatched input 'and' expecting EOF) 

복합 기본 키 아래에서 카운터를 사용하는 다른 예제가 아닌 것 같습니다. 심지어 가능할까요?

답변

0

그것은 사용하여 확실히 가능 직접 CQL (모두 CQLSH 및 C++, 적어도 통해) :

cqlsh:goh_master> describe table daily_caps;
CREATE TABLE daily_caps ( caps_type ascii, id ascii, value counter, PRIMARY KEY (caps_type, id)) WITH COMPACT STORAGE AND comment='' AND
caching='KEYS_ONLY' AND read_repair_chance=0.100000 AND
gc_grace_seconds=864000 AND replicate_on_write='true' AND
compaction_strategy_class='SizeTieredCompactionStrategy' AND
compression_parameters:sstable_compression='SnappyCompressor';

cqlsh:goh_master> update daily_caps set value=value +1 where caps_type='xp' and id ='myid';

cqlsh:goh_master> select * from daily_caps;

caps_type | id | value

-----------+------+-------

xp | myid | 1

0

CQL3 및 중고품 API 호환되지 않습니다. 따라서 CQL3을 사용하여 열 패밀리를 만들고 Hector 또는 다른 중고 안경 클라이언트와 액세스하면 작동하지 않습니다. 자세한 내용은 다음을 참조하십시오.

https://issues.apache.org/jira/browse/CASSANDRA-4377