Search in sources :

Example 46 with TripleRow

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);
}
Also used : TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 47 with TripleRow

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);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Entry(java.util.Map.Entry) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) WholeRowTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver) Value(org.apache.accumulo.core.data.Value) Install(org.apache.rya.api.client.Install) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 48 with TripleRow

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;
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 49 with TripleRow

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;
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 50 with TripleRow

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;
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Mutation(org.apache.accumulo.core.data.Mutation) IOException(java.io.IOException) RdfCloudTripleStoreConstants(org.apache.rya.api.RdfCloudTripleStoreConstants)

Aggregations

TripleRow (org.apache.rya.api.resolver.triple.TripleRow)55 RyaStatement (org.apache.rya.api.domain.RyaStatement)42 RyaURI (org.apache.rya.api.domain.RyaURI)21 Map (java.util.Map)19 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)17 Key (org.apache.accumulo.core.data.Key)14 Value (org.apache.accumulo.core.data.Value)13 ByteRange (org.apache.rya.api.query.strategy.ByteRange)13 TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)13 RyaType (org.apache.rya.api.domain.RyaType)11 RdfCloudTripleStoreConstants (org.apache.rya.api.RdfCloudTripleStoreConstants)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 Text (org.apache.hadoop.io.Text)7 Mutation (org.apache.accumulo.core.data.Mutation)6 Scanner (org.apache.accumulo.core.client.Scanner)5 Authorizations (org.apache.accumulo.core.security.Authorizations)5 IntWritable (org.apache.hadoop.io.IntWritable)5 HashMap (java.util.HashMap)4 BatchWriter (org.apache.accumulo.core.client.BatchWriter)4