Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要使用cassandra中的部分复合行键搜索数据_Cassandra - Fatal编程技术网

需要使用cassandra中的部分复合行键搜索数据

需要使用cassandra中的部分复合行键搜索数据,cassandra,Cassandra,我对卡桑德拉还不熟悉,只是玩玩而已。我已经创建了一个列族,它具有复合键和复合列。以下是相同的脚本: create column family TestCompositeKey with key_validation_class='CompositeType(UTF8Type, TimeUUIDType)' and comparator='CompositeType(UTF8Type, UTF8Type, UTF8Type, UTF8Type)' and default_validation_cl

我对卡桑德拉还不熟悉,只是玩玩而已。我已经创建了一个列
,它具有复合键复合列。以下是相同的脚本:

create column family TestCompositeKey with key_validation_class='CompositeType(UTF8Type, TimeUUIDType)' and comparator='CompositeType(UTF8Type, UTF8Type, UTF8Type, UTF8Type)' and default_validation_class='UTF8Type';
使用Hector在列族中插入数据后,以下是我在CLI上看到的视图:

RowKey: AB:e9a87550-c84b-11e2-8236-180373b60c1a
=> (column=0007:TAR:PUB:BD_2013_01_11_0125094813, value=TESTSEARCH, timestamp=1369823914277000)
现在我只想通过行键中给定的'AB'搜索数据,因为键的第二部分是动态的。当我给出完整的行键时,它工作得很好。请告诉我怎么做。我也在列上提供搜索条件以及指定键

谢谢 哈里什·库马尔(Harish Kumar)

您不能这样做(至少效率很高):要按行键查找,您需要整个键。通常,应该避免使用TimeUUID作为行键,除非您有其他一些表作为索引来检索查询的TimeUUID

如果只想通过键的第一个组件进行查找,则应将第二个组件移动到列组合中,并将单个组件作为行键。定义是

create column family TestCompositeKey with key_validation_class='UTF8Type' and comparator='CompositeType(TimeUUIDType, UTF8Type, UTF8Type, UTF8Type, UTF8Type)' and default_validation_class='UTF8Type';
如果使用CQL3定义:

CREATE TABLE TestCompositeKey (
    a varchar,
    b timeuuid varchar,
    c varchar,
    d varchar,
    e varchar,
    f varchar,
    PRIMARY KEY (a, b, c, d, e, f)
);
您将得到与我描述的基本相同的模式。行键(CQL语言中的分区键)是a,列名是b:c:d:e:f的组合。

您不能这样做(至少有效):要按行键查找,您需要整个键。通常,应该避免使用TimeUUID作为行键,除非您有其他一些表作为索引来检索查询的TimeUUID

如果只想通过键的第一个组件进行查找,则应将第二个组件移动到列组合中,并将单个组件作为行键。定义是

create column family TestCompositeKey with key_validation_class='UTF8Type' and comparator='CompositeType(TimeUUIDType, UTF8Type, UTF8Type, UTF8Type, UTF8Type)' and default_validation_class='UTF8Type';
如果使用CQL3定义:

CREATE TABLE TestCompositeKey (
    a varchar,
    b timeuuid varchar,
    c varchar,
    d varchar,
    e varchar,
    f varchar,
    PRIMARY KEY (a, b, c, d, e, f)
);

您将得到与我描述的基本相同的模式。行键(CQL语言中的分区键)是a,列名是b:c:d:e:f的组合。

感谢您更正和改进了查询内容。感谢您更正和改进了查询内容。