【问题标题】:Unmatched column names/values when inserting data in Cassandra cqlsh在 Cassandra cqlsh 中插入数据时,列名/值不匹配
【发布时间】:2023-03-23 07:15:01
【问题描述】:

所以我正在使用当前查询将数据插入到我的列族中:

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: ''}});

现在,我收到错误消息:Unmatched column names/values,这是我当前的 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';

但是我看不到插入的问题!有人可以帮我弄清楚我哪里出错了吗?

【问题讨论】:

    标签: cassandra nosql cql cql3 cqlsh


    【解决方案1】:

    好的,所以在将您的 xy 列调整为 doubles 后,我确实设法完成了这项工作:

    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)
    

    请记住,VARINT 不带单引号(例如 timezone)。

    此外,当您只需要在列列表中指定 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 is not of type frozen&lt;cityudt&gt;" - 这是 airports.cql 的要点:gist.github.com/ryankshah/636eb1eb5788514be1147c1dfd84bd7a
    • @madcrazydrumma 所以当timezone 被赋予'' 的值时,我得到了这个。当我将其更改为 0 时,它可以工作。
    • 我将timezone 的类型更改为text 并对其进行了排序。但是现在我收到了表单中的错误:D:\apache-cassandra-3.11.1\airports.cql:7179:InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid INTEGER constant (3012) for "y" of type text"
    • 废话,我将 x 和 y 更改为 double,但仍然出现错误。这是因为我正在读入的 csv 是 MySQL select/concat_ws 语句的输出,用于从我的关系表中获取值。但是我不确定如何解决这个问题
    • 嗯。也许将它们更改为 TEXTs 只是为了解决类型错误?
    【解决方案2】:

    插入冻结的 udt 时,您不必为所有行指定插入(即使是冻结的 udt 内的行),因此要修复查询,我必须删除所有直到 elevation 列的行和添加country

    【讨论】:

      猜你喜欢
      • 2017-10-18
      • 2012-09-14
      • 2015-04-27
      • 2013-10-29
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      相关资源
      最近更新 更多