2016-04-13 73 views
1

我使用COPY命令來獲取數據的副本。 COPY看起來比sstables更簡單。但它看起來像不能導入空字符串。原始表中爲空的列在導入時爲空。重現步驟如下。cassandra copy使重新導入的空字符串爲空

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區別?

回答

2

您正在使用哪種版本的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'或任何你想要的空值的字符...