Export cassandra query result to a csv file

后端 未结 13 1862
刺人心
刺人心 2020-12-08 06:18

I\'m new in cassandra, and I have to export the result of a specific query to a csv file.

I found the COPY command, but (from what I understand) it allo

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 06:52

    With bash:

    If you need to query the data (not possible with COPY TO) and if you need the final product to be importable (ie with COPY FROM):

    cqlsh -e "SELECT * FROM bar WHERE column = 'baz' > raw_output.txt
    

    Then you can reformat the output with sed

    sed 's/\ //g; /^----.*/d; /^(/d; /^\s*$/d;' raw_output.txt | tee clean_output.csv
    

    Which pretty much says

    sed 'remove spaces; remove the column boarder; remove lines beginning with (COUNT X); and remove blank lines' | write output into clean_output.csv
    

    The sed regexp's could be cleaned up to better suite your specific case, but thats the general idea.

提交回复
热议问题