cqlsh script

1.time类型

cqlsh> COPY my_keyspace.typetest from STDIN;
Using 1 child processes

Starting copy of my_keyspace.typetest with columns [col24_varchar, col11_int, col10_inet, col15_smallint, col16_text, col17_time, col18_timestamp, col1_ascii, col20_tinyint, col2_bigint, col3_blob, col4_boolean, col6_date, col7_decimal, col8_double, col9_float].
[Use . on a line by itself to end input]
[copy] 1000,2,10.0.0.1,1,test_new,3661013013013,2015-12-31 18:01:01+0000,aaa,1,10000,0x414141,false,2016-01-01,20.1,200.1,2000.1
[copy] .

Failed to import 1 rows: ParseError - Failed to parse 3661013013013 : can't interpret '3661013013013' as a time, given up without retries
Failed to process 1 rows; failed rows written to import_my_keyspace_typetest.err
Processed: 1 rows; Rate: 0 rows/s; Avg. rate: 0 rows/s
1 rows imported from 1 files in 8.406 seconds (0 skipped).

COPY时,time类型使用数值的话,解析失败

cqlsh> COPY my_keyspace.typetest from STDIN;
Using 1 child processes

Starting copy of my_keyspace.typetest with columns [col24_varchar, col11_int, col10_inet, col15_smallint, col16_text, col17_time, col18_timestamp, col1_ascii, col20_tinyint, col2_bigint, col3_blob, col4_boolean, col6_date, col7_decimal, col8_double, col9_float].
[Use . on a line by itself to end input]
[copy] 1000,2,10.0.0.1,1,test_new,01:01:01.013013013,2015-12-31 18:01:01+0000,aaa,1,10000,0x414141,false,2016-01-01,20.1,200.1,2000.1
[copy] .

Processed: 1 rows; Rate: 0 rows/s; Avg. rate: 0 rows/s
1 rows imported from 1 files in 8.927 seconds (0 skipped).

COPY时,time类型使用格式化形式的话,解析成功,成功插入。

 2. UUID类型

正确格式:

a3e64f8f-bd44-4f28-b8d9-6938726e34d4
7db1a490-5878-11e2-bcfd-0800200c9a66
8a172618-b121-4136-bb10-f665cfc469eb
2b09185b-fb5a-4734-9b56-49077de9edbf

修改后:

3e64f8f-bd44-4f28-b8d9-6938726e34d4
a490-5878-11e2-bcfd-0800200c9a66
172618-b121-4136-bb10-f665cfc469eb
9185b-fb5a-4734-9b56-49077de9edbf

cqlsh> COPY music.imported_playlists from 'playlists-20140603.csv';
Using 1 child processes

Starting copy of music.imported_playlists with columns [id, song_order, album, artist, song_id, title].
Failed to import 1 rows: ParseError - Failed to parse a490-5878-11e2-bcfd-0800200c9a66 : badly formed hexadecimal UUID string, given up without retries
Failed to import 1 rows: ParseError - Failed to parse 3e64f8f-bd44-4f28-b8d9-6938726e34d4 : badly formed hexadecimal UUID string, given up without retries
Failed to import 1 rows: ParseError - Failed to parse 9185b-fb5a-4734-9b56-49077de9edbf : badly formed hexadecimal UUID string, given up without retries
Failed to import 1 rows: ParseError - Failed to parse 172618-b121-4136-bb10-f665cfc469eb : badly formed hexadecimal UUID string, given up without retries
Failed to process 4 rows; failed rows written to import_music_imported_playlists.err
Processed: 4 rows; Rate: 7 rows/s; Avg. rate: 10 rows/s

貌似就得是固定的格式

 3.COPY时的文件

7db1a490-5878-11e2-bcfd-0800200c9a66,,,,['hot dance music'],{'rock'},,"{'2013-09-22 12:01:00.000+0000': 'The Fillmore', '2013-10-01 18:00:00.000+0000': 'The Apple Barrel'}"
a3e64f8f-bd44-4f28-b8d9-6938726e34d4,,,,,"{'1973', 'blues'}",,
8a172618-b121-4136-bb10-f665cfc469eb,,,,,"{'2007', 'covers'}",,

双引号把有“,”的字段括起来。

4. InvalidRequest: Error from server: code=2200 [Invalid query] message="unconfigured table user"

说明表user还没有创建。

5.songs表中没有数据,UPDATE也会插入一条数据。

UPDATE music.songs SET tags = tags + {'2007'} WHERE id = 8a172618-b121-4136-bb10-f665cfc469eb;

6.UUID类型是不要用单引号括起来的。

CREATE TABLE music.playlists (
id uuid,
song_order int,
song_id uuid,
title text,
album text,
artist text,
PRIMARY KEY (id, song_order)
);

select * from playlists where id = 62c36092-82a1-3a00-93d1-46196ee77204;

7.search检索条件中不包含partition key的话,需要用ALLOW FILTERING,不过对性能有影响。

一般search检索条件中必须包含partition key。

select * from playlists where song_order = 1 ALLOW FILTERING;

INSERT

1.Insert时,没有指定的列在Cassandra中是不占空间的。

2.Insert时,如果这行没有就插入,如果有就更新。使用IF NOT EXISTS,保证不存在时才插入。(performance hit?)

3.Insert不支持counter列,Update支持。

4.在内部,Insert和Update是一样的

5.TTL seconds 应用于插入的数据,而不是整个列

6.表也有个TTL,其值必须比列的TTL要大。

7.Insert不支持在Insert中同时使用IF NOT EXISTS和USING TIMESTAMP。

8.集合类型中项目的大小限制为64K。

addresses : UDT

insert into user1(id, addresses) values( '1', {street: 'q', city: 'q', state:'q', zip_code:1});

addresses : map<text, text>
insert into user2(id, addresses) values( '1', {'street': 'q', 'city': 'q', 'state':'q', 'zip_code':'1'});

原文地址:https://www.cnblogs.com/niaomingjian/p/6773471.html