public class StreamingHttpConnection extends BaseWebUserConnection
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.
webSessionResources
error, latch, queryState
Constructor and Description |
---|
StreamingHttpConnection(WebSessionResources webSessionResources) |
Modifier and Type | Method and Description |
---|---|
void |
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 |
outputAvailable(OutputStream out)
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) |
getClosureFuture, getRemoteAddress, getSession, resources, setAutoRead, webDataType
await, await, getError, getQueryState, sendResult
public StreamingHttpConnection(WebSessionResources webSessionResources)
public void onStart(UserBitShared.QueryId queryId, int rowLimit)
public void outputAvailable(OutputStream out) throws IOException
StreamingOutput
callback once the output stream is
available. Unblocks the Screen thread.IOException
public void sendData(RpcOutcomeListener<GeneralRPCProtos.Ack> listener, QueryDataPackage data)
listener
- The listenerdata
- The data to be sentpublic void emitBatch(RowSetReader batchReader) throws IOException
IOException
public void writeNewline(JsonOutput gen) throws IOException
IOException
public void finish() throws IOException
} ],
"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.
IOException
Copyright © 1970 The Apache Software Foundation. All rights reserved.