use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class RyaTableMutationsFactory method serialize.
// TODO: Does this still need to be collections
public Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serialize(RyaStatement stmt) throws IOException {
Collection<Mutation> spo_muts = new ArrayList<Mutation>();
Collection<Mutation> po_muts = new ArrayList<Mutation>();
Collection<Mutation> osp_muts = new ArrayList<Mutation>();
/**
* TODO: If there are contexts, do we still replicate the information into the default graph as well
* as the named graphs?
*/
try {
Map<TABLE_LAYOUT, TripleRow> rowMap = ryaContext.serializeTriple(stmt);
TripleRow tripleRow = rowMap.get(TABLE_LAYOUT.SPO);
spo_muts.add(createMutation(tripleRow));
tripleRow = rowMap.get(TABLE_LAYOUT.PO);
po_muts.add(createMutation(tripleRow));
tripleRow = rowMap.get(TABLE_LAYOUT.OSP);
osp_muts.add(createMutation(tripleRow));
} catch (TripleRowResolverException fe) {
throw new IOException(fe);
}
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> mutations = new HashMap<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>>();
mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, spo_muts);
mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO, po_muts);
mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP, osp_muts);
return mutations;
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class KeyValueToRyaStatementFunction method apply.
@Override
public RyaStatement apply(Map.Entry<Key, Value> input) {
Key key = input.getKey();
Value value = input.getValue();
RyaStatement statement = null;
try {
statement = context.deserializeTriple(tableLayout, new TripleRow(key.getRowData().toArray(), key.getColumnFamilyData().toArray(), key.getColumnQualifierData().toArray(), key.getTimestamp(), key.getColumnVisibilityData().toArray(), (value != null) ? value.get() : null));
} catch (TripleRowResolverException e) {
throw new RuntimeException(e);
}
return statement;
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class MRReasoningUtils method getStatement.
/**
* Convert an Accumulo row to a RyaStatement.
*/
static RyaStatement getStatement(Key row, Value data, Configuration conf) {
try {
RyaTripleContext ryaContext = RyaTripleContext.getInstance(new AccumuloRdfConfiguration(conf));
RyaStatement ryaStatement = ryaContext.deserializeTriple(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new TripleRow(row.getRow().getBytes(), row.getColumnFamily().getBytes(), row.getColumnQualifier().getBytes(), row.getTimestamp(), row.getColumnVisibility().getBytes(), data.get()));
return ryaStatement;
} catch (TripleRowResolverException e) {
e.printStackTrace();
System.err.println("row: " + row);
return null;
} catch (IllegalArgumentException e) {
e.printStackTrace();
System.err.println("row: " + row);
throw e;
}
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class DuplicateEliminationTest method testTableMapperOutput.
@Test
public void testTableMapperOutput() throws Exception {
RyaStatement rya = TestUtils.ryaStatement("x", "subOrganizationOf", "y");
TripleRowResolver trr = new WholeRowTripleResolver();
Map<TABLE_LAYOUT, TripleRow> map = trr.serialize(rya);
TripleRow tr = map.get(TABLE_LAYOUT.SPO);
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, Fact, Derivation>().withMapper(new DuplicateElimination.DuplicateTableMapper()).withInput(key, val).withOutput(X_SUB_Y, X_SUB_Y.getDerivation()).runTest();
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class ForwardChainTest method testTableMapperOutput.
@Test
public void testTableMapperOutput() throws Exception {
RyaStatement rya = TestUtils.ryaStatement("x", "subOrganizationOf", "y");
TripleRowResolver trr = new WholeRowTripleResolver();
Map<TABLE_LAYOUT, TripleRow> map = trr.serialize(rya);
TripleRow tr = map.get(TABLE_LAYOUT.SPO);
byte[] b = new byte[0];
Key key = new Key(tr.getRow(), tr.getColumnFamily(), tr.getColumnQualifier(), b, 1);
Value val = new Value(b);
ResourceWritable rw1 = new ResourceWritable();
ResourceWritable rw2 = new ResourceWritable();
rw1.set(TestUtils.uri("x"));
rw2.set(TestUtils.uri("y"));
new MapDriver<Key, Value, ResourceWritable, Fact>().withMapper(new ForwardChain.TableMapper(schema)).withInput(key, val).withOutput(rw1, X_SUB_Y).withOutput(rw2, X_SUB_Y).runTest();
}
Aggregations