|
27 | 27 | import org.apache.arrow.driver.jdbc.client.CloseableEndpointStreamPair; |
28 | 28 | import org.apache.arrow.driver.jdbc.utils.FlightEndpointDataQueue; |
29 | 29 | import org.apache.arrow.driver.jdbc.utils.VectorSchemaRootTransformer; |
| 30 | +import org.apache.arrow.flight.CallStatus; |
30 | 31 | import org.apache.arrow.flight.FlightInfo; |
| 32 | +import org.apache.arrow.flight.FlightRuntimeException; |
31 | 33 | import org.apache.arrow.flight.FlightStream; |
32 | 34 | import org.apache.arrow.util.AutoCloseables; |
33 | 35 | import org.apache.arrow.vector.VectorSchemaRoot; |
@@ -193,18 +195,28 @@ public boolean next() throws SQLException { |
193 | 195 | return true; |
194 | 196 | } |
195 | 197 |
|
196 | | - if (currentEndpointData != null) { |
197 | | - currentEndpointData.getStream().getRoot().clear(); |
198 | | - if (currentEndpointData.getStream().next()) { |
199 | | - populateDataForCurrentFlightStream(); |
200 | | - continue; |
| 198 | + try { |
| 199 | + if (currentEndpointData != null) { |
| 200 | + currentEndpointData.getStream().getRoot().clear(); |
| 201 | + if (currentEndpointData.getStream().next()) { |
| 202 | + populateDataForCurrentFlightStream(); |
| 203 | + continue; |
| 204 | + } |
| 205 | + |
| 206 | + flightEndpointDataQueue.enqueue(currentEndpointData); |
201 | 207 | } |
202 | 208 |
|
203 | | - flightEndpointDataQueue.enqueue(currentEndpointData); |
| 209 | + currentEndpointData = getNextEndpointStream(false); |
| 210 | + } catch (final FlightRuntimeException e) { |
| 211 | + // A concurrent statement.cancel() (or close) cancels in-flight FlightStreams, |
| 212 | + // which surface here as CANCELLED. Normalize to Avatica's "Statement canceled". |
| 213 | + if (flightEndpointDataQueue.isClosed() |
| 214 | + && e.status().code() == CallStatus.CANCELLED.code()) { |
| 215 | + throw AvaticaConnection.HELPER.createException("Statement canceled"); |
| 216 | + } |
| 217 | + throw e; |
204 | 218 | } |
205 | 219 |
|
206 | | - currentEndpointData = getNextEndpointStream(false); |
207 | | - |
208 | 220 | if (currentEndpointData != null) { |
209 | 221 | populateDataForCurrentFlightStream(); |
210 | 222 | continue; |
|
0 commit comments