列名 cassandra 中的连字符
Hyphen in column name cassandra
我创建了一个 table,其中一列带有 hypen
create table word ( name text,"all-category" text,primary key(name));
我可以成功做到这一点
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';
但现在当我尝试使用此列进行查询时,如下所示
SELECT * FROM word where "all-category" = 'FOOD';
我收到这个错误
InvalidRequest: code=2200 [Invalid query] message="No supported secondary index found for the non primary key columns restrictions"
这种情况下如何查询?
为了从 cassandra 的列族中查询数据,where 条件中的列应该是主键,或者您必须在该列上创建索引。
要使查询生效,您必须在该字段上创建索引
create index idx_category on word ("all-category")
创建上述索引后,您的上述查询将起作用。
尽管在 cassandra 中应该避免二级索引。
我创建了一个 table,其中一列带有 hypen
create table word ( name text,"all-category" text,primary key(name));
我可以成功做到这一点
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';
但现在当我尝试使用此列进行查询时,如下所示
SELECT * FROM word where "all-category" = 'FOOD';
我收到这个错误
InvalidRequest: code=2200 [Invalid query] message="No supported secondary index found for the non primary key columns restrictions"
这种情况下如何查询?
为了从 cassandra 的列族中查询数据,where 条件中的列应该是主键,或者您必须在该列上创建索引。
要使查询生效,您必须在该字段上创建索引
create index idx_category on word ("all-category")
创建上述索引后,您的上述查询将起作用。 尽管在 cassandra 中应该避免二级索引。