在Cassandra中查询,从一组UDT中检索

在Cassandra中查询,从一组UDT中检索,cassandra,cassandra-2.1,cassandra-cli,Cassandra,Cassandra 2.1,Cassandra Cli,城市信息作为UDT。城市代码将为“工作”或“家庭”或“模板定位” CREATE TYPE facetmanager_ps1.city ( id int, citycode text, cityname text ); 保存兼职员工名单的UDT;它有一套城市UDT CREATE TYPE facetmanager_ps1.part_time_employees ( firstname text, lastname text, address_set

城市信息作为UDT。城市代码将为“工作”或“家庭”或“模板定位”

CREATE TYPE facetmanager_ps1.city (
    id int,
    citycode text,
    cityname text
);
保存兼职员工名单的UDT;它有一套城市UDT

CREATE TYPE facetmanager_ps1.part_time_employees (
    firstname text,
    lastname text,
    address_set frozen<set<frozen<city>>>
);
创建类型facetmanager\u ps1.兼职员工(
名字文本,
姓氏文本,
地址集冻结
);
保存员工信息的表格。它有一组兼职员工集合

CREATE TABLE facetmanager_ps1.employee (
    id int PRIMARY KEY,
    name text,
    part_time_employee_set set<frozen<part_time_employees>>,
    PRIMARY KEY (id)
)


insert into employee (id,name,part_time_employee_set) 
values 
( 1, 'raghu', 
    {
        {
            firstname: 'r1',
            lastname:'r2',
            address_set : {
                {
                    id: 600000,
                    citycode: 'work',
                    cityname: 'chennai'
                },
                {
                    id:600020,
                    citycode: 'home',
                    cityname: 'kanchipuram'
                }
            }
        }
    }
);


update employee set part_time_employee_set
= part_time_employee_set + 
{ { firstname: 'arun', lastname : 'kannan', address_set :
    {
        {
            id: 600000,
            citycode:'work',
            cityname: 'chennai'
        },
        {
            id: 600000,
            citycode:'home',
            cityname: 'chennai'
        }
    }
}} where id=1;
CREATE TABLE facetmanager\u ps1.employee(
id int主键,
名称文本,
兼职员工集合,
主键(id)
)
插入员工(id、姓名、兼职员工集)
价值观
(1,“raghu”,
{
{
名字:“r1”,
姓氏:'r2',
地址集:{
{
id:600000,
城市代码:“工作”,
城市名称:“钦奈”
},
{
编号:600020,
城市代码:“家”,
城市名称:“kanchipuram”
}
}
}
}
);
更新员工集部分时间员工集
=兼职员工集合+
{{firstname:'arun',lastname:'kannan',地址集:
{
{
id:600000,
城市代码:'工作',
城市名称:“钦奈”
},
{
id:600000,
城市代码:'家',
城市名称:“钦奈”
}
}
}}其中id=1;
从id=1的员工中选择*; 它提供所有兼职员工信息

我的主要问题是:

现在我只需要兼职员工r1的员工信息。我要他的工作地点和家庭地点,即)我要完整的地址 怎么弄到的

select * from employee where id=1 and part_time_employee_set = { { firstname: 'r1' }};
InvalidRequest: Error from server: code=2200 [Invalid query] message="Collection column 'part_time_employee_set' (set<frozen<part_time_employees>>) cannot be restricted by a '=' relation"

select * from employee where id=1 and part_time_employee_set in { { firstname: 'r1' }};
SyntaxException: line 1:64 no viable alternative at input '{' (...employee where id=1 and [part_time_employee_set] in...)
select*from employee,其中id=1,part_time_employee_set={{{firstname:'r1'};
InvalidRequest:来自服务器的错误:code=2200[Invalid query]message=“收集列”part\u time\u employee\u set”(集合)不能由“=”关系限制
在{{firstname:'r1'}中选择*from employee,其中id=1和兼职员工集;
SyntaxException:第1:64行在输入“{”(…employee,其中id=1,在…)中[part_time_employee_set]没有可行的替代方案
问题2:(小问题)

从员工中选择*;
如何在devcenter中显示展开的结果?“展开”命令在dev center中不是命令
但是,如果我将值复制到文本编辑或其他编辑器中。这不是我现在主要关心的问题。

除非创建索引,否则不能使用非主键进行查询。

即使您在
兼职员工集
集合上创建索引,也无法使用冻结字段(
firstname
)进行查询。冻结字段意味着压缩。 还有一件事,您不能选择集合中的部分项。您需要选择整个集合

如果要使用firstname进行查询,则必须更改数据模型

CREATE TABLE employee (
    id int,
    firstname text,
    lastname text,
    address_set set<frozen<city>>,
    name text static,
    PRIMARY KEY (id, firstname, lastname)
);
输出:

 id          | 1
 firstname   | r1
 lastname    | r2
 name        | raghu
 address_set | {{id: 600000, citycode: 'work', cityname: 'chennai'}, {id: 600020, citycode: 'home', cityname: 'kanchipuram'}}

除非创建索引,否则不能使用非主键进行查询。

即使您在
兼职员工集
集合上创建索引,也无法使用冻结字段(
firstname
)进行查询。冻结字段意味着压缩。 还有一件事,您不能选择集合中的部分项。您需要选择整个集合

如果要使用firstname进行查询,则必须更改数据模型

CREATE TABLE employee (
    id int,
    firstname text,
    lastname text,
    address_set set<frozen<city>>,
    name text static,
    PRIMARY KEY (id, firstname, lastname)
);
输出:

 id          | 1
 firstname   | r1
 lastname    | r2
 name        | raghu
 address_set | {{id: 600000, citycode: 'work', cityname: 'chennai'}, {id: 600020, citycode: 'home', cityname: 'kanchipuram'}}