Can't create table with composite key using Astyanax client

前端 未结 1 1430
逝去的感伤
逝去的感伤 2021-01-21 20:10

How do I create table with composite keys using astyanax client. For now I\'ve created it with cqlsh -3, and this is how it looks like in cli:

[default@KS] descr         


        
相关标签:
1条回答
  • 2021-01-21 21:10

    From what I've been able to figure out, composite primary keys represent a major divergence in the protocol and interface to cassandra and the protocol you use controls the features you have access to.

    For instance, astyanax and hector are primarily thrift protocol clients, while CQL, more than just a language, is (or will be?) a binary protocol.

    The two protocols are not equivalent and CQL3 with composite primary keys makes things very different.

    The thing to understand about "TABLES" with composite primary keys is that they essentially translate into wide rows with composite column names. The first part of the primary key is the row key and the remaining parts are used as a prefix along with the TABLE-column name as the column name in the wide row.

    In your instance, the row key is "key" and the column prefix is "timeid", so the flag field of what you are inserting is actually a column named :flag and data is :data and so on.

    In order for this to work, the CQL protocol interface to cassandra is converting "TABLES" into wide rows and transparently handling all of that column naming.

    The thrift interface doesn't take care of this stuff and and when you do a mutation, it just writes columns like it is used to, without the virtual addressing.

    So, in fact, the results do not look right in your cassandra-cli. If you do an insert from cqlsh -3, here is what it should look like from the cassandra-cli point of view (with a simple text date):

    [default@testapp] list my_cf;
    RowKey: mykey
    => (column=20120827:data, value=some data, timestamp=1346090889361000)
    => (column=20120827:flag, value=, timestamp=1346090889361001)
    

    CQL3 and tables look really attractive, but there are some trade-offs to be made and there doesn't seem to be solid java client support yet.

    0 讨论(0)
提交回复
热议问题