use of com.hazelcast.jet.impl.AbstractJetInstance in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(SelectPlan plan, QueryId queryId, List<Object> arguments, long timeout) {
List<Object> args = prepareArguments(plan.getParameterMetadata(), arguments);
JobConfig jobConfig = new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, args).setArgument(KEY_SQL_QUERY_TEXT, plan.getQuery()).setArgument(KEY_SQL_UNBOUNDED, plan.isStreaming()).setTimeoutMillis(timeout);
QueryResultProducerImpl queryResultProducer = new QueryResultProducerImpl(!plan.isStreaming());
AbstractJetInstance<?> jet = (AbstractJetInstance<?>) hazelcastInstance.getJet();
long jobId = jet.newJobId();
Object oldValue = resultRegistry.store(jobId, queryResultProducer);
assert oldValue == null : oldValue;
try {
Job job = jet.newLightJob(jobId, plan.getDag(), jobConfig);
job.getFuture().whenComplete((r, t) -> {
// make sure the queryResultProducer is cleaned up after the job completes. This normally
// takes effect when the job fails before the QRP is removed by the RootResultConsumerSink
resultRegistry.remove(jobId);
if (t != null) {
int errorCode = findQueryExceptionCode(t);
String errorMessage = findQueryExceptionMessage(t);
queryResultProducer.onError(QueryException.error(errorCode, "The Jet SQL job failed: " + errorMessage, t));
}
});
} catch (Throwable e) {
resultRegistry.remove(jobId);
throw e;
}
return new SqlResultImpl(queryId, queryResultProducer, plan.getRowMetadata(), plan.isStreaming());
}
Aggregations