Search in sources :

Example 1 with NeqFragment

use of ai.grakn.graql.internal.gremlin.fragment.NeqFragment in project grakn by graknlabs.

the class QueryPlannerTest method shardCountIsUsed.

@Test
public void shardCountIsUsed() {
    // force the concept to get a new shard
    // shards of thing = 2 (thing = 1 and thing itself)
    // thing 2 = 4, thing3 = 7
    tx.shard(tx.getEntityType(thingy2).getId());
    tx.shard(tx.getEntityType(thingy2).getId());
    tx.shard(tx.getEntityType(thingy2).getId());
    tx.shard(tx.getEntityType(thingy3).getId());
    tx.shard(tx.getEntityType(thingy3).getId());
    tx.shard(tx.getEntityType(thingy3).getId());
    tx.shard(tx.getEntityType(thingy3).getId());
    tx.shard(tx.getEntityType(thingy3).getId());
    tx.shard(tx.getEntityType(thingy3).getId());
    Pattern pattern;
    ImmutableList<Fragment> plan;
    pattern = and(x.isa(thingy1), y.isa(thingy2), z.isa(thingy3), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    assertEquals(x, plan.get(3).end());
    assertEquals(3L, plan.stream().filter(fragment -> fragment instanceof NeqFragment).count());
    // TODO: should uncomment the following after updating cost of out-isa fragment
    // varName = plan.get(7).end().getValue();
    // assertEquals(y.getValue(), varName);
    // 
    // varName = plan.get(11).end().getValue();
    // assertEquals(y.getValue(), varName);
    pattern = and(x.isa(thingy), y.isa(thingy2), var().rel(x).rel(y));
    plan = getPlan(pattern);
    assertEquals(x, plan.get(3).end());
    pattern = and(x.isa(thingy), y.isa(thingy2), z.isa(thingy3), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    assertEquals(x, plan.get(4).end());
    pattern = and(x.isa(superType), superType.label(thingy), y.isa(thingy2), subType.sub(superType), z.isa(subType), var().rel(x).rel(y));
    plan = getPlan(pattern);
    assertEquals(z, plan.get(4).end());
    tx.shard(tx.getEntityType(thingy1).getId());
    tx.shard(tx.getEntityType(thingy1).getId());
    tx.shard(tx.getEntityType(thingy).getId());
    // now thing = 5, thing1 = 3
    pattern = and(x.isa(thingy), y.isa(thingy2), z.isa(thingy3), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    assertEquals(y, plan.get(3).end());
    pattern = and(x.isa(thingy1), y.isa(thingy2), z.isa(thingy3), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    assertEquals(x, plan.get(3).end());
    tx.shard(tx.getEntityType(thingy1).getId());
    tx.shard(tx.getEntityType(thingy1).getId());
    // now thing = 7, thing1 = 5
    pattern = and(x.isa(thingy), y.isa(thingy2), z.isa(thingy3), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    assertEquals(y, plan.get(3).end());
    pattern = and(x.isa(thingy1), y.isa(thingy2), z.isa(thingy3), var().rel(x).rel(y).rel(z));
    plan = getPlan(pattern);
    assertEquals(y, plan.get(3).end());
}
Also used : NeqFragment(ai.grakn.graql.internal.gremlin.fragment.NeqFragment) Pattern(ai.grakn.graql.Pattern) OutIsaFragment(ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment) NeqFragment(ai.grakn.graql.internal.gremlin.fragment.NeqFragment) LabelFragment(ai.grakn.graql.internal.gremlin.fragment.LabelFragment) InIsaFragment(ai.grakn.graql.internal.gremlin.fragment.InIsaFragment) Fragment(ai.grakn.graql.internal.gremlin.fragment.Fragment) Test(org.junit.Test)

Aggregations

Pattern (ai.grakn.graql.Pattern)1 Fragment (ai.grakn.graql.internal.gremlin.fragment.Fragment)1 InIsaFragment (ai.grakn.graql.internal.gremlin.fragment.InIsaFragment)1 LabelFragment (ai.grakn.graql.internal.gremlin.fragment.LabelFragment)1 NeqFragment (ai.grakn.graql.internal.gremlin.fragment.NeqFragment)1 OutIsaFragment (ai.grakn.graql.internal.gremlin.fragment.OutIsaFragment)1 Test (org.junit.Test)1