|
88 | 88 | import java.util.concurrent.ExecutorService; |
89 | 89 | import java.util.concurrent.Executors; |
90 | 90 |
|
| 91 | +/** |
| 92 | + * Implementation of Arrow Flight SQL service |
| 93 | + * |
| 94 | + * All methods must catch all possible Exceptions, print and throw CallStatus, |
| 95 | + * otherwise error message will be discarded. |
| 96 | + */ |
91 | 97 | public class DorisFlightSqlProducer implements FlightSqlProducer, AutoCloseable { |
92 | 98 | private static final Logger LOG = LogManager.getLogger(DorisFlightSqlProducer.class); |
93 | 99 | private final Location location; |
@@ -175,9 +181,9 @@ public void closePreparedStatement(final ActionClosePreparedStatementRequest req |
175 | 181 |
|
176 | 182 | private FlightInfo executeQueryStatement(String peerIdentity, ConnectContext connectContext, String query, |
177 | 183 | final FlightDescriptor descriptor) { |
178 | | - Preconditions.checkState(null != connectContext); |
179 | | - Preconditions.checkState(!query.isEmpty()); |
180 | 184 | try { |
| 185 | + Preconditions.checkState(null != connectContext); |
| 186 | + Preconditions.checkState(!query.isEmpty()); |
181 | 187 | // After the previous query was executed, there was no getStreamStatement to take away the result. |
182 | 188 | connectContext.getFlightSqlChannel().reset(); |
183 | 189 | final FlightSqlConnectProcessor flightSQLConnectProcessor = new FlightSqlConnectProcessor(connectContext); |
@@ -294,6 +300,9 @@ private ActionCreatePreparedStatementResult buildCreatePreparedStatementResult(B |
294 | 300 | public void createPreparedStatement(final ActionCreatePreparedStatementRequest request, final CallContext context, |
295 | 301 | final StreamListener<Result> listener) { |
296 | 302 | // TODO can only execute complete SQL, not support SQL parameters. |
| 303 | + // For Python: the Python code will try to create a prepared statement (this is to fit DBAPI, IIRC) and |
| 304 | + // if the server raises any error except for NotImplemented it will fail. (If it gets NotImplemented, |
| 305 | + // it will ignore and execute without a prepared statement.) see: https://github.com/apache/arrow/issues/38786 |
297 | 306 | executorService.submit(() -> { |
298 | 307 | ConnectContext connectContext = flightSessionsManager.getConnectContext(context.peerIdentity()); |
299 | 308 | try { |
@@ -344,20 +353,27 @@ public Runnable acceptPutStatement(CommandStatementUpdate command, CallContext c |
344 | 353 | public Runnable acceptPutPreparedStatementUpdate(CommandPreparedStatementUpdate command, CallContext context, |
345 | 354 | FlightStream flightStream, StreamListener<PutResult> ackStream) { |
346 | 355 | return () -> { |
347 | | - while (flightStream.next()) { |
348 | | - final VectorSchemaRoot root = flightStream.getRoot(); |
349 | | - final int rowCount = root.getRowCount(); |
350 | | - // TODO support update |
351 | | - Preconditions.checkState(rowCount == 0); |
352 | | - |
353 | | - final int recordCount = -1; |
354 | | - final DoPutUpdateResult build = DoPutUpdateResult.newBuilder().setRecordCount(recordCount).build(); |
355 | | - try (final ArrowBuf buffer = rootAllocator.buffer(build.getSerializedSize())) { |
356 | | - buffer.writeBytes(build.toByteArray()); |
357 | | - ackStream.onNext(PutResult.metadata(buffer)); |
| 356 | + try { |
| 357 | + while (flightStream.next()) { |
| 358 | + final VectorSchemaRoot root = flightStream.getRoot(); |
| 359 | + final int rowCount = root.getRowCount(); |
| 360 | + // TODO support update |
| 361 | + Preconditions.checkState(rowCount == 0); |
| 362 | + |
| 363 | + final int recordCount = -1; |
| 364 | + final DoPutUpdateResult build = DoPutUpdateResult.newBuilder().setRecordCount(recordCount).build(); |
| 365 | + try (final ArrowBuf buffer = rootAllocator.buffer(build.getSerializedSize())) { |
| 366 | + buffer.writeBytes(build.toByteArray()); |
| 367 | + ackStream.onNext(PutResult.metadata(buffer)); |
| 368 | + } |
358 | 369 | } |
| 370 | + ackStream.onCompleted(); |
| 371 | + } catch (Exception e) { |
| 372 | + String errMsg = "acceptPutPreparedStatementUpdate failed, " + e.getMessage() + ", " |
| 373 | + + Util.getRootCauseMessage(e); |
| 374 | + LOG.warn(errMsg, e); |
| 375 | + throw CallStatus.INTERNAL.withDescription(errMsg).withCause(e).toRuntimeException(); |
359 | 376 | } |
360 | | - ackStream.onCompleted(); |
361 | 377 | }; |
362 | 378 | } |
363 | 379 |
|
|
0 commit comments