0

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.

shiva
  • 1
  • 1
  • I dont have an answer for you but I have to tell you that having 13,500 tables, let alone more than a few hundred will eventually cause you pain in the form of JVM heap pressure. Just something to keep in mind. – MarcintheCloud Apr 22 '17 at 03:08

1 Answers1

0

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

Community
  • 1
  • 1
Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53
  • Hi the table names are not sequential they are random but starting with same prefix.For example some tables can have sample_rt4f and sample_123r .I am trying to do from Dev Centre(cassandra ide like sql studio).I cannot do via linux as I dont have permissions to server. – shiva Apr 23 '17 at 03:17