use of io.confluent.ksql.util.PushQueryMetadata in project ksql by confluentinc.
the class StreamedQueryResource method handleQuery.
private EndpointResponse handleQuery(final PreparedStatement<Query> statement, final CompletableFuture<Void> connectionClosedFuture, final QueryMetadataHolder queryMetadataHolder) {
if (queryMetadataHolder.getPullQueryResult().isPresent()) {
final PullQueryResult result = queryMetadataHolder.getPullQueryResult().get();
final PullQueryStreamWriter pullQueryStreamWriter = new PullQueryStreamWriter(result, disconnectCheckInterval.toMillis(), OBJECT_MAPPER, result.getPullQueryQueue(), Clock.systemUTC(), connectionClosedFuture, statement);
return EndpointResponse.ok(pullQueryStreamWriter);
} else if (queryMetadataHolder.getPushQueryMetadata().isPresent()) {
final PushQueryMetadata query = queryMetadataHolder.getPushQueryMetadata().get();
final boolean emptyStream = queryMetadataHolder.getStreamPullQueryMetadata().map(streamPullQueryMetadata -> streamPullQueryMetadata.getEndOffsets().isEmpty()).orElse(false);
final QueryStreamWriter queryStreamWriter = new QueryStreamWriter(query, disconnectCheckInterval.toMillis(), OBJECT_MAPPER, connectionClosedFuture, emptyStream);
return EndpointResponse.ok(queryStreamWriter);
} else {
return Errors.badRequest(String.format("Statement type `%s' not supported for this resource", statement.getClass().getName()));
}
}
use of io.confluent.ksql.util.PushQueryMetadata in project ksql by confluentinc.
the class QueryEndpoint method createQueryPublisher.
public QueryPublisher createQueryPublisher(final String sql, final Map<String, Object> properties, final Map<String, Object> sessionVariables, final Map<String, Object> requestProperties, final Context context, final WorkerExecutor workerExecutor, final ServiceContext serviceContext, final MetricsCallbackHolder metricsCallbackHolder, final Optional<Boolean> isInternalRequest) {
// Must be run on worker as all this stuff is slow
VertxUtils.checkIsWorker();
final ConfiguredStatement<Query> statement = createStatement(sql, properties, sessionVariables);
final QueryMetadataHolder queryMetadataHolder = queryExecutor.handleStatement(serviceContext, properties, requestProperties, statement.getPreparedStatement(), isInternalRequest, metricsCallbackHolder, context, false);
if (queryMetadataHolder.getPullQueryResult().isPresent()) {
final PullQueryResult result = queryMetadataHolder.getPullQueryResult().get();
final BlockingQueryPublisher publisher = new BlockingQueryPublisher(context, workerExecutor);
publisher.setQueryHandle(new KsqlPullQueryHandle(result, pullQueryMetrics, statement.getPreparedStatement().getStatementText()), true, false);
// Start from the worker thread so that errors can bubble up, and we can get a proper response
// code rather than waiting until later after the header has been written and all we can do
// is write an error message.
publisher.startFromWorkerThread();
return publisher;
} else if (queryMetadataHolder.getPushQueryMetadata().isPresent()) {
final PushQueryMetadata metadata = queryMetadataHolder.getPushQueryMetadata().get();
final BlockingQueryPublisher publisher = new BlockingQueryPublisher(context, workerExecutor);
publisher.setQueryHandle(new KsqlQueryHandle(metadata), false, queryMetadataHolder.getScalablePushQueryMetadata().isPresent());
return publisher;
} else {
throw new KsqlStatementException("Unexpected metadata for query", statement.getStatementText());
}
}
Aggregations