Cassandra selective copy

前端 未结 4 1113
轮回少年
轮回少年 2021-01-04 09:10

I want to copy selected rows from a columnfamily to a .csv file. The copy command is available just to dump a column or entire table to a file without where clause. Is there

相关标签:
4条回答
  • 2021-01-04 09:33

    There are no way to make a where clause in copy, but you can use this method :

    echo "select c1,c2.... FROM keySpace.Table where ;" | bin/cqlsh > output.csv

    It allows you to save your result in the output.csv file.

    0 讨论(0)
  • 2021-01-04 09:45

    In addition to Amine CHERIFI's answer:

    | sed -e 's/^\s+//; s_\s*\|\s*_,_g; /^-{3,}|^$|^\(.+\)$/d'

    1. Removes spaces
    2. Replaces | with ,
    3. Removes header separator, empty and summary lines
    0 讨论(0)
  • 2021-01-04 09:54

    No, there is no built-in support for a "where" clause when exporting to a CSV file.

    One alternative would be to write your own script using one of the drivers. In the script you would do the "select", then read the results and write out to a CSV file.

    0 讨论(0)
  • 2021-01-04 09:57

    Other ways to run the SQL with filter and redirect the response to csv

    1) Inside the cqlsh, use the CAPTURE command and redirect the output to a file. You need to set the tracing on before executing the command

    Example: CAPTURE 'output.txt' -- output of the sql executed after this command gets captured into output.txt file

    2) In case if you would like to redirect the SQL output to a file from outside of cqlsh

    ./cqlsh -e'select * from keyspaceName.tableName' > fileName.txt -- hostname
    
    0 讨论(0)
提交回复
热议问题