Cassandra - WHERE clause with primary key flaws

I am new to cassandra and I use it for analytics tasks (requires good indexing).

I read in this post (and others): cassandra, select through a non-primary key , which I cannot request from my database with non-primary key columns with WHERE clause .

To do this, it seems that there are 3 possibilities (ALL with big flaws):

  • Create a secondary index (not recommended for performance issues).
  • Create a new table (I don't want redundant data, even if this is normal with cassandra).
  • Place the column that I want to query within the primary key, in which case I need to define all parts of the primary key in my WHERE clause, and I cannot use a statement other than IN or = .

Is there any other way to do what I'm trying to do ( WHERE clause with non-primary key column) without having 3 restrictions above?

+11
database indexing where-clause cassandra nosql
source share
4 answers

Inside Kassandra itself, you are limited by the options that you specified above. If you want to know why look here:

Deep look at CQL Where clause

However, if you are trying to run analytics for the information stored in Cassandra, then you should take a look at Spark. Spark is designed for large-scale data processing in distributed systems. In fact, if you are considering using Datastax (see here ), which has some nice integration features between Spark and Cassandra specifically for loading and saving data. There are both free (Community) and paid (Enterprise) editions.

+6
source share

I assume the table is for a different purpose, given that the fields you want to query are not part of the partitioning key. My suggestion was to duplicate the table and call it the fields you want to query. I would recommend developing a new table for a specific purpose, which you will use in accordance with the Data Modeling Concept .

Cassandra offers several advantages, such as linear scaling, etc., introducing certain restrictions on what you can do with CQL.

0
source share

I had a similar problem when using cassandra 2.x version, upgrade your version to cassandra version 3.0 and higher. It was the only solution for me.

0
source share

Please try using IF in your query:

 UPDATE [keyspace_name.] table_name [USING TTL time_value | USING TIMESTAMP timestamp_value] SET assignment [, assignment] . . . WHERE row_specification [IF EXISTS | IF condition [AND condition] . . .] ; 

see https://docs.datastax.com/en/archived/cql/3.3/cql/cql_reference/cqlUpdate.html

0
source share

All Articles