updating all Cassandra tables starting with a specific name

288 views Asked by At

I am trying to alter my cassandra tables starting with a specific name. My table starts with sample_1,sample_2,sample_13567,sample_adgf and so on... The table names are random but starting with same prefix.

I want to add a new column to all these tables. Can some one suggest me the update query using the regex for table names.

1

There are 1 answers

1
Ashraful Islam On

If you are using linux You can this in two step :

First Generate all alter command into a file like below :

for i in {1..13567}; do echo "ALTER TABLE sample_$i ADD test text;"; done > alter.cql

The above command will create alter command to add test text column for table sample_1 to sample_13567 and store into a file alter.cql

Now you can just load the cql file into cqlsh like below :

cqlsh 127.0.0.1 -u cassandra -p cassandra -k ashraful_test -f alter.cql

Here

-u username
-p password
-k keyspace_name
-f file name to load

By the way having too much table is not a good idea.
Check this link https://stackoverflow.com/a/33389204/2320144