use of org.apache.ignite.internal.sql.engine.prepare.QueryPlan in project ignite-3 by apache.
the class ExecutionServiceImpl method onMessage.
@SuppressWarnings("unchecked")
private void onMessage(String nodeId, QueryStartRequest msg) {
assert nodeId != null && msg != null;
try {
Query<RowT> qry = (Query<RowT>) queryRegistry.register(new Query<>(msg.queryId(), nodeId, null, exchangeSrvc, (q) -> queryRegistry.unregister(q.id()), LOG));
QueryPlan qryPlan = qryPlanCache.queryPlan(new CacheKey(msg.schema(), msg.root()), () -> prepareFragment(msg.root()));
FragmentPlan plan = (FragmentPlan) qryPlan;
final BaseQueryContext qctx = createQueryContext(Contexts.empty(), msg.schema());
ExecutionContext<RowT> ectx = new ExecutionContext<>(qctx, taskExecutor, msg.queryId(), locNodeId, nodeId, msg.topologyVersion(), msg.fragmentDescription(), handler, Commons.parametersMap(msg.parameters()));
executeFragment(qry, plan, ectx);
} catch (Throwable ex) {
LOG.error("Failed to start query fragment", ex);
mailboxRegistry.outboxes(msg.queryId(), msg.fragmentId(), -1).forEach(Outbox::close);
mailboxRegistry.inboxes(msg.queryId(), msg.fragmentId(), -1).forEach(Inbox::close);
try {
msgSrvc.send(nodeId, FACTORY.queryStartResponse().queryId(msg.queryId()).fragmentId(msg.fragmentId()).error(ex).build());
} catch (Exception e) {
LOG.error("Error occurred during send error message", e);
IgniteInternalException wrpEx = new IgniteInternalException("Error occurred during send error message", e);
e.addSuppressed(ex);
RunningQuery qry = queryRegistry.query(msg.queryId());
qry.cancel();
throw wrpEx;
}
throw ex;
}
}
use of org.apache.ignite.internal.sql.engine.prepare.QueryPlan in project ignite-3 by apache.
the class SqlQueryProcessor method query0.
private List<SqlCursor<List<?>>> query0(QueryContext context, String schemaName, String sql, Object... params) {
SchemaPlus schema = schemaManager.schema(schemaName);
assert schema != null : "Schema not found: " + schemaName;
QueryPlan plan = planCache.queryPlan(new CacheKey(schema.getName(), sql));
if (plan != null) {
final QueryPlan finalPlan = plan;
context.maybeUnwrap(QueryValidator.class).ifPresent(queryValidator -> queryValidator.validatePlan(finalPlan));
RootQuery<Object[]> qry = new RootQuery<>(sql, schema, params, exchangeService, (q) -> queryRegistry.unregister(q.id()), LOG);
queryRegistry.register(qry);
try {
return Collections.singletonList(executionSrvc.executePlan(qry, plan));
} catch (Exception e) {
boolean isCanceled = qry.isCancelled();
qry.cancel();
queryRegistry.unregister(qry.id());
if (isCanceled) {
throw new IgniteInternalException("The query was cancelled while planning", e);
} else {
throw e;
}
}
}
SqlNodeList qryList = Commons.parse(sql, FRAMEWORK_CONFIG.getParserConfig());
List<SqlCursor<List<?>>> cursors = new ArrayList<>(qryList.size());
List<RootQuery<Object[]>> qrys = new ArrayList<>(qryList.size());
for (final SqlNode sqlNode : qryList) {
RootQuery<Object[]> qry = new RootQuery<>(sqlNode.toString(), // Update schema for each query in multiple statements.
schemaManager.schema(schemaName), params, exchangeService, (q) -> queryRegistry.unregister(q.id()), LOG);
qrys.add(qry);
queryRegistry.register(qry);
try {
if (qryList.size() == 1) {
plan = planCache.queryPlan(new CacheKey(schemaName, qry.sql()), () -> prepareSvc.prepareSingle(sqlNode, qry.planningContext()));
} else {
plan = prepareSvc.prepareSingle(sqlNode, qry.planningContext());
}
final QueryPlan finalPlan = plan;
context.maybeUnwrap(QueryValidator.class).ifPresent(queryValidator -> queryValidator.validatePlan(finalPlan));
cursors.add(executionSrvc.executePlan(qry, plan));
} catch (Exception e) {
boolean isCanceled = qry.isCancelled();
qrys.forEach(RootQuery::cancel);
queryRegistry.unregister(qry.id());
if (isCanceled) {
throw new IgniteInternalException("The query was cancelled while planning", e);
} else {
throw e;
}
}
}
return cursors;
}
Aggregations