需要一些关于在cassandra中创建条目的指导

时间:2012-03-12 11:48:43

标签: cassandra command-line-interface

我是cassandra的新手,并且发现在创建一个我正在考虑的某种结构的简单键空间时有点难以理解。我使用cassandra CLI创建了一个名为“acquisition”的密钥空间。

使用Cassandra-CLI如何为“获取”键空间创建以下内容 -

TagNo // This is the super column
{
  ID // This is the column family
   {
     // here we shall have lots of entries. (Rows)
     user1: {rate, distance, capacity}
     user2: {rate, distance, capacity}
    }    
}

速率距离和容量可以存储为字符串或双精度。但此刻并不重要。

我不确定如何使用CLI执行此操作。所以请帮忙

1 个答案:

答案 0 :(得分:2)

  • 创建键空间。

      

    使用placement_strategy =创建键空间获取   'org.apache.cassandra.locator.SimpleStrategy'和strategy_options =   {replication_factor:1};

  • 创建超级列族。

    create column family TagNo with column_type = 'Super' and comparator = 'UTF8Type' and subcomparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and column_metadata = [{ column_name : rate, validation_class : AsciiType}, { column_name : 'distance', validation_class : AsciiType}, {column_name : 'capacity', validation_class : AsciiType}];
    
  • 为TagNo超级列族设置一些示例值。

    [default@acquisition] set TagNo[utf8('ID')]['user1']['rate'] = '10';
    Value inserted.
    Elapsed time: 2 msec(s).
    [default@acquisition] set TagNo[utf8('ID')]['user1']['distance'] = '100'; 
    Value inserted.
    Elapsed time: 2 msec(s).
    [default@acquisition] set TagNo[utf8('ID')]['user1']['capacity'] = '50';
    Value inserted.
    Elapsed time: 2 msec(s).
    [default@acquisition] set TagNo[utf8('ID')]['user2']['capacity'] = '50';
    Value inserted.
    Elapsed time: 2 msec(s).
    [default@acquisition] set TagNo[utf8('ID')]['user2']['rate'] = '20';
    Value inserted.
    Elapsed time: 1 msec(s).
    [default@acquisition] set TagNo[utf8('ID')]['user2']['distance'] = '100'; 
    Value inserted.
    Elapsed time: 2 msec(s).
    
  • 显示值..

    [default@acquisition] get TagNo[utf8('ID')];
    => (super_column=user1,
         (column=capacity, value=50, timestamp=1331605812776000)
         (column=distance, value=100, timestamp=1331605805912000)
         (column=rate, value=10, timestamp=1331605780216000))
    => (super_column=user2,
         (column=capacity, value=50, timestamp=1331605816568000)
         (column=distance, value=100, timestamp=1331605846008000)
         (column=rate, value=20, timestamp=1331605821608000))
    Returned 2 results.
    Elapsed time: 3 msec(s).