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 --help
as 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 --help
Build from source with SBT:
sbt stage
cat assets.json | ./cpipe --mode import --hosts localhost --keyspace space --table assets
Use 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.json
Sometimes 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" > ouput
During 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 assets
Piping 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 assets
If 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
done
Of course there are tons of other useful options, all ready to be used. List them with '--help'
./cpipe --help