0

I have 2 Cassandra databases and on each database I have a table with the same schema (t1 and t2). I need to copy some rows from one table to the other. What's the best approach to do so using the Java driver?

                    Select select = QueryBuilder.select().all().from(keyspace, table);
                    select.where(clause);
                    for (Row row : results) {
                            Insert insert = QueryBuilder.insertInto(keyspace, table);
                            for(Column c: columns)
                            {
                                insert.value(c.column_name, row.getObject(c.column_name));
                            }
                            dstSession.execute(insert);
                        }

Should I just do a select and then get all values for each row and then do an insert or is there a more efficient way?

Hossein
  • 1,152
  • 1
  • 16
  • 32
  • You could also use the solution provided [here](https://stackoverflow.com/questions/43274928/copy-data-from-one-table-to-other-in-cassandra-using-java), – Horia Oct 27 '17 at 06:21
  • Why don't you use cqlsh copy command to do so ? – Ashraful Islam Oct 27 '17 at 06:41
  • As I understand it Hossein doesn't want all data from a table, but rather the selected rows in the where clause. I believe that is not possible with using only COPY command. However you could use COPY and then filter the data file yourself with sed or awk. However I don't see any advantage of doing that over what what you suggested yourself. – Simon Fontana Oscarsson Oct 27 '17 at 09:59
  • That's right, I don't want to move all data (that's super expensive bandwidth wise) – Hossein Oct 28 '17 at 00:43

1 Answers1

0

Use stableloader to load those records in that particular sstable

user6238251
  • 66
  • 1
  • 10