Search in sources :

Example 1 with TypeQLUndefine

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();
            }
        }
    }
}
Also used : TypeQLDelete(com.vaticle.typeql.lang.query.TypeQLDelete) TypeQLInsert(com.vaticle.typeql.lang.query.TypeQLInsert) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) TypeQLUndefine(com.vaticle.typeql.lang.query.TypeQLUndefine) Util.assertNotNulls(com.vaticle.typedb.core.test.integration.util.Util.assertNotNulls) RelationType(com.vaticle.typedb.core.concept.type.RelationType) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) Path(java.nio.file.Path) TypeQLDefine(com.vaticle.typeql.lang.query.TypeQLDefine) TypeQL(com.vaticle.typeql.lang.TypeQL) FunctionalIterator(com.vaticle.typedb.core.common.iterator.FunctionalIterator) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Test(org.junit.Test) IOException(java.io.IOException) RoleType(com.vaticle.typedb.core.concept.type.RoleType) TypeDB(com.vaticle.typedb.core.TypeDB) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) Database(com.vaticle.typedb.core.common.parameters.Options.Database) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) EntityType(com.vaticle.typedb.core.concept.type.EntityType) TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) Entity(com.vaticle.typedb.core.concept.thing.Entity) Assert.assertEquals(org.junit.Assert.assertEquals) Util(com.vaticle.typedb.core.test.integration.util.Util) TypeQLUndefine(com.vaticle.typeql.lang.query.TypeQLUndefine) RoleType(com.vaticle.typedb.core.concept.type.RoleType) TypeDB(com.vaticle.typedb.core.TypeDB) EntityType(com.vaticle.typedb.core.concept.type.EntityType) TypeQLDefine(com.vaticle.typeql.lang.query.TypeQLDefine) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) RelationType(com.vaticle.typedb.core.concept.type.RelationType) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Test(org.junit.Test)

Example 2 with TypeQLUndefine

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);
}
Also used : TypeQLUndefine(com.vaticle.typeql.lang.query.TypeQLUndefine) Given(io.cucumber.java.en.Given)

Example 3 with TypeQLUndefine

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));
}
Also used : Context(com.vaticle.typedb.core.common.parameters.Context) TypeQLUndefine(com.vaticle.typeql.lang.query.TypeQLUndefine)

Aggregations

TypeQLUndefine (com.vaticle.typeql.lang.query.TypeQLUndefine)3 TypeDB (com.vaticle.typedb.core.TypeDB)1 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)1 FunctionalIterator (com.vaticle.typedb.core.common.iterator.FunctionalIterator)1 Arguments (com.vaticle.typedb.core.common.parameters.Arguments)1 Context (com.vaticle.typedb.core.common.parameters.Context)1 Database (com.vaticle.typedb.core.common.parameters.Options.Database)1 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)1 Attribute (com.vaticle.typedb.core.concept.thing.Attribute)1 Entity (com.vaticle.typedb.core.concept.thing.Entity)1 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)1 EntityType (com.vaticle.typedb.core.concept.type.EntityType)1 RelationType (com.vaticle.typedb.core.concept.type.RelationType)1 RoleType (com.vaticle.typedb.core.concept.type.RoleType)1 CoreDatabaseManager (com.vaticle.typedb.core.database.CoreDatabaseManager)1 Util (com.vaticle.typedb.core.test.integration.util.Util)1 Util.assertNotNulls (com.vaticle.typedb.core.test.integration.util.Util.assertNotNulls)1 TypeQL (com.vaticle.typeql.lang.TypeQL)1 TypeQLDefine (com.vaticle.typeql.lang.query.TypeQLDefine)1 TypeQLDelete (com.vaticle.typeql.lang.query.TypeQLDelete)1