2016-04-13 8 views
1

Ich verwende COPY Befehl, um eine Kopie der Daten zu nehmen. COPY sieht einfacher aus als stables. Aber es sieht so aus, als könnte es keine leere Zeichenfolge importieren. Spalten, die in der Originaltabelle leer sind, sind im Import ungültig. Schritte zum Reproduzieren unten.Cassandra-Kopie macht leere Zeichenfolge null auf Reimport

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 

Ich habe versucht, mit WITH Optionen zu spielen, aber das Problem nicht lösen kann. Ist es möglich, Null/Leer-String-Unterscheidung mit COPY zu erhalten?

Antwort

2

Welche Version von Cassandra verwenden Sie? Da Cassandra 3.4, Befehle COPY hat eine Reihe von Optionen leer oder null Strings zu handhaben:

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 

Wie Sie sehen können, wird standardmäßig die Option NULL = ‚‘ bedeutet, dass leere Zeichenfolge als null behandelt wird Wert. Um dieses Verhalten zu ändern, setzen Sie NULL = 'null' oder welches Zeichen auch immer für Nullwert ...

Verwandte Themen