Cassandra插入布尔错误

Cassandra insert boolean error

我用的是Cassandra,视觉信息是这样的:

[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]

我发现在CQL中可以插入boolean。 cql insert

我的 table 架构是这样的:

CREATE TABLE test.crew (
name text PRIMARY KEY,
alliance_trouble boolean,
bunk int
) WITH bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
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 = '99.0PERCENTILE';

当我使用 cql 插入时

insert into crew (alliance_trouble) values ('true');

显示:

   code=2200 [Invalid query] message="Invalid STRING constant (true) for "alliance_trouble" of type boolean" 

这里有什么问题?如何在 Cassandra 中插入 boolean 类型?

> insert into crew (alliance_trouble) values ('true');
code=2200 [Invalid query] message="Invalid STRING constant (true) for "alliance_trouble" of type boolean"

我在这里看到两个问题。 #1,您正在插入值 true 作为字符串常量。去掉单引号。但即使这样也不能完全解决这个问题:

> insert into crew (alliance_trouble) values (true);
code=2200 [Invalid query] message="Missing mandatory PRIMARY KEY part name"

您不能 INSERT 一个值而不指定主键,或者 name 在这种情况下:

> insert into crew (name,alliance_trouble) values ('Malcolm Reynolds',true);
> SELECT * FROM crew;
 name             | alliance_trouble | bunk
------------------+------------------+------
 Malcolm Reynolds |             True | null

(1 rows)