Search in sources :

Example 16 with AccumuloSelectivityEvalDAO

use of org.apache.rya.joinselect.AccumuloSelectivityEvalDAO in project incubator-rya by apache.

the class AccumuloSelectivityEvalDAOTest method testJoinCardinalityQuery2.

@Test
public void testJoinCardinalityQuery2() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MalformedQueryException {
    AccumuloSelectivityEvalDAO accc = new AccumuloSelectivityEvalDAO();
    accc.setConf(arc);
    accc.setConnector(conn);
    accc.setRdfEvalDAO(res);
    accc.init();
    BatchWriter bw1 = conn.createBatchWriter("rya_prospects", config);
    BatchWriter bw2 = conn.createBatchWriter("rya_selectivity", config);
    String s1 = "subjectobject" + DELIM + "http://www.w3.org/2000/01/rdf-schema#label" + DELIM + "uri:dog";
    String s2 = "subjectobject" + DELIM + "uri:barksAt" + DELIM + "uri:cat";
    String s3 = "subjectobject" + DELIM + "uri:peesOn" + DELIM + "uri:hydrant";
    String s4 = "objectsubject" + DELIM + "uri:dog" + DELIM + "http://www.w3.org/2000/01/rdf-schema#label";
    String s5 = "objectsubject" + DELIM + "uri:cat" + DELIM + "uri:barksAt";
    String s6 = "objectsubject" + DELIM + "uri:hydrant" + DELIM + "uri:peesOn";
    List<String> sList = Arrays.asList("subjectobject", "subjectpredicate", "subjectsubject", "predicateobject", "predicatepredicate", "predicatesubject");
    List<Mutation> mList = new ArrayList<Mutation>();
    List<Mutation> mList2 = new ArrayList<Mutation>();
    Mutation m1, m2, m3, m4;
    m1 = new Mutation(s1 + DELIM + "1");
    m1.put(new Text("count"), new Text(""), new Value("2".getBytes()));
    m2 = new Mutation(s2 + DELIM + "2");
    m2.put(new Text("count"), new Text(""), new Value("4".getBytes()));
    m3 = new Mutation(s3 + DELIM + "3");
    m3.put(new Text("count"), new Text(""), new Value("6".getBytes()));
    mList.add(m1);
    mList.add(m2);
    mList.add(m3);
    bw1.addMutations(mList);
    bw1.close();
    m1 = new Mutation(s4);
    m2 = new Mutation(s5);
    m3 = new Mutation(s6);
    int i = 5;
    int j = 6;
    int k = 7;
    Long count1;
    Long count2;
    Long count3;
    for (String s : sList) {
        count1 = (long) i;
        count2 = (long) j;
        count3 = (long) k;
        m1.put(new Text(s), new Text(count1.toString()), EMPTY_VAL);
        m2.put(new Text(s), new Text(count2.toString()), EMPTY_VAL);
        m3.put(new Text(s), new Text(count3.toString()), EMPTY_VAL);
        i = 2 * i;
        j = 2 * j;
        k = 2 * k;
    }
    m4 = new Mutation(new Text("subjectpredicateobject" + DELIM + "FullTableCardinality"));
    m4.put(new Text("FullTableCardinality"), new Text("600"), EMPTY_VAL);
    mList2.add(m1);
    mList2.add(m2);
    mList2.add(m3);
    mList2.add(m4);
    bw2.addMutations(mList2);
    bw2.close();
    List<StatementPattern> spList = getSpList(q2);
    // System.out.println(spList);
    List<Double> jCardList = new ArrayList<Double>();
    for (StatementPattern sp1 : spList) {
        for (StatementPattern sp2 : spList) {
            jCardList.add(accc.getJoinSelect(arc, sp1, sp2));
        }
    }
    System.out.println("Join cardinalities are " + jCardList);
    Assert.assertEquals(0, jCardList.get(0), .001);
    Assert.assertEquals(0, jCardList.get(3), .001);
    Assert.assertEquals(2.0 / 600, jCardList.get(5), .001);
    Assert.assertEquals(4.0 / 600, jCardList.get(6), .001);
    Assert.assertEquals(.0 / 600, jCardList.get(8), .001);
    Assert.assertEquals(6. / 600, jCardList.get(7), .001);
    Assert.assertEquals(6. / 600, jCardList.get(11), .001);
    Assert.assertTrue(jCardList.get(0) == 0);
    Assert.assertTrue(jCardList.get(3) == 0);
    Assert.assertTrue(jCardList.get(5) == (1.0 / 300));
    Assert.assertTrue(jCardList.get(6) == (4.0 / 600));
    Assert.assertTrue(jCardList.get(8) == 0);
    Assert.assertTrue(jCardList.get(7) == .01);
    Assert.assertTrue(jCardList.get(11) == .01);
}
Also used : ArrayList(java.util.ArrayList) AccumuloSelectivityEvalDAO(org.apache.rya.joinselect.AccumuloSelectivityEvalDAO) Text(org.apache.hadoop.io.Text) StatementPattern(org.openrdf.query.algebra.StatementPattern) 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)

Example 17 with AccumuloSelectivityEvalDAO

use of org.apache.rya.joinselect.AccumuloSelectivityEvalDAO in project incubator-rya by apache.

the class AccumuloSelectivityEvalDAOTest method testJoinCardinalityQuery3.

@Test
public void testJoinCardinalityQuery3() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MalformedQueryException {
    AccumuloSelectivityEvalDAO accc = new AccumuloSelectivityEvalDAO();
    accc.setConf(arc);
    accc.setConnector(conn);
    accc.setRdfEvalDAO(res);
    accc.init();
    BatchWriter bw1 = conn.createBatchWriter("rya_prospects", config);
    BatchWriter bw2 = conn.createBatchWriter("rya_selectivity", config);
    String s1 = "subjectpredicate" + DELIM + "http://www.w3.org/2000/01/rdf-schema#label" + DELIM + "uri:dog";
    String s2 = "subjectobject" + DELIM + "uri:barksAt" + DELIM + "uri:cat";
    String s3 = "predicateobject" + DELIM + "uri:peesOn" + DELIM + "uri:hydrant";
    String s4 = "subjectpredicate" + DELIM + "uri:howlsAt" + DELIM + "uri:moon";
    String s5 = "objectsubject" + DELIM + "uri:cat" + DELIM + "uri:barksAt";
    List<String> sList = Arrays.asList("subjectobject", "objectsubject", "objectobject", "objectpredicate", "subjectpredicate", "subjectsubject", "predicateobject", "predicatepredicate", "predicatesubject");
    List<Mutation> mList = new ArrayList<Mutation>();
    List<Mutation> mList2 = new ArrayList<Mutation>();
    Mutation m1, m2, m3, m4, m5, m6;
    m1 = new Mutation(s1 + DELIM + "1");
    m1.put(new Text("count"), new Text(""), new Value("15".getBytes()));
    m2 = new Mutation(s2 + DELIM + "2");
    m2.put(new Text("count"), new Text(""), new Value("11".getBytes()));
    m3 = new Mutation(s3 + DELIM + "3");
    m3.put(new Text("count"), new Text(""), new Value("13".getBytes()));
    m4 = new Mutation(s4 + DELIM + "8");
    m4.put(new Text("count"), new Text(""), new Value("20".getBytes()));
    m5 = new Mutation(s4 + DELIM + "2");
    m5.put(new Text("count"), new Text(""), new Value("10".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(s5);
    m3 = new Mutation(s3);
    m4 = new Mutation(s4);
    int i = 5;
    int j = 6;
    int k = 7;
    int l = 8;
    Long count1;
    Long count2;
    Long count3;
    Long count4;
    for (String s : sList) {
        count1 = (long) i;
        count2 = (long) j;
        count3 = (long) k;
        count4 = (long) l;
        m1.put(new Text(s), new Text(count1.toString()), EMPTY_VAL);
        m2.put(new Text(s), new Text(count2.toString()), EMPTY_VAL);
        m3.put(new Text(s), new Text(count3.toString()), EMPTY_VAL);
        m4.put(new Text(s), new Text(count4.toString()), EMPTY_VAL);
        i = 2 * i;
        j = 2 * j;
        k = 2 * k;
        l = 2 * l;
    }
    m5 = new Mutation(new Text("subjectpredicateobject" + DELIM + "FullTableCardinality"));
    m5.put(new Text("FullTableCardinality"), new Text("600"), EMPTY_VAL);
    mList2.add(m1);
    mList2.add(m2);
    mList2.add(m3);
    mList2.add(m4);
    mList2.add(m5);
    bw2.addMutations(mList2);
    bw2.close();
    List<StatementPattern> spList = getSpList(q3);
    System.out.println(spList);
    List<Double> jCardList = new ArrayList<Double>();
    for (StatementPattern sp1 : spList) {
        for (StatementPattern sp2 : spList) {
            jCardList.add(accc.getJoinSelect(arc, sp1, sp2));
        }
    }
    MathContext mc = new MathContext(3);
    Assert.assertEquals(3.2 / 600, jCardList.get(0), .001);
    Assert.assertEquals(0.5384615384615384 / 600, jCardList.get(3), .001);
    Assert.assertEquals(1.3333333333333333 / 600, jCardList.get(5), .001);
    Assert.assertEquals(2.6666666666666665 / 600, jCardList.get(6), .001);
    Assert.assertEquals(6.4 / 600, jCardList.get(8), .001);
    Assert.assertEquals(13. / 600, jCardList.get(15), .001);
    Assert.assertTrue(new BigDecimal(jCardList.get(2)).round(mc).equals(new BigDecimal(64.0 / 6000).round(mc)));
    Assert.assertTrue(new BigDecimal(jCardList.get(7)).round(mc).equals(new BigDecimal(7.0 / 7800).round(mc)));
    Assert.assertTrue(new BigDecimal(jCardList.get(14)).round(mc).equals(new BigDecimal(112.0 / 7800).round(mc)));
}
Also used : ArrayList(java.util.ArrayList) AccumuloSelectivityEvalDAO(org.apache.rya.joinselect.AccumuloSelectivityEvalDAO) Text(org.apache.hadoop.io.Text) MathContext(java.math.MathContext) BigDecimal(java.math.BigDecimal) StatementPattern(org.openrdf.query.algebra.StatementPattern) 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)

Example 18 with AccumuloSelectivityEvalDAO

use of org.apache.rya.joinselect.AccumuloSelectivityEvalDAO in project incubator-rya by apache.

the class AccumuloSelectivityEvalDAOTest method testCardinalityQuery1.

@Test
public void testCardinalityQuery1() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MalformedQueryException {
    AccumuloSelectivityEvalDAO accc = new AccumuloSelectivityEvalDAO();
    accc.setConf(arc);
    accc.setRdfEvalDAO(res);
    accc.setConnector(conn);
    accc.init();
    BatchWriter bw = conn.createBatchWriter("rya_prospects", config);
    BatchWriter bw1 = conn.createBatchWriter("rya_selectivity", config);
    Mutation m = new Mutation(new Text("subjectpredicateobject" + DELIM + "FullTableCardinality"));
    m.put(new Text("FullTableCardinality"), new Text("600"), EMPTY_VAL);
    List<Mutation> list = Lists.newArrayList();
    list.add(m);
    bw1.addMutations(list);
    bw1.close();
    String s1 = "predicateobject" + DELIM + "http://www.w3.org/2000/01/rdf-schema#label" + DELIM + "uri:dog";
    String s2 = "predicateobject" + DELIM + "uri:barksAt" + DELIM + "uri:cat";
    String s3 = "predicateobject" + DELIM + "uri:peesOn" + DELIM + "uri:hydrant";
    List<Mutation> mList = new ArrayList<Mutation>();
    Mutation m1, m2, m3;
    Integer tempInt;
    Integer tempInt2;
    for (int i = 1; i < 7; i++) {
        tempInt = 5 * i;
        tempInt2 = 10 - i;
        m1 = new Mutation(s1 + DELIM + i);
        m1.put(new Text("count"), new Text(""), new Value((tempInt.toString()).getBytes()));
        m2 = new Mutation(s2 + DELIM + (7 - i));
        m2.put(new Text("count"), new Text(""), new Value((tempInt.toString()).getBytes()));
        m3 = new Mutation(s3 + DELIM + (10 + i));
        m3.put(new Text("count"), new Text(""), new Value((tempInt2.toString()).getBytes()));
        mList.add(m1);
        mList.add(m2);
        mList.add(m3);
    }
    bw.addMutations(mList);
    bw.close();
    List<StatementPattern> spList = getSpList(q1);
    long c1 = accc.getCardinality(arc, spList.get(0));
    long c2 = accc.getCardinality(arc, spList.get(1));
    long c3 = accc.getCardinality(arc, spList.get(2));
    long c4 = accc.getCardinality(arc, spList.get(3));
    Assert.assertTrue(c1 == (long) 0);
    Assert.assertTrue(c2 == (long) 5);
    Assert.assertTrue(c3 == (long) 30);
    Assert.assertTrue(c4 == (long) 9);
}
Also used : ArrayList(java.util.ArrayList) AccumuloSelectivityEvalDAO(org.apache.rya.joinselect.AccumuloSelectivityEvalDAO) Text(org.apache.hadoop.io.Text) StatementPattern(org.openrdf.query.algebra.StatementPattern) 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)

Example 19 with AccumuloSelectivityEvalDAO

use of org.apache.rya.joinselect.AccumuloSelectivityEvalDAO in project incubator-rya by apache.

the class AccumuloSelectivityEvalDAOTest method testInitialize.

@Test
public void testInitialize() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
    AccumuloSelectivityEvalDAO accc = new AccumuloSelectivityEvalDAO();
    accc.setConf(arc);
    accc.setConnector(conn);
    accc.setRdfEvalDAO(res);
    accc.init();
    TableOperations tos = conn.tableOperations();
    Assert.assertTrue(tos.exists("rya_prospects") && tos.exists("rya_selectivity"));
    Assert.assertTrue(accc.isInitialized());
    Assert.assertTrue(accc.getConf().equals(arc));
    Assert.assertTrue(accc.getConnector().equals(conn));
    Assert.assertTrue(accc.getRdfEvalDAO().equals(res));
}
Also used : TableOperations(org.apache.accumulo.core.client.admin.TableOperations) AccumuloSelectivityEvalDAO(org.apache.rya.joinselect.AccumuloSelectivityEvalDAO) Test(org.junit.Test)

Example 20 with AccumuloSelectivityEvalDAO

use of org.apache.rya.joinselect.AccumuloSelectivityEvalDAO in project incubator-rya by apache.

the class EntityOptimizerTest method testOptimizeFilters.

@Test
public void testOptimizeFilters() 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(q8);
    (new FilterOptimizer()).optimize(te, null, null);
    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 8 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 : FilterOptimizer(org.openrdf.query.algebra.evaluation.impl.FilterOptimizer) 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

AccumuloSelectivityEvalDAO (org.apache.rya.joinselect.AccumuloSelectivityEvalDAO)25 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)22 BatchWriter (org.apache.accumulo.core.client.BatchWriter)22 Mutation (org.apache.accumulo.core.data.Mutation)22 Value (org.apache.accumulo.core.data.Value)22 Text (org.apache.hadoop.io.Text)22 TupleExpr (org.openrdf.query.algebra.TupleExpr)17 ProspectorServiceEvalStatsDAO (org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO)10 RdfCloudTripleStoreConfiguration (org.apache.rya.api.RdfCloudTripleStoreConfiguration)9 EntityOptimizer (org.apache.rya.indexing.accumulo.entity.EntityOptimizer)9 Map (java.util.Map)7 Scanner (org.apache.accumulo.core.client.Scanner)7 Key (org.apache.accumulo.core.data.Key)7 Range (org.apache.accumulo.core.data.Range)7 Authorizations (org.apache.accumulo.core.security.Authorizations)7 EntityTupleSet (org.apache.rya.indexing.accumulo.entity.EntityTupleSet)6 QueryJoinSelectOptimizer (org.apache.rya.rdftriplestore.evaluation.QueryJoinSelectOptimizer)6 RdfCloudTripleStoreSelectivityEvaluationStatistics (org.apache.rya.rdftriplestore.evaluation.RdfCloudTripleStoreSelectivityEvaluationStatistics)6 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)6