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());
}
Aggregations