use of com.vaticle.typeql.lang.query.TypeQLUndefine in project grakn by graknlabs.
the class QueryTest method test_query_undefine.
@Test
public void test_query_undefine() throws IOException {
Util.resetDirectory(dataDir);
try (TypeDB.DatabaseManager typedb = CoreDatabaseManager.open(options)) {
typedb.create(database);
try (TypeDB.Session session = typedb.session(database, Arguments.Session.Type.SCHEMA)) {
try (TypeDB.Transaction transaction = session.transaction(Arguments.Transaction.Type.WRITE)) {
TypeQLDefine query = TypeQL.parseQuery(new String(Files.readAllBytes(Paths.get("test/integration/schema.tql")), UTF_8));
transaction.query().define(query);
transaction.commit();
}
try (TypeDB.Transaction transaction = session.transaction(Arguments.Transaction.Type.WRITE)) {
String queryString = "undefine analysis abstract, owns created, plays commit-analysis:analysis;";
TypeQLUndefine query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
queryString = "undefine rule performance-tracker-rule;";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
queryString = "undefine performance-tracker relates tracker;";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
queryString = "undefine email regex '.+\\@.+\\..+';";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
queryString = "undefine index sub attribute, value long;";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
// undefine first 4 rules
queryString = "undefine rule repo-fork-rule;";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
queryString = "undefine rule repo-dependency-transitive-rule;";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
queryString = "undefine rule repo-dependency-transitive-type-rule;";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
queryString = "undefine rule repo-collaborator-org-rule;";
query = TypeQL.parseQuery(queryString);
transaction.query().undefine(query);
transaction.commit();
}
try (TypeDB.Transaction tx = session.transaction(Arguments.Transaction.Type.READ)) {
EntityType analysis = tx.concepts().getEntityType("analysis");
RelationType performanceTracker = tx.concepts().getRelationType("performance-tracker");
RoleType commitAnalysisAnalysis = tx.concepts().getRelationType("commit-analysis").getRelates("analysis");
AttributeType.DateTime created = tx.concepts().getAttributeType("created").asDateTime();
AttributeType.String email = tx.concepts().getAttributeType("email").asString();
assertNotNulls(analysis, performanceTracker, commitAnalysisAnalysis, created, email);
assertFalse(analysis.isAbstract());
assertTrue(analysis.getOwns().noneMatch(att -> att.equals(created)));
assertTrue(analysis.getPlays().noneMatch(rol -> rol.equals(commitAnalysisAnalysis)));
assertTrue(performanceTracker.getRelates().noneMatch(rol -> rol.getLabel().name().equals("tracker")));
assertNull(email.getRegex());
AttributeType index = tx.concepts().getAttributeType("index");
assertNull(index);
assertNull(tx.logic().getRule("repo-fork-rule"));
assertNull(tx.logic().getRule("repo-dependency-transitive-rule"));
assertNull(tx.logic().getRule("repo-dependency-transitive-type-rule"));
assertNull(tx.logic().getRule("repo-collaborator-org-rule"));
// check total count
assertEquals(15 - 5, tx.logic().rules().toList().size());
// a query that used to trigger a rule should not cause an error
List<ConceptMap> answers = tx.query().match(TypeQL.parseQuery("match $x isa repo-fork;").asMatch()).toList();
}
}
}
}
use of com.vaticle.typeql.lang.query.TypeQLUndefine in project grakn by graknlabs.
the class TypeQLSteps method typeql_undefine.
@Given("typeql undefine")
public void typeql_undefine(String undefineQueryStatements) {
TypeQLUndefine typeQLQuery = TypeQL.parseQuery(String.join("\n", undefineQueryStatements)).asUndefine();
tx().query().undefine(typeQLQuery);
}
use of com.vaticle.typeql.lang.query.TypeQLUndefine in project grakn by graknlabs.
the class QueryService method undefine.
private void undefine(String queryStr, Options.Query options, UUID reqID) {
TypeQLUndefine query = TypeQL.parseQuery(queryStr).asUndefine();
Context.Query context = new Context.Query(transactionSvc.context(), options.query(query), query);
queryMgr.undefine(query, context);
transactionSvc.respond(undefineRes(reqID));
}
Aggregations