Class StreamingHttpConnection
- All Implemented Interfaces:
ConnectionThrottle
,UserClientConnection
QueryResult
to maintain backward compatibility. That schema
is not ideal for streaming, but it is what it is.
Streaming requires that we use a low-level JSON writer and handle serialization ourselves. While we could build up, then serialize objects, there is little advantage of doing so, and it would simply increase cost -- the very thing that this design tries to decrease.
Does minimal pretty-printing: just inserts newlines in a few places.
Enforces the row limit, discarding all rows after the requested limit. Trusts that the query will enforce the limit at the batch level to avoid wasting resources.
-
Field Summary
Fields inherited from class org.apache.drill.exec.server.rest.BaseWebUserConnection
webSessionResources
Fields inherited from class org.apache.drill.exec.rpc.AbstractDisposableUserClientConnection
error, latch, queryState
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
emitBatch
(RowSetReader batchReader) void
finish()
Called from the REST request, after the query completes, to emit the end of the JSON payload:void
onStart
(UserBitShared.QueryId queryId, int rowLimit) Provide query info once the query starts.void
Set the output stream.void
sendData
(RpcOutcomeListener<GeneralRPCProtos.Ack> listener, QueryDataPackage data) Called from query thread, specifically from the Screen operator, for each batch.void
writeNewline
(JsonOutput gen) Methods inherited from class org.apache.drill.exec.server.rest.BaseWebUserConnection
getClosureFuture, getRemoteAddress, getSession, resources, setAutoRead, webDataType
Methods inherited from class org.apache.drill.exec.rpc.AbstractDisposableUserClientConnection
await, await, getError, getQueryState, sendResult
-
Constructor Details
-
StreamingHttpConnection
-
-
Method Details
-
outputAvailable
Set the output stream. Sent from the REST request thread in theStreamingOutput
callback once the output stream is available. Unblocks the Screen thread.- Throws:
IOException
-
sendData
Called from query thread, specifically from the Screen operator, for each batch.- Parameters:
listener
- The listenerdata
- The data to be sent
-
emitBatch
- Throws:
IOException
-
writeNewline
- Throws:
IOException
-
finish
Called from the REST request, after the query completes, to emit the end of the JSON payload:} ], "queryState" : "COMPLETED" }
Admittedly the tail is pretty lame, but we need it to maintain backward compatibility.
Note that, under the original design, there is no good way to report an error that occurs once the query starts running. Here, we report the query state, which can indicate an error. But, the design of the API does not currently provide the error message itself.
- Throws:
IOException