Search in sources :

Example 1 with TripleEntry

use of org.apache.rya.joinselect.mr.utils.TripleEntry in project incubator-rya by apache.

the class CardinalityIdentityReducerTest method testCIReducerOneConstant.

@Test
public void testCIReducerOneConstant() throws InterruptedException, IOException {
    TripleEntry te = new TripleEntry(new Text("urn:gem:etype#1234"), new Text(""), new Text("subject"), new Text(""), new Text("object"));
    CardList cL1 = new CardList(1, 2, 3, 0, 0, 0);
    CardList cL2 = new CardList(4, 5, 6, 0, 0, 0);
    CardList cl = new CardList(5, 7, 9, 0, 0, 0);
    List<CardList> list = new ArrayList<CardList>();
    list.add(cL1);
    list.add(cL2);
    Text row = new Text(te.getFirstPos().toString() + DELIM + te.getFirst().toString());
    Mutation m1 = new Mutation(row);
    m1.put(new Text(te.getKeyPos().toString() + "subject"), new Text(cl.getcardS().toString()), new Value(new byte[0]));
    Mutation m2 = new Mutation(row);
    m2.put(new Text(te.getKeyPos().toString() + "predicate"), new Text(cl.getcardP().toString()), new Value(new byte[0]));
    Mutation m3 = new Mutation(row);
    m3.put(new Text(te.getKeyPos().toString() + "object"), new Text(cl.getcardO().toString()), new Value(new byte[0]));
    Text table = new Text("");
    new ReduceDriver<TripleEntry, CardList, Text, Mutation>().withReducer(new JoinSelectStatisticsSum.CardinalityIdentityReducer()).withInput(te, list).withOutput(table, m1).withOutput(table, m2).withOutput(table, m3).runTest();
}
Also used : CardList(org.apache.rya.joinselect.mr.utils.CardList) ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) ReduceDriver(org.apache.hadoop.mrunit.mapreduce.ReduceDriver) Test(org.junit.Test)

Example 2 with TripleEntry

use of org.apache.rya.joinselect.mr.utils.TripleEntry in project incubator-rya by apache.

the class CardinalityIdentityReducerTest method testJoinTwoVarsReverseOrder.

@Test
public void testJoinTwoVarsReverseOrder() throws InterruptedException, IOException {
    TripleEntry te = new TripleEntry(new Text("urn:gem:etype#1234"), new Text(""), new Text("subject"), new Text(""), new Text("objectpredicate"));
    CardList cL1 = new CardList(0, 0, 0, 1, 2, 3);
    CardList cL2 = new CardList(0, 0, 0, 4, 5, 6);
    CardList cl = new CardList(0, 0, 0, 5, 7, 9);
    List<CardList> list = new ArrayList<CardList>();
    list.add(cL1);
    list.add(cL2);
    Text row = new Text(te.getFirstPos().toString() + DELIM + te.getFirst().toString());
    Mutation m1 = new Mutation(row);
    m1.put(new Text("predicateobject" + "predicatesubject"), new Text(cl.getcardSP().toString()), new Value(new byte[0]));
    Mutation m2 = new Mutation(row);
    m2.put(new Text("predicateobject" + "objectpredicate"), new Text(cl.getcardPO().toString()), new Value(new byte[0]));
    Mutation m3 = new Mutation(row);
    m3.put(new Text("predicateobject" + "subjectobject"), new Text(cl.getcardSO().toString()), new Value(new byte[0]));
    Text table = new Text("");
    new ReduceDriver<TripleEntry, CardList, Text, Mutation>().withReducer(new JoinSelectStatisticsSum.CardinalityIdentityReducer()).withInput(te, list).withOutput(table, m1).withOutput(table, m2).withOutput(table, m3).runTest();
}
Also used : CardList(org.apache.rya.joinselect.mr.utils.CardList) ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) ReduceDriver(org.apache.hadoop.mrunit.mapreduce.ReduceDriver) Test(org.junit.Test)

Example 3 with TripleEntry

use of org.apache.rya.joinselect.mr.utils.TripleEntry in project incubator-rya by apache.

the class CardinalityIdentityReducerTest method testCIReducerTwoConstant.

@Test
public void testCIReducerTwoConstant() throws InterruptedException, IOException {
    TripleEntry te = new TripleEntry(new Text("urn:gem:etype#1234"), new Text("urn:gem#pred"), new Text("subject"), new Text("predicate"), new Text("object"));
    CardList cL1 = new CardList(1, 2, 3, 0, 0, 0);
    CardList cL2 = new CardList(4, 5, 6, 0, 0, 0);
    CardList cl = new CardList(5, 7, 9, 0, 0, 0);
    List<CardList> list = new ArrayList<CardList>();
    list.add(cL1);
    list.add(cL2);
    Text row = new Text(te.getFirstPos().toString() + te.getSecondPos().toString() + DELIM + te.getFirst().toString() + DELIM + te.getSecond());
    Mutation m1 = new Mutation(row);
    m1.put(new Text(te.getKeyPos().toString() + "subject"), new Text(cl.getcardS().toString()), new Value(new byte[0]));
    Mutation m2 = new Mutation(row);
    m2.put(new Text(te.getKeyPos().toString() + "predicate"), new Text(cl.getcardP().toString()), new Value(new byte[0]));
    Mutation m3 = new Mutation(row);
    m3.put(new Text(te.getKeyPos().toString() + "object"), new Text(cl.getcardO().toString()), new Value(new byte[0]));
    Text table = new Text("");
    new ReduceDriver<TripleEntry, CardList, Text, Mutation>().withReducer(new JoinSelectStatisticsSum.CardinalityIdentityReducer()).withInput(te, list).withOutput(table, m1).withOutput(table, m2).withOutput(table, m3).runTest();
}
Also used : CardList(org.apache.rya.joinselect.mr.utils.CardList) ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) ReduceDriver(org.apache.hadoop.mrunit.mapreduce.ReduceDriver) Test(org.junit.Test)

Example 4 with TripleEntry

use of org.apache.rya.joinselect.mr.utils.TripleEntry in project incubator-rya by apache.

the class CardinalityIdentityReducerTest method testJoinTwoVars.

@Test
public void testJoinTwoVars() throws InterruptedException, IOException {
    TripleEntry te = new TripleEntry(new Text("urn:gem:etype#1234"), new Text(""), new Text("subject"), new Text(""), new Text("predicateobject"));
    CardList cL1 = new CardList(0, 0, 0, 1, 2, 3);
    CardList cL2 = new CardList(0, 0, 0, 4, 5, 6);
    CardList cl = new CardList(0, 0, 0, 5, 7, 9);
    List<CardList> list = new ArrayList<CardList>();
    list.add(cL1);
    list.add(cL2);
    Text row = new Text(te.getFirstPos().toString() + DELIM + te.getFirst().toString());
    Mutation m1 = new Mutation(row);
    m1.put(new Text(te.getKeyPos().toString() + "subjectpredicate"), new Text(cl.getcardSP().toString()), new Value(new byte[0]));
    Mutation m2 = new Mutation(row);
    m2.put(new Text(te.getKeyPos().toString() + "predicateobject"), new Text(cl.getcardPO().toString()), new Value(new byte[0]));
    Mutation m3 = new Mutation(row);
    m3.put(new Text(te.getKeyPos().toString() + "objectsubject"), new Text(cl.getcardSO().toString()), new Value(new byte[0]));
    Text table = new Text("");
    new ReduceDriver<TripleEntry, CardList, Text, Mutation>().withReducer(new JoinSelectStatisticsSum.CardinalityIdentityReducer()).withInput(te, list).withOutput(table, m1).withOutput(table, m2).withOutput(table, m3).runTest();
}
Also used : CardList(org.apache.rya.joinselect.mr.utils.CardList) ArrayList(java.util.ArrayList) Value(org.apache.accumulo.core.data.Value) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) ReduceDriver(org.apache.hadoop.mrunit.mapreduce.ReduceDriver) Test(org.junit.Test)

Example 5 with TripleEntry

use of org.apache.rya.joinselect.mr.utils.TripleEntry in project incubator-rya by apache.

the class JoinSelectMapperTest method testOutput.

@Test
public void testOutput() throws TripleRowResolverException, IOException {
    RyaStatement rya = new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"));
    Text s = new Text(rya.getSubject().getData());
    Text p = new Text(rya.getPredicate().getData());
    Text o = new Text(rya.getObject().getData());
    Text sp = new Text(rya.getSubject().getData() + DELIM + rya.getPredicate().getData());
    Text so = new Text(rya.getSubject().getData() + DELIM + rya.getObject().getData());
    Text po = new Text(rya.getPredicate().getData() + DELIM + rya.getObject().getData());
    Text ps = new Text(rya.getPredicate().getData() + DELIM + rya.getSubject().getData());
    Text op = new Text(rya.getObject().getData() + DELIM + rya.getPredicate().getData());
    Text os = new Text(rya.getObject().getData() + DELIM + rya.getSubject().getData());
    TripleEntry t1 = new TripleEntry(s, p, new Text("subject"), new Text("predicate"), new Text("object"));
    TripleEntry t2 = new TripleEntry(p, o, new Text("predicate"), new Text("object"), new Text("subject"));
    TripleEntry t3 = new TripleEntry(o, s, new Text("object"), new Text("subject"), new Text("predicate"));
    TripleEntry t4 = new TripleEntry(o, new Text(""), new Text("object"), new Text(""), new Text("subjectpredicate"));
    TripleEntry t5 = new TripleEntry(p, new Text(""), new Text("predicate"), new Text(""), new Text("objectsubject"));
    TripleEntry t6 = new TripleEntry(s, new Text(""), new Text("subject"), new Text(""), new Text("predicateobject"));
    TripleEntry t7 = new TripleEntry(s, new Text(""), new Text("subject"), new Text(""), new Text("objectpredicate"));
    TripleEntry t8 = new TripleEntry(p, new Text(""), new Text("predicate"), new Text(""), new Text("subjectobject"));
    TripleEntry t9 = new TripleEntry(o, new Text(""), new Text("object"), new Text(""), new Text("predicatesubject"));
    TripleRowResolver trr = new WholeRowTripleResolver();
    Map<TABLE_LAYOUT, TripleRow> map = trr.serialize(rya);
    System.out.println(map);
    TripleRow tr = map.get(TABLE_LAYOUT.SPO);
    System.out.println("Triple row is" + tr);
    System.out.println("ColumnV is " + tr.getTimestamp());
    byte[] b = new byte[0];
    Key key = new Key(tr.getRow(), tr.getColumnFamily(), tr.getColumnQualifier(), b, 1);
    Value val = new Value(b);
    new MapDriver<Key, Value, CompositeType, TripleCard>().withMapper(new JoinSelectSpoTableOutput.JoinSelectMapper()).withInput(key, val).withOutput(new CompositeType(o, new IntWritable(2)), new TripleCard(t1)).withOutput(new CompositeType(s, new IntWritable(2)), new TripleCard(t2)).withOutput(new CompositeType(p, new IntWritable(2)), new TripleCard(t3)).withOutput(new CompositeType(po, new IntWritable(2)), new TripleCard(t6)).withOutput(new CompositeType(so, new IntWritable(2)), new TripleCard(t5)).withOutput(new CompositeType(sp, new IntWritable(2)), new TripleCard(t4)).withOutput(new CompositeType(op, new IntWritable(2)), new TripleCard(t7)).withOutput(new CompositeType(os, new IntWritable(2)), new TripleCard(t8)).withOutput(new CompositeType(ps, new IntWritable(2)), new TripleCard(t9)).runTest();
}
Also used : TripleRowResolver(org.apache.rya.api.resolver.triple.TripleRowResolver) MapDriver(org.apache.hadoop.mrunit.mapreduce.MapDriver) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) TripleCard(org.apache.rya.joinselect.mr.utils.TripleCard) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) WholeRowTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver) Value(org.apache.accumulo.core.data.Value) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) Key(org.apache.accumulo.core.data.Key) IntWritable(org.apache.hadoop.io.IntWritable) CompositeType(org.apache.rya.joinselect.mr.utils.CompositeType) Test(org.junit.Test)

Aggregations

TripleEntry (org.apache.rya.joinselect.mr.utils.TripleEntry)10 Test (org.junit.Test)10 CardList (org.apache.rya.joinselect.mr.utils.CardList)9 ArrayList (java.util.ArrayList)7 Text (org.apache.hadoop.io.Text)7 Value (org.apache.accumulo.core.data.Value)5 ReduceDriver (org.apache.hadoop.mrunit.mapreduce.ReduceDriver)5 Mutation (org.apache.accumulo.core.data.Mutation)4 CompositeType (org.apache.rya.joinselect.mr.utils.CompositeType)4 TripleCard (org.apache.rya.joinselect.mr.utils.TripleCard)4 MapDriver (org.apache.hadoop.mrunit.mapreduce.MapDriver)3 CardinalityType (org.apache.rya.joinselect.mr.utils.CardinalityType)3 JoinSelectAggregate (org.apache.rya.joinselect.mr.JoinSelectAggregate)2 Key (org.apache.accumulo.core.data.Key)1 IntWritable (org.apache.hadoop.io.IntWritable)1 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)1 RyaStatement (org.apache.rya.api.domain.RyaStatement)1 RyaType (org.apache.rya.api.domain.RyaType)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)1