I'm working on smart parking data stored in Cassandra database and i'm trying to get the last status of each device. I'm working on self-made dataset. here's the description of the table. table description
need help please !
I'm working on smart parking data stored in Cassandra database and i'm trying to get the last status of each device. I'm working on self-made dataset. here's the description of the table. table description
need help please !
Copyright © 2021 Jogjafile Inc.
In Cassandra, you need to design your tables according to your query patterns. Building a table, filling it with data, and then trying to fulfill a query requirement is a very backward approach. The point, is that if you really need to satisfy that query, then your table should have been designed to serve that query from the beginning.
That being said, there may still be a way to make this work. You haven't mentioned which version of Cassandra you are using, but if you are on 3.6+, you can use the PER PARTITION LIMIT clause on your SELECT.
If I build your table structure and INSERT some of your rows:
And I consider your PRIMARY KEY and CLUSTERING ORDER definitions:
You are at least clustering by date (which should be an actual date type, not a text), so that will order your rows in a way that helps you here: