use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class FileCopyToolMapper method writeRyaStatement.
private void writeRyaStatement(final RyaStatement ryaStatement, final Context context) throws TripleRowResolverException, IOException, InterruptedException {
final Map<TABLE_LAYOUT, TripleRow> serialize = childRyaContext.getTripleResolver().serialize(ryaStatement);
final TripleRow tripleRow = serialize.get(TABLE_LAYOUT.SPO);
final Key key = AccumuloRdfUtils.from(tripleRow);
final Value value = AccumuloRdfUtils.extractValue(tripleRow);
context.write(key, value);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class AccumuloLoadStatementsFileIT method loadTurtleFile.
@Test
public void loadTurtleFile() throws Exception {
// Install an instance of Rya.
final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableEntityCentricIndex(false).setEnableFreeTextIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(false).setEnableGeoIndex(false).setFluoPcjAppName("fluo_app_name").build();
final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), getInstanceName(), getZookeepers());
final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, getConnector());
final Install install = ryaClient.getInstall();
install.install(getRyaInstanceName(), installConfig);
// Load the test statement file.
ryaClient.getLoadStatementsFile().loadStatements(getRyaInstanceName(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE);
// Verify that the statements were loaded.
final ValueFactory vf = new ValueFactoryImpl();
final List<Statement> expected = new ArrayList<>();
expected.add(vf.createStatement(vf.createURI("http://example#alice"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#bob")));
expected.add(vf.createStatement(vf.createURI("http://example#bob"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#charlie")));
expected.add(vf.createStatement(vf.createURI("http://example#charlie"), vf.createURI("http://example#likes"), vf.createURI("http://example#icecream")));
final List<Statement> statements = new ArrayList<>();
final WholeRowTripleResolver tripleResolver = new WholeRowTripleResolver();
final Scanner scanner = getConnector().createScanner(getRyaInstanceName() + "spo", new Authorizations());
final Iterator<Entry<Key, Value>> it = scanner.iterator();
while (it.hasNext()) {
final Entry<Key, Value> next = it.next();
final Key key = next.getKey();
final byte[] row = key.getRow().getBytes();
final byte[] columnFamily = key.getColumnFamily().getBytes();
final byte[] columnQualifier = key.getColumnQualifier().getBytes();
final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier);
final RyaStatement ryaStatement = tripleResolver.deserialize(TABLE_LAYOUT.SPO, tripleRow);
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// Filter out the rya version statement if it is present.
if (!isRyaMetadataStatement(vf, statement)) {
statements.add(statement);
}
}
assertEquals(expected, statements);
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class MergeToolMapper method createRyaStatement.
private static RyaStatement createRyaStatement(final Key key, final Value value, final RyaTripleContext ryaTripleContext) throws TripleRowResolverException {
final byte[] row = key.getRowData() != null && key.getRowData().toArray().length > 0 ? key.getRowData().toArray() : null;
final byte[] columnFamily = key.getColumnFamilyData() != null && key.getColumnFamilyData().toArray().length > 0 ? key.getColumnFamilyData().toArray() : null;
final byte[] columnQualifier = key.getColumnQualifierData() != null && key.getColumnQualifierData().toArray().length > 0 ? key.getColumnQualifierData().toArray() : null;
final Long timestamp = key.getTimestamp();
final byte[] columnVisibility = key.getColumnVisibilityData() != null && key.getColumnVisibilityData().toArray().length > 0 ? key.getColumnVisibilityData().toArray() : null;
final byte[] valueBytes = value != null && value.get().length > 0 ? value.get() : null;
final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier, timestamp, columnVisibility, valueBytes);
final RyaStatement ryaStatement = ryaTripleContext.deserializeTriple(TABLE_LAYOUT.SPO, tripleRow);
return ryaStatement;
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class RyaTableKeyValues method invoke.
@SuppressWarnings({ "unchecked", "rawtypes" })
public RyaTableKeyValues invoke() throws IOException {
/**
* TODO: If there are contexts, do we still replicate the information into the default graph as well
* as the named graphs?
*/
try {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, org.apache.rya.api.resolver.triple.TripleRow> rowMap = instance.serializeTriple(stmt);
TripleRow tripleRow = rowMap.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
byte[] columnVisibility = tripleRow.getColumnVisibility();
Text cv = columnVisibility == null ? EMPTY_CV_TEXT : new Text(columnVisibility);
Long timestamp = tripleRow.getTimestamp();
timestamp = timestamp == null ? 0l : timestamp;
byte[] value = tripleRow.getValue();
Value v = value == null ? EMPTY_VALUE : new Value(value);
spo.add(new SimpleEntry(new Key(new Text(tripleRow.getRow()), new Text(tripleRow.getColumnFamily()), new Text(tripleRow.getColumnQualifier()), cv, timestamp), v));
tripleRow = rowMap.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
po.add(new SimpleEntry(new Key(new Text(tripleRow.getRow()), new Text(tripleRow.getColumnFamily()), new Text(tripleRow.getColumnQualifier()), cv, timestamp), v));
tripleRow = rowMap.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP);
osp.add(new SimpleEntry(new Key(new Text(tripleRow.getRow()), new Text(tripleRow.getColumnFamily()), new Text(tripleRow.getColumnQualifier()), cv, timestamp), v));
} catch (TripleRowResolverException e) {
throw new IOException(e);
}
return this;
}
use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.
the class RyaTableMutationsFactory method serializeDelete.
public Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serializeDelete(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(deleteMutation(tripleRow));
tripleRow = rowMap.get(TABLE_LAYOUT.PO);
po_muts.add(deleteMutation(tripleRow));
tripleRow = rowMap.get(TABLE_LAYOUT.OSP);
osp_muts.add(deleteMutation(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;
}
Aggregations