Cassandra - 查询不返回带冻结类型的结果

时间:2017-11-25 09:00:47

标签: cassandra

我使用少量primary datatypes和冻结类型address_type创建了一个cassandra表。

CREATE TYPE address_type (
                  first_name text,
                  last_name text,
                  address_line1 text,
                  address_line2 text
              );

CREATE TABLE user (
              id text,
              active_profile boolean,
              addresses frozen<address_type>,
              PRIMARY KEY (id)
          );

并对列addresses编制索引,因为我想根据resultset选择少数address_type.first_name

CREATE INDEX ON user (addresses) ;

最后这是我的查询,它返回 0行

select * from user where addresses = {first_name:'test2'};

当我尝试

select * from "user" where addresses > {first_name:'test2'}; 

导致了

code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: 'addresses > <value>'"

有人能帮助我吗?我在哪里错了?

1 个答案:

答案 0 :(得分:2)

让我们插入一些数据:

cqlsh:test> INSERT INTO user (id , addresses) VALUES ('user_0', {first_name:'Ashraful', last_name:'Islam'});
cqlsh:test> INSERT INTO user (id , addresses) VALUES ('user_1', {first_name:'Ashraful'});
cqlsh:test> SELECT * FROM user ;

 id     | active_profile | addresses
--------+----------------+----------------------------------------------------------------------------------------
 user_1 |           null |    {first_name: 'Ashraful', last_name: null, address_line1: null, address_line2: null}
 user_0 |           null | {first_name: 'Ashraful', last_name: 'Islam', address_line1: null, address_line2: null}

由于地址是冻结类型。你不能用一块冰冻的田地来查询。您必须提供完整的地址价值

示例:

cqlsh:test> SELECT * FROM user WHERE addresses = {first_name:'Ashraful', last_name:'Islam'} ;

 id     | active_profile | addresses
--------+----------------+----------------------------------------------------------------------------------------
 user_0 |           null | {first_name: 'Ashraful', last_name: 'Islam', address_line1: null, address_line2: null}

(1 rows)
cqlsh:test> SELECT * FROM user WHERE addresses = {first_name: 'Ashraful'} ;

 id     | active_profile | addresses
--------+----------------+-------------------------------------------------------------------------------------
 user_1 |           null | {first_name: 'Ashraful', last_name: null, address_line1: null, address_line2: null}

(1 rows)