Search in sources :

Example 1 with TypeQLQuery

use of com.vaticle.typeql.lang.query.TypeQLQuery in project grakn by graknlabs.

the class StatisticsTest method updateAges.

private void updateAges(CoreDatabaseManager databaseMgr, Set<Long> ages) {
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
        try (CoreTransaction tx = session.transaction(Arguments.Transaction.Type.WRITE)) {
            TypeQLQuery query = TypeQL.parseQuery("match $x isa person, has age $y;");
            List<ConceptMap> conceptMaps = tx.query().match(query.asMatch()).toList();
            conceptMaps.forEach(cm -> {
                Attribute.Long attribute = cm.get("y").asAttribute().asLong();
                cm.get("x").asEntity().unsetHas(attribute);
                long newAge = attribute.getValue() + 1;
                Attribute.Long newAttribute = attribute.getType().asLong().put(newAge);
                cm.get("x").asEntity().setHas(newAttribute);
                cm.get("x").asEntity().setHas(newAttribute);
                ages.add(newAge);
            });
            tx.commit();
        }
    }
}
Also used : Attribute(com.vaticle.typedb.core.concept.thing.Attribute) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) TypeQLQuery(com.vaticle.typeql.lang.query.TypeQLQuery)

Example 2 with TypeQLQuery

use of com.vaticle.typeql.lang.query.TypeQLQuery in project grakn by graknlabs.

the class StatisticsTest method insertPersonAndAges.

private void insertPersonAndAges(CoreDatabaseManager databaseMgr, int personCount, Set<Long> ages, Random random) {
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
        try (CoreTransaction tx = session.transaction(Arguments.Transaction.Type.WRITE)) {
            for (int i = 0; i < personCount; i++) {
                long age = random.nextInt(personCount);
                ages.add(age);
                TypeQLQuery query = TypeQL.parseQuery("insert $x isa person, has age " + age + ";").asInsert();
                tx.query().insert(query.asInsert());
            }
            tx.commit();
        }
    }
}
Also used : TypeQLQuery(com.vaticle.typeql.lang.query.TypeQLQuery)

Example 3 with TypeQLQuery

use of com.vaticle.typeql.lang.query.TypeQLQuery in project typeql-lang-java by vaticle.

the class ParserTest method testParseListOneInsertWithWhitespacePrefix.

@Test
public void testParseListOneInsertWithWhitespacePrefix() {
    final String insertString = " insert $x isa movie;";
    List<TypeQLQuery> queries = TypeQL.parseQueries(insertString).collect(toList());
    assertEquals(list(insert(var("x").isa("movie"))), queries);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TypeQLQuery(com.vaticle.typeql.lang.query.TypeQLQuery) Test(org.junit.Test)

Example 4 with TypeQLQuery

use of com.vaticle.typeql.lang.query.TypeQLQuery in project typeql-lang-java by vaticle.

the class TypeQLSteps method typeql_match.

@Given("for typeql query")
@Given("reasoning query")
@Given("get answers of typeql match")
@Given("get answers of typeql match group")
@Given("get answer of typeql match aggregate")
@Given("get answers of typeql match group aggregate")
@Given("verify answer set is equivalent for query")
public void typeql_match(String query) {
    TypeQLQuery parsed = TypeQL.parseQuery(query);
    assertEquals(parsed, TypeQL.parseQuery(parsed.toString()));
    if (parsed instanceof TypeQLMatch) {
        parsed.asMatch().conjunction().normalise();
    }
}
Also used : TypeQLMatch(com.vaticle.typeql.lang.query.TypeQLMatch) TypeQLQuery(com.vaticle.typeql.lang.query.TypeQLQuery) Given(io.cucumber.java.en.Given)

Example 5 with TypeQLQuery

use of com.vaticle.typeql.lang.query.TypeQLQuery in project typeql-lang-java by vaticle.

the class ParserTest method testParseListOneMatch.

@Test
public void testParseListOneMatch() {
    final String getString = "match\n$y isa movie;";
    List<TypeQLQuery> queries = TypeQL.parseQueries(getString).collect(toList());
    assertEquals(list(match(var("y").isa("movie"))), queries);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TypeQLQuery(com.vaticle.typeql.lang.query.TypeQLQuery) Test(org.junit.Test)

Aggregations

TypeQLQuery (com.vaticle.typeql.lang.query.TypeQLQuery)11 Test (org.junit.Test)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 TypeQLMatch (com.vaticle.typeql.lang.query.TypeQLMatch)2 TypeDB (com.vaticle.typedb.core.TypeDB)1 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)1 Attribute (com.vaticle.typedb.core.concept.thing.Attribute)1 Conjunction (com.vaticle.typeql.lang.pattern.Conjunction)1 Given (io.cucumber.java.en.Given)1