Search code examples
cassandracql

Converting multi-list row into multiple rows with single elements Cassandra


I have a table in Cassandra with the following schema (simplified):

       id   |     lat      |    lng  
    --------+--------------+-------------  
      uuid  | list<double> | list<double>

I would like to query one row of this table (by id) and obtain something like this:

       id   |    lat    |    lng  
    --------+-----------+-----------  
       id0  |   lat[0]  |   lng[0]
       id0  |   lat[1]  |   lng[1]
       id0  |   lat[2]  |   lng[2]
                  .
                  .
                  .
       id0  |   lat[n]  |   lng[n]

Is this possible? What would be a good approach?

Note: both lists always have the same length.


Solution

  • I think there is no easy way select this from cassandra. Just note, if you know that your values would be use in different ways, you should store it in normalized form (in that context you should store second table).

    Good approach would be understand what is more critical in your task: map JSON, map for new query, how much requests would you have and find compromiss.

    Generally, for Cassandra it is common to save data in different tables for different selects, when talking about different keys/indexes.