// may be left off, i.e. just "SELECT * FROM Browser_Groups LIMIT 500"
String selectStatement = "SELECT * FROM City WHERE targetable = true LIMIT 500";
int offset = 0;
int resultSetSize = 0;
List<Row> allRows = new ArrayList<Row>();
ResultSet resultSet;
do {
StatementBuilder statementBuilder =
new StatementBuilder(selectStatement + " OFFSET " + offset);
// Get all cities.
resultSet = pqlService.select(statementBuilder.toStatement());
// Collect all cities from each page.
allRows.addAll(Arrays.asList(resultSet.getRows()));
// Display results.
System.out.println(PqlUtils.resultSetToString(resultSet));
offset += 500;
resultSetSize = resultSet.getRows() == null ? 0 : resultSet.getRows().length;
} while (resultSetSize == 500);
System.out.println("Number of results found: " + allRows.size());
// Optionally, save all rows to a CSV.
resultSet.setRows(allRows.toArray(new Row[] {}));
CsvUtils.writeCsv(PqlUtils.resultSetToStringArrayList(resultSet), "cities.csv");
} catch (Exception e) {
e.printStackTrace();
}
}