Search in sources :

Example 1 with CompositeType

use of org.apache.rya.joinselect.mr.utils.CompositeType 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)

Example 2 with CompositeType

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

the class CardinalityMapperTest method testOutput.

@Test
public void testOutput() throws InterruptedException, IOException {
    String s = "urn:gem:etype#1234";
    String p = "urn:gem#pred";
    Text t1 = new Text(TripleValueType.subject.name() + DELIM + s + DELIM + 1);
    Text t2 = new Text(TripleValueType.predicate.name() + DELIM + p + DELIM + 2);
    Text t3 = new Text(TripleValueType.subjectpredicate.name() + DELIM + s + DELIM + p + DELIM + 3);
    byte[] b = new byte[0];
    byte[] c = "25".getBytes();
    byte[] d = "47".getBytes();
    byte[] e = "15".getBytes();
    Key key1 = new Key(t1.getBytes(), b, b, b, 1);
    Key key2 = new Key(t2.getBytes(), b, b, b, 1);
    Key key3 = new Key(t3.getBytes(), b, b, b, 1);
    Value val1 = new Value(c);
    Value val2 = new Value(d);
    Value val3 = new Value(e);
    // System.out.println("Keys are " + key1 + " and " + key2);
    new MapDriver<Key, Value, CompositeType, TripleCard>().withMapper(new JoinSelectProspectOutput.CardinalityMapper()).withInput(key1, val1).withInput(key2, val2).withInput(key3, val3).withOutput(new CompositeType(s, 1), new TripleCard(new CardinalityType(25, "subject", 1))).withOutput(new CompositeType(p, 1), new TripleCard(new CardinalityType(47, "predicate", 2))).withOutput(new CompositeType(s + DELIM + p, 1), new TripleCard(new CardinalityType(15, "subjectpredicate", 3))).runTest();
}
Also used : MapDriver(org.apache.hadoop.mrunit.mapreduce.MapDriver) CardinalityType(org.apache.rya.joinselect.mr.utils.CardinalityType) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) TripleCard(org.apache.rya.joinselect.mr.utils.TripleCard) Key(org.apache.accumulo.core.data.Key) CompositeType(org.apache.rya.joinselect.mr.utils.CompositeType) Test(org.junit.Test)

Example 3 with CompositeType

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

the class JoinReducerTest method testTwoConstCard.

@Test
public void testTwoConstCard() throws InterruptedException, IOException {
    CompositeType ct1 = new CompositeType("urn:gem#pred" + DELIM + "urn:gem:etype#1234", 1);
    TripleEntry te1 = new TripleEntry("uri:testSubject", "", "subject", "", "predicateobject");
    TripleEntry te2 = new TripleEntry("uri:testSubject", "", "subject", "", "objectpredicate");
    CardinalityType c5 = new CardinalityType(45, "subjectobject", 0);
    CardinalityType c1 = new CardinalityType(25, "subjectobject", 2);
    CardinalityType c2 = new CardinalityType(27, "predicateobject", 5);
    CardinalityType c3 = new CardinalityType(29, "predicateobject", 2);
    CardinalityType c4 = new CardinalityType(31, "subjectpredicate", 1);
    CardinalityType c6 = new CardinalityType(56, "subjectpredicate", 2);
    List<TripleCard> list1 = new ArrayList<TripleCard>();
    list1.add(new TripleCard(c1));
    list1.add(new TripleCard(c2));
    list1.add(new TripleCard(c3));
    list1.add(new TripleCard(c4));
    list1.add(new TripleCard(c5));
    list1.add(new TripleCard(c6));
    list1.add(new TripleCard(te1));
    list1.add(new TripleCard(te2));
    // System.out.println("List is " + list);
    new ReduceDriver<CompositeType, TripleCard, TripleEntry, CardList>().withReducer(new JoinSelectAggregate.JoinReducer()).withInput(ct1, list1).withOutput(te1, new CardList(0, 0, 0, 31, 29, 45)).withOutput(te2, new CardList(0, 0, 0, 31, 29, 45)).runTest();
}
Also used : CardinalityType(org.apache.rya.joinselect.mr.utils.CardinalityType) CardList(org.apache.rya.joinselect.mr.utils.CardList) ArrayList(java.util.ArrayList) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) TripleCard(org.apache.rya.joinselect.mr.utils.TripleCard) JoinSelectAggregate(org.apache.rya.joinselect.mr.JoinSelectAggregate) CompositeType(org.apache.rya.joinselect.mr.utils.CompositeType) Test(org.junit.Test)

Example 4 with CompositeType

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

the class JoinReducerTest method testSingleConstCard.

@Test
public void testSingleConstCard() throws InterruptedException, IOException {
    CompositeType ct = new CompositeType("urn:gem:etype#1234", 1);
    TripleEntry te = new TripleEntry("urn:gem#pred", "urn:gem:etype#4567", "predicate", "object", "subject");
    CardinalityType c5 = new CardinalityType(45, "object", 0);
    CardinalityType c1 = new CardinalityType(25, "subject", 2);
    CardinalityType c2 = new CardinalityType(27, "predicate", 2);
    CardinalityType c3 = new CardinalityType(29, "object", 2);
    CardinalityType c4 = new CardinalityType(31, "predicate", 1);
    List<TripleCard> list = new ArrayList<TripleCard>();
    list.add(new TripleCard(c1));
    list.add(new TripleCard(c2));
    list.add(new TripleCard(c3));
    list.add(new TripleCard(c4));
    list.add(new TripleCard(c5));
    list.add(new TripleCard(te));
    System.out.println("List is " + list);
    new ReduceDriver<CompositeType, TripleCard, TripleEntry, CardList>().withReducer(new JoinSelectAggregate.JoinReducer()).withInput(ct, list).withOutput(te, new CardList(25, 31, 45, 0, 0, 0)).runTest();
}
Also used : CardinalityType(org.apache.rya.joinselect.mr.utils.CardinalityType) CardList(org.apache.rya.joinselect.mr.utils.CardList) ArrayList(java.util.ArrayList) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) TripleCard(org.apache.rya.joinselect.mr.utils.TripleCard) ReduceDriver(org.apache.hadoop.mrunit.mapreduce.ReduceDriver) CompositeType(org.apache.rya.joinselect.mr.utils.CompositeType) Test(org.junit.Test)

Example 5 with CompositeType

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

the class JoinReducerTest method testTwoTripleEntry.

@Test
public void testTwoTripleEntry() throws InterruptedException, IOException {
    CompositeType ct = new CompositeType("urn:gem:etype#1234", 1);
    TripleEntry te1 = new TripleEntry("urn:gem#pred", "urn:gem:etype#4567", "predicate", "object", "subject");
    TripleEntry te2 = new TripleEntry("urn:gem#8910", "urn:gem:etype#4567", "subject", "predicate", "object");
    CardinalityType c5 = new CardinalityType(45, "object", 0);
    CardinalityType c1 = new CardinalityType(25, "subject", 2);
    CardinalityType c2 = new CardinalityType(27, "predicate", 2);
    CardinalityType c3 = new CardinalityType(29, "object", 2);
    CardinalityType c4 = new CardinalityType(31, "predicate", 1);
    List<TripleCard> list = new ArrayList<TripleCard>();
    list.add(new TripleCard(c1));
    list.add(new TripleCard(c2));
    list.add(new TripleCard(c3));
    list.add(new TripleCard(c4));
    list.add(new TripleCard(c5));
    list.add(new TripleCard(te1));
    list.add(new TripleCard(te2));
    System.out.println("List is " + list);
    new ReduceDriver<CompositeType, TripleCard, TripleEntry, CardList>().withReducer(new JoinSelectAggregate.JoinReducer()).withInput(ct, list).withOutput(te1, new CardList(25, 31, 45, 0, 0, 0)).withOutput(te2, new CardList(25, 31, 45, 0, 0, 0)).runTest();
}
Also used : CardinalityType(org.apache.rya.joinselect.mr.utils.CardinalityType) CardList(org.apache.rya.joinselect.mr.utils.CardList) ArrayList(java.util.ArrayList) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) TripleCard(org.apache.rya.joinselect.mr.utils.TripleCard) JoinSelectAggregate(org.apache.rya.joinselect.mr.JoinSelectAggregate) CompositeType(org.apache.rya.joinselect.mr.utils.CompositeType) Test(org.junit.Test)

Aggregations

CompositeType (org.apache.rya.joinselect.mr.utils.CompositeType)6 TripleCard (org.apache.rya.joinselect.mr.utils.TripleCard)6 Test (org.junit.Test)6 CardinalityType (org.apache.rya.joinselect.mr.utils.CardinalityType)5 TripleEntry (org.apache.rya.joinselect.mr.utils.TripleEntry)4 ArrayList (java.util.ArrayList)3 Key (org.apache.accumulo.core.data.Key)3 Value (org.apache.accumulo.core.data.Value)3 Text (org.apache.hadoop.io.Text)3 MapDriver (org.apache.hadoop.mrunit.mapreduce.MapDriver)3 CardList (org.apache.rya.joinselect.mr.utils.CardList)3 JoinSelectAggregate (org.apache.rya.joinselect.mr.JoinSelectAggregate)2 IntWritable (org.apache.hadoop.io.IntWritable)1 ReduceDriver (org.apache.hadoop.mrunit.mapreduce.ReduceDriver)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 TripleRowResolver (org.apache.rya.api.resolver.triple.TripleRowResolver)1