REQUIREMENT:
A SELECT query may result to 200K records. We need to fetch the records, process it and write it in the database with processed results.
Database Used: NuoDB
PROBLEM:
I have read in NuoDB documentation:
Results of queries to the transaction engine will be buffered back to the client in rows that fit into less than 100 KB. Once the client iterates through a set of fetched results, it will go back to the TE to get more results.
I am not sure whether the engine of the database can return 200K records at once. And I also feel that holding 200K records in a List variable is not ideal. The SELECT query has date field in the where clause like:
SELECT * FROM Table WHERE DATE >= '2020-06-04 00:00:00' AND DATE < '2020-06-04 23:00:00'
The above query may result in 200K records.
I thought of dividing the query like:
SELECT * FROM Table WHERE DATE >= '2020-06-04 00:00:00' AND DATE < '2020-06-04 10:00:00'
SELECT * FROM Table WHERE DATE >= '2020-06-04 10:00:01' AND DATE < '2020-06-04 18:00:00'
SELECT * FROM Table WHERE DATE >= '2020-06-04 18:00:01' AND DATE < '2020-06-04 23:00:00'
But I am not sure whether this approach is ideal. Please advice.
So Please consider 3 classes A, B, C that extends ItemReader, ItemProcessor and ItemWriter respectively.
.get("stepToReadDataFromTable")
.<Entity1, Entity2>chunk(2000)
.reader(A())
.processor(B())
.writer(C())
.build();
Can we do like this: Class A will extract 2000 records out of 200K records and process it and after processing 2000 records (as mentioned in the chunk) write it into the database. This loop will go on untill all the 200K records are processed.
If yes, how can we achieve this. Is there any way to extract data from the select query in chunks?