One to many mapping in Cassandra -


i new cassandra , 1 many mapping of user , vehicle. 1 user may have multiple vehicles. user table contain user details name, surname, etc. , vehicle table have vehicle details.

my select query fetch vehicle details particular user.

how should design in cassandra?

you can model in single table:

create table uservehicles (   userid text,   vehicleid text,   name text static,   surname text static,   vehiclemake text,   vehiclemodel text,   vehicleyear text,   primary key (userid,vehicleid) ); 

this way can query vehicles single user in 1 shot, , user data can static stored @ partition key level. long cardinality of user vehicle isn't big (as-in, user has 1000 vehicles) should work fine.

the case have considered above simple. if user has lot of details around 20 30 fields , same vehicle. still suggest have single table , copying user data vehicle?

it depends. use case require returning of them? if so, "yes" still recommend approach. way best query performance out of cassandra, model tables fit queries. cassandra works best when can read single row specific key, or range of rows (stored sequentially). want avoid performing multiple queries or writing queries force cassandra perform random reads.

what consequences of having 2 different tables user , vehicle , vehicle table have primary key user_id , vehicle_id?

in distributed system network time enemy. having 2 tables, making 2 queries...assuming 1 1 ratio of users vehicles. if user has 8 vehicles, need 9 queries achieve result. design above can build result set in 1 query (minimizing network time). userid partition key, query guaranteed served 1 node, opposed additional queries vehicle data require contacting multiple nodes.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -