【问题标题】:Cassandra: create CompositeType columnCassandra:创建 CompositeType 列
【发布时间】:2012-10-23 14:48:56
【问题描述】:

我是 cassandra 的新手,我正在尝试创建一个允许我拥有一行的架构

users: {
    name: <value>,
    ...
    phone_numbers:1: <value>,
    phone_numbers:2: <value>,
    ...
    phone_numbers: <value>
 }

我一直在阅读有关复合列的信息,并且只能找到主键是复合列的示例。那么是否可以在一个 CF 中包含上述内容?

我的尝试是:-

create column family users with comparator=AsciiType
and key_validation_class=AsciiType
and column_metadata=[
{column_name: name, validation_class: AsciiType, index_type: KEYS},
{column_name: phone_numbers, validation_class: CompositeType(AsciiType, IntegerType), index_type: KEYS}];

上述失败。 任何帮助表示赞赏 干杯

【问题讨论】:

    标签: cassandra composite cql


    【解决方案1】:

    cassandra 中的CompositeType 可以用作comparator [列名类型] 或key_validation_class [行键类型],但不能用作default_validation_class [列值类型]

    create column family users with 
    comparator='CompositeType(UTF8Type, IntegerType)' 
    and key_validation_class='UTF8Type'
    

    应该适合你。我已经分享了详细的post cassandra 中的复合类型

    【讨论】:

    • 那么设计我的架构的最佳方式是在两个 CF 中吗?一个用于比较器 = AsciiType 的用户,第二个 CF 是 user_phone_numers,比较器 = CompositeType(AsciiType, IntegerType)?
    • 我认为您的 OP 正在创建 CompositeTypes :P 如果您需要一些有关架构的帮助,请尝试描述您的用例并读取、写入模式
    【解决方案2】:

    在 cql 3 中,您可以将其声明为:(为简单起见,使用 ascii 类型)

    创建表用户(用户ascii,phoneid ascii,phonenumber ascii, 主键(用户,电话号码)),具有紧凑的存储空间;

    填写为

    插入用户(user,phoneid,phonenumber 值('john smith','home','555-121345')

    插入用户(user,phoneid,phonenumber 值('john smith','office','555-121346')

    并将其检索为

    从 user = 'john smith' 的用户中选择 *

    用户,电话号码,电话号码

    '约翰·史密斯','家','555-121345'

    '约翰·史密斯','办公室','555-121346'

    希望对你有帮助

    【讨论】:

    • 这很有帮助,所以我仍然只能通过一个键的一部分进行搜索,但是有复合键允许我存储数组。
    猜你喜欢
    • 2013-12-05
    • 2012-11-26
    • 1970-01-01
    • 2012-07-12
    • 2014-09-08
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 2016-07-24
    相关资源
    最近更新 更多