How do I build a two-level index after Cassandra1.1.1 a composite primary key? -

Source: Internet
Author: User
Keywords Nbsp; java psd exe

Recently in use Cassandra, the version is 1.1.1, CQL version is 3.0.0. Encountered the following problems.

Objective: To query and sort using compound primary key, and to use two-level index for multiple condition query.

First CQL the table, using the composite primary key (instigator, Startedat):

&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp;

CREATE TABLE Altercations (instigator text, startedat text, shipsdestroyed text, energyused text,allianceinvolvement Text, PRIMARY KEY (instigator, startedat));

Then establish a Level two index:

CREATE INDEX on altercations (shipsdestroyed);

After performing the Create INDEX operation, Cassandra the error:

Java.lang.IllegalArgumentException at Java.nio.Buffer.limit (buffer.java:249) at Org.apache.cassandra.db.marshal.AbstractCompositeType.getBytes (abstractcompositetype.java:51) at Org.apache.cassandra.db.marshal.AbstractCompositeType.getWithShortLength (abstractcompositetype.java:60) at Org.apache.cassandra.db.marshal.AbstractCompositeType.getString (abstractcompositetype.java:140) at Org.apache.cassandra.config.CFMetaData.getDefaultIndexName (cfmetadata.java:875) at Org.apache.cassandra.config.CFMetaData.addDefaultIndexNames (cfmetadata.java:863) at Org.apache.cassandra.cql3.statements.CreateIndexStatement.announceMigration (createindexstatement.java:90) at Org.apache.cassandra.cql3.statements.SchemaAlteringStatement.execute (schemaalteringstatement.java:99) at Org.apache.cassandra.cql3.QueryProcessor.processStatement (queryprocessor.java:108) at Org.apache.cassandra.cql3.QueryProcessor.process (queryprocessor.java:121) at Org.apache.cassandra.thrift.CassandraServer.execute_cql_query (Cassandraserver.java:1237) at Org.apache.cassandra.thrift.cassandra$processor$execute_cql_query.getresult (Cassandra.java : 3542) at Org.apache.cassandra.thrift.cassandra$processor$execute_cql_query.getresult (Cassandra.java:3530) at Org.apache.thrift.ProcessFunction.process (processfunction.java:32) at Org.apache.thrift.TBaseProcessor.process ( tbaseprocessor.java:34) at Org.apache.cassandra.thrift.customtthreadpoolserver$workerprocess.run ( customtthreadpoolserver.java:186) at Java.util.concurrent.threadpoolexecutor$worker.runtask ( threadpoolexecutor.java:886) at Java.util.concurrent.threadpoolexecutor$worker.run (ThreadPoolExecutor.java:908) At Java.lang.Thread.run (thread.java:619)

However, this error is not possible if you change the composite primary key to a single primary key.

After a day of thinking, I find it really impossible to build a level two index.
I am not very clear on the internal principle of two level index establishment, but refer to Apache Cassandra 1.1 documentation, found that can only use primary key query (is to build several primary key), and the Multiple condition query (except the last one) must use "=" expression.
Like this:
Build table:

CREATE TABLE Altercations (instigator text, startedat text, shipsdestroyed text, energyused text, allianceinvolvement Text, PRIMARY KEY (instigator, Startedat, shipsdestroyed));


Inquire:

SELECT * from altercations WHERE instigator= ' Jayne Cobb ' and startedat = ' 7943-06-23 ' and shipsdestroyed> ' 3 ' Startedat DESC;

. =============== Separator ============================

Problem:

Later, a composite primary key was added, and the table statement was:

CREATE TABLE Altercations (instigator text, startedat text, shipsdestroyed text, energyused text, allianceinvolvement Text, PRIMARY KEY (instigator, Startedat, shipsdestroyed, energyused));

Query statement:

SELECT * from altercations WHERE instigator= ' Jayne Cobb ' and startedat = ' 7943-06-23 ' and shipsdestroyed= ' 3 ' and energyused > ' 4.6 ' ORDER by Startedat DESC;

found that the results of the search is completely confusing, not according to the conditions of the query, as follows:

Instigator:jayne Cobb;  startedat:7943-06-24;  Shipsdestroyed:7;  energyused:4.6;  Allianceinvolvement:false; Gender:null;
Instigator:jayne Cobb;  startedat:7943-06-24;  Shipsdestroyed:6;  energyused:4.6;  Allianceinvolvement:false; Gender:null;
Instigator:jayne Cobb;  startedat:7943-06-24;  Shipsdestroyed:5;  energyused:4.6;  Allianceinvolvement:false; Gender:null;
Instigator:jayne Cobb;  startedat:7943-06-23;  Shipsdestroyed:4;  energyused:4.6;  Allianceinvolvement:false; Gender:null;

It's not clear what's going on! Mainly is energyused> ' 4.6 ' This judgment condition, changes energyused= ' 4.6 ' is no problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.