use of ai.grakn.exception.GraqlQueryException in project grakn by graknlabs.
the class MatchBase method stream.
@Override
public Stream<Answer> stream(Optional<EmbeddedGraknTx<?>> optionalGraph) {
EmbeddedGraknTx<?> tx = optionalGraph.orElseThrow(GraqlQueryException::noTx);
validatePattern(tx);
GraqlTraversal graqlTraversal = GreedyTraversalPlan.createTraversal(pattern, tx);
LOG.trace("Created query plan");
LOG.trace(graqlTraversal.toString());
return streamWithTraversal(this.getPattern().commonVars(), tx, graqlTraversal);
}
use of ai.grakn.exception.GraqlQueryException in project grakn by graknlabs.
the class RemoteGraknTxTest method whenAnErrorOccurs_TheTxCloses.
@Test
public void whenAnErrorOccurs_TheTxCloses() {
Query<?> query = match(var("x")).get();
TxRequest execQueryRequest = GrpcUtil.execQueryRequest(query);
throwOn(execQueryRequest, ErrorType.GRAQL_QUERY_EXCEPTION, "well something went wrong");
try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
try {
tx.graql().match(var("x")).get().execute();
} catch (GraqlQueryException e) {
// Ignore
}
assertTrue(tx.isClosed());
}
}
use of ai.grakn.exception.GraqlQueryException in project grakn by graknlabs.
the class InsertQueryImpl method getSchemaConcepts.
@Override
public Set<SchemaConcept> getSchemaConcepts() {
GraknTx theGraph = getTx().orElseThrow(GraqlQueryException::noTx);
Set<SchemaConcept> types = allVarPatterns().map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).map(theGraph::<Type>getSchemaConcept).collect(Collectors.toSet());
match().ifPresent(mq -> types.addAll(mq.admin().getSchemaConcepts()));
return types;
}
use of ai.grakn.exception.GraqlQueryException in project grakn by graknlabs.
the class RelatesProperty method define.
@Override
public Collection<PropertyExecutor> define(Var var) throws GraqlQueryException {
Var roleVar = role().var();
PropertyExecutor.Method relatesMethod = executor -> {
Role role = executor.get(roleVar).asRole();
executor.get(var).asRelationshipType().relates(role);
};
PropertyExecutor relatesExecutor = PropertyExecutor.builder(relatesMethod).requires(var, roleVar).build();
// This allows users to skip stating `$roleVar sub role` when they say `$var relates $roleVar`
PropertyExecutor.Method isRoleMethod = executor -> executor.builder(roleVar).isRole();
PropertyExecutor isRoleExecutor = PropertyExecutor.builder(isRoleMethod).produces(roleVar).build();
VarPatternAdmin superRoleVarPattern = superRole();
if (superRoleVarPattern != null) {
Var superRoleVar = superRoleVarPattern.var();
PropertyExecutor.Method subMethod = executor -> {
Role superRole = executor.get(superRoleVar).asRole();
executor.builder(roleVar).sub(superRole);
};
PropertyExecutor subExecutor = PropertyExecutor.builder(subMethod).requires(superRoleVar).produces(roleVar).build();
return ImmutableSet.of(relatesExecutor, isRoleExecutor, subExecutor);
} else {
return ImmutableSet.of(relatesExecutor, isRoleExecutor);
}
}
use of ai.grakn.exception.GraqlQueryException in project grakn by graknlabs.
the class MatchInfer method stream.
@Override
public Stream<Answer> stream(Optional<EmbeddedGraknTx<?>> optionalGraph) {
// If the tx is not embedded, treat it like there is no transaction
// TODO: this is dodgy - when queries don't contain transactions this can be fixed
EmbeddedGraknTx<?> tx = optionalOr(optionalGraph, inner.tx().filter(t -> t instanceof EmbeddedGraknTx).map(t -> (EmbeddedGraknTx<?>) t)).orElseThrow(GraqlQueryException::noTx);
if (!RuleUtils.hasRules(tx))
return inner.stream(optionalGraph);
validatePattern(tx);
try {
Iterator<Conjunction<VarPatternAdmin>> conjIt = getPattern().getDisjunctiveNormalForm().getPatterns().iterator();
Conjunction<VarPatternAdmin> conj = conjIt.next();
ReasonerQuery conjQuery = ReasonerQueries.create(conj, tx);
conjQuery.checkValid();
Stream<Answer> answerStream = conjQuery.isRuleResolvable() ? conjQuery.resolve(materialise) : tx.graql().infer(false).match(conj).stream();
while (conjIt.hasNext()) {
conj = conjIt.next();
conjQuery = ReasonerQueries.create(conj, tx);
Stream<Answer> localStream = conjQuery.isRuleResolvable() ? conjQuery.resolve(materialise) : tx.graql().infer(false).match(conj).stream();
answerStream = Stream.concat(answerStream, localStream);
}
return answerStream.map(result -> result.project(getSelectedNames()));
} catch (GraqlQueryException e) {
System.err.println(e.getMessage());
return Stream.empty();
}
}
Aggregations