在Cassandra cqlsh中插入数据时列名称/值不匹配
因此,我使用当前查询将数据插入到我的列族中:在Cassandra cqlsh中插入数据时列名称/值不匹配,cassandra,nosql,cql,cql3,cqlsh,Cassandra,Nosql,Cql,Cql3,Cqlsh,因此,我使用当前查询将数据插入到我的列族中: INSERT INTO airports (apid, name, iata, icao, x, y, elevation, code, name, oa_code, dst, cid, name, timezone, tz_id) VALUES (12012,'Ararat Airport','ARY','YARA','142.98899841308594','-37.30939865112305',1008,{ code: 'AS', name:
INSERT INTO airports (apid, name, iata, icao, x, y, elevation, code, name, oa_code, dst, cid, name, timezone, tz_id) VALUES (12012,'Ararat Airport','ARY','YARA','142.98899841308594','-37.30939865112305',1008,{ code: 'AS', name: 'Australia', oa_code: 'AU', dst: 'U',city: { cid: 1, name: '', timezone: '', tz_id: ''}});
现在,我得到了一个错误:不匹配的列名/值
当这是我当前的airports columnfamily模型时:
CREATE TYPE movielens.cityudt (
cid varint,
name text,
timezone varint,
tz_id text
);
CREATE TYPE movielens.countryudt (
code text,
name text,
oa_code text,
dst text,
city frozen<cityudt>
);
CREATE TABLE movielens.airports (
apid varint PRIMARY KEY,
country frozen<countryudt>,
elevation varint,
iata text,
icao text,
name text,
x varint,
y varint
) 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';
创建类型movielens.cityudt(
cid变量,
名称文本,
时区变量,
tz_id文本
);
创建类型movielens.countryudt(
代码文本,
名称文本,
oa_代码文本,
dst文本,
城市冻结
);
创建表movielens.airports(
apid变量主键,
国家冻结,
高程变量,
国际航空运输协会文本,
国际民航组织文本,
名称文本,
x变量,
y变异体
)使用bloom_过滤器时,fp_概率=0.01
和缓存={'keys':'ALL','rows\u per\u partition':'NONE'}
和注释=“”
和compression={'class':'org.apache.cassandra.db.compression.SizeTieredCompactionStrategy','max_threshold':'32','min_threshold':'4'}
压缩={'chunk_length_in_kb':'64','class':'org.apache.cassandra.io.compress.LZ4Compressor'}
和crc检查机会=1.0
和dclocal\u read\u repair\u chance=0.1
并且默认的\u time\u to\u live=0
gc_grace_秒=864000
最大指数间隔=2048
和memtable_flush_period_in_ms=0
最小索引间隔=128
并读取_repair_chance=0.0
推测性_重试='99百分位';
但是我看不出插入有什么问题!有人能帮我找出哪里出了问题吗?当插入到冻结的udt中时,您不必为所有行(甚至是冻结的udt中的行)指定插入,因此要修复查询,我必须删除所有到
高程
列的行,并添加国家确定,因此,在将您的x
和y
列调整为double
s后,我成功地完成了这项工作:
INSERT INTO airports (apid, name, iata, icao, x, y, elevation, country)
VALUES (12012,'Ararat Airport','ARY','YARA',142.98899841308594,-37.30939865112305,
1008,{ code: 'AS', name: 'Australia', oa_code: 'AU', dst: 'U',
city:{ cid: 1, name: '', timezone: 0, tz_id: ''}});
cassdba@cqlsh:stackoverflow> SELECT * FROM airports WHERE apid=12012;
apid | country | elevation | iata | icao | name | x | y
-------+------------------------------------------------------------------------------------------------------------+-----------+------+------+----------------+---------+----------
12012 | {code: 'AS', name: 'Australia', oa_code: 'AU', dst: 'U', city: {cid: 1, name: '', timezone: 0, tz_id: ''}} | 1008 | ARY | YARA | Ararat Airport | 142.989 | -37.3094
(1 rows)
请记住,变量不带单引号(如时区)
此外,您还指定了每种类型的列,而您只需要在列列表中指定country
(如您所述)。嘿,亚伦,谢谢!但我在插入时没有遇到此错误:D:\apache-cassandra-3.11.1\airports.cql:7181:InvalidRequest:error from server:code=2200[Invalid query]message=“Invalid user type literal for country:field city不是冻结类型”
-这是机场的要点。cql:@madcrazydrumma所以当时区
的值为'
时,我得到了它。当我将其更改为0
时,它可以工作。我将时区的类型更改为文本
,并对其进行排序。然而,现在我得到的错误格式是:D:\apache-cassandra-3.11.1\airports.cql:7179:InvalidRequest:Error from server:code=2200[Invalid query]message=“对于text类型的“y”无效整数常量(3012)
废弃它,我将x和y更改为double
,我仍然得到一个错误。这是因为我正在读取的csv是从MySQL select/concat_ws语句输出的,以从我的关系表中获取值。然而,我不知道如何修复这个声明。也许将它们更改为TEXT
s只是为了避开类型错误?