Search in sources :

Example 6 with EntityTupleSet

use of org.apache.rya.indexing.accumulo.entity.EntityTupleSet in project incubator-rya by apache.

the class EntityOptimizerTest method testOptimizeConstantPriority.

@Test
public void testOptimizeConstantPriority() throws Exception {
    AccumuloSelectivityEvalDAO accc = new AccumuloSelectivityEvalDAO();
    accc.setConf(conf);
    accc.setConnector(accCon);
    accc.setRdfEvalDAO(res);
    accc.init();
    BatchWriter bw1 = accCon.createBatchWriter("rya_prospects", config);
    BatchWriter bw2 = accCon.createBatchWriter("rya_selectivity", config);
    String s1 = "predicateobject" + DELIM + "http://www.w3.org/2000/01/rdf-schema#label" + DELIM + "uri:chickens";
    String s2 = "predicateobject" + DELIM + "uri:barksAt" + DELIM + "uri:chickens";
    String s3 = "predicate" + DELIM + "uri:peesOn";
    String s5 = "predicateobject" + DELIM + "uri:scratches" + DELIM + "uri:ears";
    String s4 = "predicateobject" + DELIM + "uri:eats" + DELIM + "uri:chickens";
    List<Mutation> mList = new ArrayList<Mutation>();
    List<Mutation> mList2 = new ArrayList<Mutation>();
    List<String> sList = Arrays.asList("subjectobject", "subjectpredicate", "subjectsubject", "objectsubject", "objectpredicate", "objectobject");
    Mutation m1, m2, m3, m4, m5, m6;
    m1 = new Mutation(s1 + DELIM + "1");
    m1.put(new Text("count"), new Text(""), new Value("2".getBytes()));
    m2 = new Mutation(s2 + DELIM + "1");
    m2.put(new Text("count"), new Text(""), new Value("2".getBytes()));
    m3 = new Mutation(s3 + DELIM + "1");
    m3.put(new Text("count"), new Text(""), new Value("2".getBytes()));
    m4 = new Mutation(s4 + DELIM + "1");
    m4.put(new Text("count"), new Text(""), new Value("2".getBytes()));
    m5 = new Mutation(s5 + DELIM + "1");
    m5.put(new Text("count"), new Text(""), new Value("2".getBytes()));
    mList.add(m1);
    mList.add(m2);
    mList.add(m3);
    mList.add(m4);
    mList.add(m5);
    bw1.addMutations(mList);
    bw1.close();
    m1 = new Mutation(s1);
    m2 = new Mutation(s2);
    m3 = new Mutation(s3);
    m4 = new Mutation(s4);
    m5 = new Mutation(s5);
    m6 = new Mutation(new Text("subjectpredicateobject" + DELIM + "FullTableCardinality"));
    m6.put(new Text("FullTableCardinality"), new Text("100"), EMPTY_VAL);
    for (String s : sList) {
        m1.put(new Text(s), new Text(Integer.toString(1)), EMPTY_VAL);
        m2.put(new Text(s), new Text(Integer.toString(1)), EMPTY_VAL);
        m3.put(new Text(s), new Text(Integer.toString(1)), EMPTY_VAL);
        m4.put(new Text(s), new Text(Integer.toString(1)), EMPTY_VAL);
        m5.put(new Text(s), new Text(Integer.toString(1)), EMPTY_VAL);
    }
    mList2.add(m1);
    mList2.add(m2);
    mList2.add(m3);
    mList2.add(m4);
    mList2.add(m5);
    mList2.add(m6);
    bw2.addMutations(mList2);
    bw2.close();
    TupleExpr te = getTupleExpr(q7);
    EntityOptimizer cco = new EntityOptimizer(accc);
    System.out.println("Originial query is " + te);
    cco.optimize(te, null, null);
    EntityCentricVisitor ccv = new EntityCentricVisitor();
    te.visit(ccv);
    List<QueryModelNode> nodes = Lists.newArrayList(ccv.getCcNodes());
    System.out.println("Test 7 nodes are :" + nodes);
    Assert.assertEquals(2, nodes.size());
    for (QueryModelNode q : nodes) {
        if (((EntityTupleSet) q).getStarQuery().getNodes().size() == 2) {
            Assert.assertEquals("m", ((EntityTupleSet) q).getStarQuery().getCommonVarName());
        } else if (((EntityTupleSet) q).getStarQuery().getNodes().size() == 3) {
            Assert.assertEquals("uri:chickens", ((EntityTupleSet) q).getStarQuery().getCommonVarName());
        } else {
            Assert.assertTrue(false);
        }
    }
    System.out.println(te);
}
Also used : EntityOptimizer(org.apache.rya.indexing.accumulo.entity.EntityOptimizer) EntityTupleSet(org.apache.rya.indexing.accumulo.entity.EntityTupleSet) ArrayList(java.util.ArrayList) AccumuloSelectivityEvalDAO(org.apache.rya.joinselect.AccumuloSelectivityEvalDAO) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) Text(org.apache.hadoop.io.Text) TupleExpr(org.openrdf.query.algebra.TupleExpr) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)6 BatchWriter (org.apache.accumulo.core.client.BatchWriter)6 Mutation (org.apache.accumulo.core.data.Mutation)6 Value (org.apache.accumulo.core.data.Value)6 Text (org.apache.hadoop.io.Text)6 EntityOptimizer (org.apache.rya.indexing.accumulo.entity.EntityOptimizer)6 EntityTupleSet (org.apache.rya.indexing.accumulo.entity.EntityTupleSet)6 AccumuloSelectivityEvalDAO (org.apache.rya.joinselect.AccumuloSelectivityEvalDAO)6 Test (org.junit.Test)6 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)6 TupleExpr (org.openrdf.query.algebra.TupleExpr)6 FilterOptimizer (org.openrdf.query.algebra.evaluation.impl.FilterOptimizer)2