use of org.apache.rya.api.resolver.triple.TripleRow 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();
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class JoinSelectStatisticsTest method testMap3.
@Test
public void testMap3() throws Exception {
init();
System.out.println("*************************Test3**************************** ");
BatchWriter bw_table1 = c.createBatchWriter("rya_spo", new BatchWriterConfig());
for (int i = 1; i < 3; i++) {
for (int j = 1; j < 3; j++) {
for (int k = 1; k < 3; k++) {
RyaStatement rs = new RyaStatement(new RyaURI(uri + i), new RyaURI(uri + (j)), new RyaType(uri + k));
Map<TABLE_LAYOUT, TripleRow> tripleRowMap = ryaContext.serializeTriple(rs);
TripleRow tripleRow = tripleRowMap.get(TABLE_LAYOUT.SPO);
Mutation m = JoinSelectStatsUtil.createMutation(tripleRow);
bw_table1.addMutation(m);
}
}
}
bw_table1.close();
BatchWriter bw_table2 = c.createBatchWriter("rya_prospects", new BatchWriterConfig());
for (int i = 1; i < 3; i++) {
int k = 1;
for (String s : cardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + k).toString().getBytes()));
bw_table2.addMutation(m);
k++;
}
for (int j = 1; j < 3; j++) {
k = 1;
for (String s : aggCardList) {
Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + uri + j + DELIM + i));
m.put(new Text(), new Text(), new Value(new IntWritable(i + k + j).toString().getBytes()));
bw_table2.addMutation(m);
k++;
}
}
}
bw_table2.close();
Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[] { "" }));
Scanner scan = c.createScanner("rya_selectivity", new Authorizations());
scan.setRange(new Range());
for (Map.Entry<Key, Value> entry : scan) {
System.out.println("Key row string is " + entry.getKey().getRow().toString());
System.out.println("Join type is " + entry.getKey().getColumnFamily().toString());
System.out.println("Value is " + entry.getKey().getColumnQualifier().toString());
}
Scanner scan1 = c.createScanner("rya_selectivity", new Authorizations());
scan1.setRange(Range.prefix("subject" + DELIM + uri + 1));
int i = 0;
for (Map.Entry<Key, Value> entry : scan1) {
Key key = entry.getKey();
String s = key.getColumnFamily().toString();
int val = Integer.parseInt(key.getColumnQualifier().toString());
if (s.equals("predicatepredicate")) {
Assert.assertTrue(val == 14);
}
if (s.equals("objectobject")) {
Assert.assertTrue(val == 18);
}
if (s.equals("predicateobjectpredicateobject")) {
Assert.assertTrue(val == 28);
}
if (s.equals("predicateobjectsubjectpredicate")) {
Assert.assertTrue(val == 20);
}
if (s.equals("predicateobjectobjectsubject")) {
Assert.assertTrue(val == 16);
}
i++;
}
Assert.assertTrue(i == 12);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class StatementPatternStorage method getNext.
@Override
public Tuple getNext() throws IOException {
try {
if (reader.nextKeyValue()) {
Key key = (Key) reader.getCurrentKey();
org.apache.accumulo.core.data.Value value = (org.apache.accumulo.core.data.Value) reader.getCurrentValue();
ByteArrayDataInput input = ByteStreams.newDataInput(key.getRow().getBytes());
RyaStatement ryaStatement = ryaContext.deserializeTriple(layout, new TripleRow(key.getRow().getBytes(), key.getColumnFamily().getBytes(), key.getColumnQualifier().getBytes()));
Tuple tuple = TupleFactory.getInstance().newTuple(7);
tuple.set(0, ryaStatement.getSubject().getData());
tuple.set(1, ryaStatement.getPredicate().getData());
tuple.set(2, ryaStatement.getObject().getData());
tuple.set(3, (ryaStatement.getContext() != null) ? (ryaStatement.getContext().getData()) : (null));
tuple.set(4, ryaStatement.getSubject().getDataType());
tuple.set(5, ryaStatement.getPredicate().getDataType());
tuple.set(6, ryaStatement.getObject().getDataType());
return tuple;
}
} catch (Exception e) {
throw new IOException(e);
}
return null;
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class IncUpdateDAO method deserializeTriple.
/**
* Deserializes a triple stored in the Fluo table.
* @param row - serialized triple
* @return - triple deserialized as a RyaStatement
*/
public static RyaStatement deserializeTriple(final Bytes row) {
checkNotNull(row);
final byte[] rowArray = removeTriplePrefixAndConvertToByteArray(row);
RyaStatement rs = null;
try {
rs = tr.deserialize(TABLE_LAYOUT.SPO, new TripleRow(rowArray, new byte[0], new byte[0]));
} catch (final TripleRowResolverException e) {
e.printStackTrace();
}
return rs;
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class RyaStatementKeyValueIterator method next.
@Override
public RyaStatement next() throws RyaDAOException {
if (!hasNext()) {
return null;
}
try {
Map.Entry<Key, Value> next = dataIterator.next();
Key key = next.getKey();
RyaStatement statement = context.deserializeTriple(tableLayout, new TripleRow(key.getRowData().toArray(), key.getColumnFamilyData().toArray(), key.getColumnQualifierData().toArray(), key.getTimestamp(), key.getColumnVisibilityData().toArray(), next.getValue().get()));
if (next.getValue() != null) {
statement.setValue(next.getValue().get());
}
maxResults--;
return statement;
} catch (TripleRowResolverException e) {
throw new RyaDAOException(e);
}
}
Aggregations