Cassandra selective copy

跟風遠走 提交于 2019-11-30 18:17:37

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.

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.

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

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!