-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate ExecutingStatement response from QueuedStatement
- Loading branch information
Showing
4 changed files
with
174 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ain/src/main/java/com/facebook/presto/server/protocol/ExecutingQueryResponseProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.server.protocol; | ||
|
||
import com.facebook.presto.dispatcher.DispatchInfo; | ||
import com.facebook.presto.spi.QueryId; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.airlift.units.DataSize; | ||
import io.airlift.units.Duration; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ExecutingQueryResponseProvider | ||
{ | ||
/** | ||
* Generally, the Presto protocol redirects the client from QueuedStatementResource | ||
* to ExecutingStatementResource once the query has been de-queued and begun execution. | ||
* But this redirect might add too much latency for certain very low latency use cases. | ||
* This interface allows for a response from ExecutingStatementResource to be wired into | ||
* QueuedStatementResource, so that the client can receive results directly from the | ||
* QueuedStatement endpoint, without having to be redirected to the ExecutingStatement endpoint. | ||
* | ||
* This interface is required for https://github.com/prestodb/presto/issues/23455 | ||
* | ||
* @param queryId query id | ||
* @param slug nonce to protect the query | ||
* @param dispatchInfo information about state of the query | ||
* @param uriInfo endpoint URI | ||
* @param xPrestoPrefixUrl prefix URL, that is useful if a proxy is being used | ||
* @param scheme HTTP scheme | ||
* @param maxWait duration to wait for query results | ||
* @param targetResultSize target result size of first response | ||
* @param compressionEnabled enable compression | ||
* @param nestedDataSerializationEnabled enable nested data serialization | ||
* @param binaryResults generate results in binary format, rather than JSON | ||
* @return the ExecutingStatement's Response, if available | ||
*/ | ||
Optional<ListenableFuture<Response>> waitForExecutingResponse( | ||
QueryId queryId, | ||
String slug, | ||
DispatchInfo dispatchInfo, | ||
UriInfo uriInfo, | ||
String xPrestoPrefixUrl, | ||
String scheme, | ||
Duration maxWait, | ||
DataSize targetResultSize, | ||
boolean compressionEnabled, | ||
boolean nestedDataSerializationEnabled, | ||
boolean binaryResults); | ||
} |
70 changes: 70 additions & 0 deletions
70
...rc/main/java/com/facebook/presto/server/protocol/LocalExecutingQueryResponseProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.server.protocol; | ||
|
||
import com.facebook.presto.dispatcher.DispatchInfo; | ||
import com.facebook.presto.spi.QueryId; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.airlift.units.DataSize; | ||
import io.airlift.units.Duration; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.google.common.util.concurrent.Futures.transform; | ||
import static com.google.common.util.concurrent.MoreExecutors.directExecutor; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class LocalExecutingQueryResponseProvider | ||
implements ExecutingQueryResponseProvider | ||
{ | ||
private final LocalQueryProvider queryProvider; | ||
|
||
@Inject | ||
public LocalExecutingQueryResponseProvider(LocalQueryProvider queryProvider) | ||
{ | ||
this.queryProvider = requireNonNull(queryProvider, "queryProvider is null"); | ||
} | ||
|
||
@Override | ||
public Optional<ListenableFuture<Response>> waitForExecutingResponse( | ||
QueryId queryId, | ||
String slug, | ||
DispatchInfo dispatchInfo, | ||
UriInfo uriInfo, | ||
String xPrestoPrefixUrl, | ||
String scheme, | ||
Duration maxWait, | ||
DataSize targetResultSize, | ||
boolean compressionEnabled, | ||
boolean nestedDataSerializationEnabled, | ||
boolean binaryResults) | ||
{ | ||
Query query; | ||
try { | ||
query = queryProvider.getQuery(queryId, slug); | ||
} | ||
catch (WebApplicationException e) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(transform( | ||
query.waitForResults(0, uriInfo, scheme, maxWait, targetResultSize, binaryResults), | ||
results -> QueryResourceUtil.toResponse(query, results, xPrestoPrefixUrl, compressionEnabled, nestedDataSerializationEnabled), | ||
directExecutor())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters