我使用COPY
命令获取数据副本。 COPY
看起来比sstables更简单。但看起来它无法导入空字符串。原始表中为空的列在导入时为空。下面重现的步骤。
CREATE TABLE empty_example (id bigint PRIMARY KEY, empty_column text, null_column text);
INSERT INTO empty_example (id, empty_column) VALUES ( 1, '');
SELECT * from empty_example ;
id | empty_column | null_column
----+--------------+-------------
1 | | null
COPY empty_example TO 'empty_example.csv';
TRUNCATE empty_example ;
COPY empty_example FROM 'empty_example.csv';
SELECT * from empty_example ;
id | empty_column | null_column
----+--------------+-------------
1 | null | null
我尝试使用WITH
选项,但无法解决问题。
是否可以使用COPY
保留空/空字符串区别?
答案 0 :(得分:2)
您使用的是哪个版本的Cassandra?从Cassandra 3.4开始,COPY命令有许多选项来处理空字符串或空字符串:
cqlsh:system_schema> help COPY
COPY [cqlsh only]
COPY x FROM: Imports CSV data into a Cassandra table
COPY x TO: Exports data from a Cassandra table in CSV format.
COPY <table_name> [ ( column [, ...] ) ]
FROM ( '<file_pattern_1, file_pattern_2, ... file_pattern_n>' | STDIN )
[ WITH <option>='value' [AND ...] ];
File patterns are either file names or valid python glob expressions, e.g. *.csv or folder/*.csv.
COPY <table_name> [ ( column [, ...] ) ]
TO ( '<filename>' | STDOUT )
[ WITH <option>='value' [AND ...] ];
Available common COPY options and defaults:
DELIMITER=',' - character that appears between records
QUOTE='"' - quoting character to be used to quote fields
ESCAPE='\' - character to appear before the QUOTE char when quoted
HEADER=false - whether to ignore the first line
NULL='' - string that represents a null value
如您所见,默认情况下,选项 NULL =''表示空字符串被视为 null 值。要更改此行为,请将 NULL ='null'或您想要的任何字符设置为空值...