jbonofre commented on code in PR #1547:
URL: https://github.com/apache/arrow-java/pull/1547#discussion_r4787408330
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/utils/FlightEndpointDataQueue.java:
##########
@@ -183,7 +183,8 @@ public synchronized void enqueue(final
CloseableEndpointStreamPair endpointReque
() -> {
// `FlightStream#next` will block until new data can be read or
stream is over.
while (endpointRequest.getStream().next()) {
- if (endpointRequest.getStream().getRoot().getRowCount() > 0) {
+ if (endpointRequest.getStream().getLatestMetadata() != null
Review Comment:
This changes when `executeQuery` returns, and as a result
`Statement#setQueryTimeout` no longer covers the wait for the first rows.
The query timeout is only enforced here, through
`completionService.poll(timeout)` in `next(long, TimeUnit)`. Before this
change, the background task kept reading until it got a batch with rows or the
end of the stream, so a server that was slow to produce data hit the timeout.
With `getLatestMetadata() != null`, the task returns at the first metadata-only
message. `executeQuery` then returns immediately, and the first
`ResultSet#next()` blocks in `FlightStream#next()` with no timeout.
Here's the reproducer: the server calls `start(root)`,
`putMetadata(progress)`, sleeps 6s, then `putNext()` with one row. The client
calls `setQueryTimeout(2)`.
- `main`: `SQLTimeoutException: Query timed out after 2 SECONDS` after ~2s
- this PR: `executeQuery` returns after ~13ms, and the first `next()` blocks
~6s and then returns the row. No timeout.
This affects every client of a server that sends progress metadata before
the first batch, including clients that never call `getLatestBatchMetadata()`.
If the goal is to keep the trailer of a query with no rows, could the queue
keep its original condition and only hand back such a stream when it ends?
Something like this:
```java
while (stream.next()) {
if (stream.getRoot().getRowCount() > 0) {
return endpointRequest;
}
}
// End of stream: keep the endpoint if it ended with metadata so the trailer
stays readable.
return stream.getLatestMetadata() != null ? endpointRequest : null;
```
We could add a regression test that combines `setQueryTimeout` with a
producer that sends metadata first.
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFlightStreamResultSet.java:
##########
@@ -160,7 +162,14 @@ private void populateData() throws SQLException {
}
private void populateDataForCurrentFlightStream() throws SQLException {
- final VectorSchemaRoot originalRoot =
currentEndpointData.getStream().getRoot();
+ final FlightStream stream = currentEndpointData.getStream();
+ final ArrowBuf metadata = stream.getLatestMetadata();
+ latestBatchMetadata =
Review Comment:
This field is overwritten on every message, and `next()` keeps looping past
empty roots within a single call. So callers never see a metadata-only message
when more data follows it.
This is a new public API, so I would rather settle its shape before it
ships: changing what it returns later would break callers. Some options are
collecting the metadata per endpoint (for example a list of trailers), or
letting callers register a listener that receives every `app_metadata` the
driver reads.
--
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]