use of org.apache.ignite.internal.sql.engine.RootQuery in project ignite-3 by apache.
the class ExecutionServiceImpl method mapAndExecutePlan.
private SqlCursor<List<?>> mapAndExecutePlan(RootQuery<RowT> qry, MultiStepPlan plan) {
qry.mapping();
plan.init(mappingSrvc, new MappingQueryContext(locNodeId, topologyVersion()));
List<Fragment> fragments = plan.fragments();
// Local execution
Fragment fragment = first(fragments);
if (IgniteUtils.assertionsEnabled()) {
assert fragment != null;
FragmentMapping mapping = plan.mapping(fragment);
assert mapping != null;
List<String> nodes = mapping.nodeIds();
assert nodes != null && nodes.size() == 1 && first(nodes).equals(locNodeId);
}
FragmentDescription fragmentDesc = new FragmentDescription(fragment.fragmentId(), plan.mapping(fragment), plan.target(fragment), plan.remotes(fragment));
ExecutionContext<RowT> ectx = new ExecutionContext<>(qry.context(), taskExecutor, qry.id(), locNodeId, locNodeId, topologyVersion(), fragmentDesc, handler, Commons.parametersMap(qry.parameters()));
Node<RowT> node = new LogicalRelImplementor<>(ectx, affSrvc, mailboxRegistry, exchangeSrvc).go(fragment.root());
qry.run(ectx, plan, node);
// start remote execution
for (int i = 1; i < fragments.size(); i++) {
fragment = fragments.get(i);
fragmentDesc = new FragmentDescription(fragment.fragmentId(), plan.mapping(fragment), plan.target(fragment), plan.remotes(fragment));
Throwable ex = null;
for (String nodeId : fragmentDesc.nodeIds()) {
if (ex != null) {
qry.onResponse(nodeId, fragment.fragmentId(), ex);
} else {
try {
QueryStartRequest req = FACTORY.queryStartRequest().queryId(qry.id()).fragmentId(fragment.fragmentId()).schema(qry.context().schemaName()).root(fragment.serialized()).topologyVersion(ectx.topologyVersion()).fragmentDescription(fragmentDesc).parameters(qry.parameters()).build();
msgSrvc.send(nodeId, req);
} catch (Throwable e) {
qry.onResponse(nodeId, fragment.fragmentId(), ex = e);
}
}
}
}
return Commons.createCursor(new TransformingIterator<>(iteratorsHolder.iterator(qry.iterator()), row -> {
int rowSize = ectx.rowHandler().columnCount(row);
List<Object> res = new ArrayList<>(rowSize);
for (int i = 0; i < rowSize; i++) {
res.add(ectx.rowHandler().get(i, row));
}
return res;
}), plan);
}
use of org.apache.ignite.internal.sql.engine.RootQuery in project ignite-3 by apache.
the class ExecutionServiceImpl method onMessage.
private void onMessage(String nodeId, ErrorMessage msg) {
assert nodeId != null && msg != null;
RunningQuery qry = queryRegistry.query(msg.queryId());
if (qry != null && qry.state() != QueryState.CLOSED) {
assert qry instanceof RootQuery : "Unexpected query object: " + qry;
Exception e = new RemoteException(nodeId, msg.queryId(), msg.fragmentId(), msg.error());
((RootQuery<?>) qry).onError(e);
}
}
Aggregations