How to read all 1000 lines from cassandra CF with astyanax

We have one CF that has only about 1000 lines. Is there a way with astyanax to read all 1000 lines? Does this support help?

thanks dean

+4
source share
1 answer

You can read all lines with a lean call to get_range_slices. Note that it returns rows in marker order, not in key order. So it’s great to read all the lines, but not do the ranges between the line keys.

You can use it in Astyanax with getAllRows (). Here is a sample code (copied from documents at https://github.com/Netflix/astyanax/wiki/Reading-Data#iterate-all-rows-in-a-column-family )

Rows<String, String>> rows; try { rows = keyspace.prepareQuery("ColumnFamilyName") .getAllRows() .setBlockSize(10) .withColumnRange(new RangeBuilder().setMaxSize(10).build()) .setExceptionCallback(new ExceptionCallback() { @Override public boolean onException(ConnectionException e) { try { Thread.sleep(1000); } catch (InterruptedException e1) { } return true; }}) .execute().getResult(); } catch (ConnectionException e) { } // This will never throw an exception for (Row<String, String> row : rows.getResult()) { LOG.info("ROW: " + row.getKey() + " " + row.getColumns().size()); } 

This will return the first 10 columns of each row in batches of 10 rows. Increase the number passed to RangeBuilder (). SetMaxSize to get more (or fewer) columns.

+3
source

Source: https://habr.com/ru/post/1491505/


All Articles