Cassandra query statement: cql (Cassandra Query Language)

Source: Internet
Author: User
Tags cassandra

Similar to SQL (Structured Query Language), Cassandra will also provide Cassandra query statements (cql) in future releases ).

For example, if the keyspace name is websiteks and cql is used:

Use websiteks;

Query the value of column family with standard1 and key as K:

Select from standard1 where key = "K ";

Update the value of column family to standard1, key to k, and column to C:

Update standard1 with row ("K", COL ("C", "Hello! "));

For more information about cql syntax, see the official documentation: https://svn.apache.org/repos/asf/cassandra/trunk/doc/cql/CQL.html.

Aside from the cql syntax, it goes deep into cassandra's internal implementation. It is nothing more than parsing the cql operation type, and then converting it into an internal operation interface for calling.

Use statement implementation logic:

Case use:
Clientstate. setkeyspace (string) statement. statement );

The keyspace is switched here, which is consistent with the setkeyspace that calls the thrift API directly.

Select statement implementation logic:

Case select:
Selectstatement select = (selectstatement) statement. statement;
List <cqlrow> avrorows = new arraylist <cqlrow> ();
Avroresult. type = cqlresulttype. Rows;
List <org. Apache. Cassandra. DB. Row> rows = NULL;
If (! Select. getkeypredicates (). isrange ())
Rows = multislice (keyspace, select );
Else
Rows = multirangeslice (keyspace, select );

This is consistent with the mutislice or multirangeslice that calls the thrift API:

Update statement implementation logic:

Case update:
Updatestatement update = (updatestatement) statement. statement;
Validatecolumnfamily (keyspace, update. getcolumnfamily ());
Avroresult. type = cqlresulttype. void;
List <rowmutation> rowmutations = new arraylist <rowmutation> ();
For (Row row: update. getrows ())
{
Validatekey (row. getkey (). getbytebuffer ());
Rowmutation Rm = new rowmutation (keyspace, row. getkey (). getbytebuffer ());
For (Org. Apache. Cassandra. cql. Column Col: Row. getcolumns ())
{
Rm. Add (New querypath (update. getcolumnfamily (), null, col. getname (). getbytebuffer ()),
Col. getvalue (). getbytebuffer (),
System. currenttimemillis ());
}
Rowmutations. Add (RM );
}
Try
{
Storageproxy. mutate (rowmutations, update. getconsistencylevel ());
}
Catch (Org. Apache. Cassandra. Thrift. unavailableexception E)
{
Throw new unavailableexception ();
}
Catch (timeoutexception E)
{
Throw new timedoutexception ();
}

This is consistent with the batch_mutate function that calls the thrift API:

Although the cql function is still weak, it is a huge step forward.

For more information about CassandraArticle: Http://www.cnblogs.com/gpcuster/tag/Cassandra/

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.