I am trying create a sql query on ignite to fetch records in batches. I found in ignite docs that there is a way to set page size. I would like to know if this parameter is query result payload size or number of records returned at a time.
Also, is page size applicable only when we obtain query cursor? Is it used when we do query.getAll() ?
private static final String EMP_CACHE = "emp_cache";
public static void main(String[] args) {
try (Ignite ignite = Ignition.start(new IgniteConfiguration())) {
IgniteCache<Long, Employee> empCache = ignite.getOrCreateCache(empCacheConfig());
String[] dept = {"Math", "Science", "CS", "ECE", "Physics", "Chemistry", "English", "Hindi"};
long count = 10;
while (count-- > 0) {
String name = RandomStringUtils.randomAlphanumeric(20);
int deptNo = (int) (Math.random() * 7);
empCache.put(count, new Employee(count, name, dept[deptNo]));
}
FieldsQueryCursor<List<?>> cursor =
empCache.query(new SqlFieldsQuery("select * from empCache.EMPLOYEE").setPageSize(2));
for (List<?> objects : cursor) {
System.out.println("Record =" + objects);
// would this mean cursor will fetch two records and go back to ignite to fetch next batch
// OR cursor will fetch records 2KB at a time
}
}
}
public static CacheConfiguration<Long, Employee> empCacheConfig() {
CacheConfiguration<Long, Employee> empCacheConfig = new CacheConfiguration<>(EMP_CACHE);
empCacheConfig.setCacheMode(CacheMode.PARTITIONED);
empCacheConfig.setBackups(1);
empCacheConfig.setIndexedTypes(Long.class, Employee.class);
return empCacheConfig;
}
Thanks.
pageSize
sets the number of rows per batch (not bytes). Rows are transferred in batches from remote nodes.
getAll
is not affected by this property