turb opened a new issue, #29762:
URL: https://github.com/apache/beam/issues/29762
### What happened?
We are using Apache Beam in Scala with scio, running on Google Dataflow.
Those specifics do not seem to influence what follows.
When using `Neo4JIO`, if the data set is big, jobs fail with OOM, even when
lowering `fetchSize` (whose default value is 1000). Our usage seems pretty
standard.
After investigation, the relevant code in Apache Beam'
`org.apache.beam.sdk.io.neo4j.Neo4jIO` is:
```java
TransactionWork<List<OutputT>> transactionWork =
transaction -> {
Result result = transaction.run(cypher, parametersMap);
return result.list(
record -> {
try {
return rowMapper.mapRow(record);
} catch (Exception e) {
throw new RuntimeException("error mapping Neo4j record
to row", e);
}
});
};
```
Debug showed that this returns a list with the whole dataset, not at all
`fetchSize`.
The thing is, as documented in the driver, calling `result.list` returns the
full result of the cypher query:
```java
/**
* Retrieve and store a projection of the entire result.
* This can be used if you want to iterate over the stream multiple
times or to store the
* whole result for later use.
*
* Note that this method can only be used if you know that the query that
* yielded this result returns a finite stream. Some queries can yield
* infinite results, in which case calling this method will lead to
running
* out of memory.
*
* Calling this method exhausts the result.
*
* @param mapFunction a function to map from Record to T. See {@link
Records} for some predefined functions.
* @param <T> the type of result list elements
* @return list of all mapped remaining immutable records
*/
<T> List<T> list(Function<Record, T> mapFunction);
```
And indeed in the driver, it leads to:
```java
private synchronized CompletionStage<ResultSummary> pullAllAsync() {
if (isDone()) {
return completedWithValueIfNoFailure(summary);
} else {
request(UNLIMITED_FETCH_SIZE);
if (summaryFuture == null) {
summaryFuture = new CompletableFuture<>();
}
return summaryFuture;
}
```
So the `fetchSize` config value is completely ignored, and the worker MUST
have the size of the complete result set returned when executing the cypher
query, which is, for very large ones, nearly impossible.
One solution may be to call `result.next` to get the next element, however,
per the driver documentation, the recommended way `QueryRunner`.
If my analysis is confirmed, I may take the time to work on this change.
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [ ] Component: Python SDK
- [X] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [X] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Samza Runner
- [ ] Component: Twister2 Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]