I am having a hard time finding information about how to use SequenceWriter to output a custom POJO to a JSON file in an incremental way.
In
my use case, we have a service that receives a SQL query and outputs it
as a CSV file.
Since some queries may produce millions of rows, this
CSV is written incrementally as the result set is read, line by line, to
prevent out of memory issues.
I was asked to add the option of outputting a JSON file instead of a CSV file, but in the same incremental way.
The gotcha is that I need to use a legacy JSON structure, something like:
{
"metadata": {
"query": "SELECT * FROM ZZZ",
"processingTime": 100,
},
"result": {
"columns": [
"Column1",
"Column2",
"..."
],
"result": [
[
"abc",
"def",
"..."
],
[
"foo",
"bar",
"..."
],
...millions of lines...
]
}
}
The part in red is the part I want to incrementally write/update on the JSON file, while keeping the blue parts fixed.
Would
you have a piece of documentation or an example of how I could use
SequenceWriter to incrementally write the JSON file I need, based on a
custom POJO?
Or could you please tell me if I should be looking for
another approach, in case SequenceWriter is not the answer for my use
case?
Many thanks,
Best regards,
Rodrigo