1
votes

I created a table with one of the column having hypen

create table word ( name text,"all-category" text,primary key(name));

I could do this successfully

desc schema; 
CREATE KEYSPACE demo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;

CREATE TABLE demo.word (
name text PRIMARY KEY,
"all-category" text
) WITH bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';

but now when i try to query using this column as follows

SELECT * FROM word where "all-category" = 'FOOD';

I get this error

InvalidRequest: code=2200 [Invalid query] message="No supported secondary index found for the non primary key columns restrictions"

How to query in this case ?

1

1 Answers

2
votes

In order to query data from column family in cassandra the column in where condition should be either primary key or you must create index on that column.

for your query to work you will have to create index on that field

create index idx_category on word ("all-category")

After creating the above index your above query will work. Though secondary indexes should be avoided in cassandra.