Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-8675

COPY TO/FROM broken for newline characters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Normal
    • Resolution: Unresolved
    • 3.0.x
    • Legacy/Tools
    • [cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]
      Ubuntu 14.04 64-bit

    • Normal
    • Hide

      .

      Show
      .

    Description

      Exporting/importing does not preserve contents when texts containing newline (and possibly other) characters are involved:

      cqlsh:test> create table if not exists copytest (id int primary key, t text);
      cqlsh:test> insert into copytest (id, t) values (1, 'This has a newline
              ... character');
      cqlsh:test> insert into copytest (id, t) values (2, 'This has a quote " character');
      cqlsh:test> insert into copytest (id, t) values (3, 'This has a fake tab \t character (typed backslash, t)');
      cqlsh:test> select * from copytest;
      
       id | t
      ----+---------------------------------------------------------
        1 |                           This has a newline\ncharacter
        2 |                            This has a quote " character
        3 | This has a fake tab \t character (entered slash-t text)
      
      (3 rows)
      
      cqlsh:test> copy copytest to '/tmp/copytest.csv';
      
      3 rows exported in 0.034 seconds.
      cqlsh:test> copy copytest from '/tmp/copytest.csv';
      
      3 rows imported in 0.005 seconds.
      cqlsh:test> select * from copytest;
      
       id | t
      ----+-------------------------------------------------------
        1 |                          This has a newlinencharacter
        2 |                          This has a quote " character
        3 | This has a fake tab \t character (typed backslash, t)
      
      (3 rows)
      

      I tried replacing \n in the CSV file with
      n, which just expands to \n in the table; and with an actual newline character, which fails with error since it prematurely terminates the record.

      It seems backslashes are only used to take the following character as a literal

      Until this is fixed, what would be the best way to refactor an old table with a new, incompatible structure maintaining its content and name, since we can't rename tables?

      Attachments

        1. copytest.csv
          0.1 kB
          Lex Lythius
        2. CASSANDRA-8675.patch
          1 kB
          Vincenzo Melandri

        Issue Links

          Activity

            People

              Unassigned Unassigned
              lexlythius Lex Lythius
              Philip Thompson Philip Thompson
              Votes:
              4 Vote for this issue
              Watchers:
              19 Start watching this issue

              Dates

                Created:
                Updated: