How to filter a cassandra request by field in a user-defined type

how to filter cassandra request by user type field? I want to create a people table in my cassandra database, so I am creating this custom type in my cassandra database.

    create type fullname ( firstname text, lastname text );

and I also have this table.

    create table people ( id UUID primary key, name frozen <fullname> );

and I need to filter my query to find out all the people with the last name jolie. how can i query this from this table. and completely, how to filter and query in cassandra? I know that I can remove the full name type and add the first and last name to the main table, but this is an example of what I want to do. I must have a full name type.

+4
source share
1 answer

: UDT. UDT.

// create table, type and index
create type fullname ( firstname text, lastname text );
create table people ( id UUID primary key, name frozen <fullname> );
create index fname_index on your_keyspace.people (name);

// insert some data into it
insert into people (id, name) values (now(), {firstname: 'foo', lastname: 'bar'});
insert into people (id, name) values (now(), {firstname: 'baz', lastname: 'qux'});

// query it by fullname
select * from people where name = { firstname: 'baz', lastname: 'qux' };

// the following will NOT work:
select * from people where name = { firstname: 'baz'};

C *. , , C *, :

create table fname_index (name frozen <fullname> primary key, id uuid);

. , : " PK?":

  • PK (firstname + lastname) hashed, .
  • memtable ( SSTable, , ).
  • PK (, ), C * , ( - lastname ), , . C * , :)

:

  • UDT , , .
  • Cassandra 3.0 ( cassandra UDT)
  • , ( UDT, )
+5

Source: https://habr.com/ru/post/1616833/


All Articles