Export Cassandra tables as JSON to stdout. Import Cassandra tables as JSON from stdin.
Using stdin/stdout opens the door to the land of pipes and thus enables to slice and dice the stream of JSON data using command line tools. Most useful for the processing of streamed json data will probably be the infamous jq.
as Zip: https://github.com/splink/cpipe/releases/download/v0.0.2/cpipe-0.0.2.zip
unzip cpipe-0.0.2.zip
./bin/cpipe --help as Rpm: https://github.com/splink/cpipe/releases/download/v0.0.2/cpipe-0.0.2-1.noarch.rpm
rpm -i cpipe-0.0.2.noarch.rpm
cpipe --helpas deb: https://github.com/splink/cpipe/releases/download/v0.0.2/cpipe-0.0.2_all.deb
dpkg -i cpipe-0.0.2.noarch.rpm
cpipe --helpBuild from source with SBT:
sbt stagecat assets.json | ./cpipe --mode import --hosts localhost --keyspace space --table assetsUse the export2 mode which leverages optimized range queries to speed up the retrieval of data and reduce the work the coordinator node has to perform. If you don't need to filter and the table is well partitioned, 'export2' should be your first choice for export.
./cpipe --mode export2 --hosts localhost --keyspace space --table assets > assets.jsonSometimes it is not feasible to import a complete table, then it's time to use a filter.
./cpipe --mode export --hosts localhost --keyspace space --table assets --filter "limit 100" > ouputDuring development it is useful to quickly import tables from another Cassandra into the local development environment
./cpipe --mode export2 --hosts localhost --keyspace space --table assets --quiet | ./cpipe --mode import --hosts otherhost --keyspace space --table assetsPiping into jq to transform or filter the data before importing is often useful.
./cpipe --mode export2 --hosts localhost --keyspace space --table assets --quiet | jq 'select(.name == "" | not)' | ./cpipe --mode import --hosts otherhost --keyspace space --table assetsIf you want to process multiple tables, a simple for loop does the trick.
#!/bin/sh
src_host="somehost"
target_host="localhost"
src_keyspace="space"
target_keyspace="space"
tables=(assets products campaigns)
for table in ${tables[@]}; do
echo "import $table"
cpipe --mode export2 --hosts src_host --keyspace $src_keyspace --table $table --quiet | cpipe --mode import --hosts $target_host --keyspace $target_keyspace --table $table
doneOf course there are tons of other useful options, all ready to be used. List them with '--help'
./cpipe --help