Irfan21
Irfan21

Reputation: 17

How to check length of text field of Cassandra table

There is one field 'name' in our Cassandra database whose data type is type 'text' How do I retrieve the data which has length of the 'name' field greater than some number using Cassandra query.

Upvotes: 0

Views: 1245

Answers (1)

Alex Ott
Alex Ott

Reputation: 87119

As was pointed in the comment, it's easy to add the user-defined function, and use it to retrieve the length of the text field, but the catch is that you can't use the user-defined function in the WHERE condition (see CASSANDRA-8488).

Even if it was possible, if you only have this as condition - that's a bad query for Cassandra, as it will need to go through all data in the database, and filter them out. For such tasks, usually things like, Spark are used - you can read data via Spark Cassandra Connector, and apply necessary filtering conditions. But this will involve reading all of the data from database, and then performing the filtering - this would be quite slower than normal CQL queries, but at least automatically parallelized.

Upvotes: 1

Related Questions