Search in sources :

Example 31 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class SpanBatchBindingSetUpdater method deleteBatch.

private Optional<RowColumn> deleteBatch(TransactionBase tx, Optional<String> nodeId, Span span, Column column, int batchSize) {
    log.trace("Deleting batch of size: " + batchSize + " using Span: " + span + " and Column: " + column);
    RowScanner rs = tx.scanner().over(span).fetch(column).byRow().build();
    try {
        Iterator<ColumnScanner> colScannerIter = rs.iterator();
        int count = 0;
        boolean batchLimitMet = false;
        Bytes row = span.getStart().getRow();
        // get prefix if nodeId is specified
        Optional<Bytes> prefixBytes = Optional.empty();
        if (nodeId.isPresent()) {
            NodeType type = NodeType.fromNodeId(nodeId.get()).get();
            prefixBytes = Optional.ofNullable(Bytes.of(type.getNodeTypePrefix()));
        }
        while (colScannerIter.hasNext() && !batchLimitMet) {
            ColumnScanner colScanner = colScannerIter.next();
            row = colScanner.getRow();
            // extract the nodeId from the returned row if a nodeId was passed
            // into the SpanBatchInformation.  This is to ensure that the returned
            // row nodeId is equal to the nodeId passed in to the span batch information
            Optional<String> rowNodeId = Optional.empty();
            if (prefixBytes.isPresent()) {
                rowNodeId = Optional.of(BindingSetRow.makeFromShardedRow(prefixBytes.get(), row).getNodeId());
            }
            // on the nodeId.  This occurs when the hash is not included in the span
            if (!rowNodeId.isPresent() || rowNodeId.equals(nodeId)) {
                Iterator<ColumnValue> iter = colScanner.iterator();
                while (iter.hasNext()) {
                    if (count >= batchSize) {
                        batchLimitMet = true;
                        break;
                    }
                    ColumnValue colVal = iter.next();
                    tx.delete(row, colVal.getColumn());
                    count++;
                }
            }
        }
        if (batchLimitMet) {
            return Optional.of(new RowColumn(row));
        } else {
            return Optional.empty();
        }
    } catch (Exception e) {
        return Optional.empty();
    }
}
Also used : RowColumn(org.apache.fluo.api.data.RowColumn) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner) Bytes(org.apache.fluo.api.data.Bytes) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnValue(org.apache.fluo.api.data.ColumnValue)

Example 32 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class CreateDeleteIT method deletePCJ.

@Test
public void deletePCJ() throws Exception {
    // A query that finds people who talk to Eve and work at Chipotle.
    final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://Chipotle>." + "}";
    // Triples that are loaded into Rya before the PCJ is created.
    final ValueFactory vf = new ValueFactoryImpl();
    final Set<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve")), vf.createStatement(vf.createURI("http://Bob"), vf.createURI("http://talksTo"), vf.createURI("http://Eve")), vf.createStatement(vf.createURI("http://Charlie"), vf.createURI("http://talksTo"), vf.createURI("http://Eve")), vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://helps"), vf.createURI("http://Kevin")), vf.createStatement(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")), vf.createStatement(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")), vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")), vf.createStatement(vf.createURI("http://David"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadData(sparql, statements);
    try (FluoClient fluoClient = FluoFactory.newClient(getFluoConfiguration())) {
        // Ensure the data was loaded.
        final List<Bytes> rows = getFluoTableEntries(fluoClient);
        assertEquals(19, rows.size());
        // Delete the PCJ from the Fluo application.
        new DeleteFluoPcj(1).deletePcj(fluoClient, pcjId);
        getMiniFluo().waitForObservers();
        // Ensure all data related to the query has been removed.
        final List<Bytes> empty_rows = getFluoTableEntries(fluoClient);
        assertEquals(1, empty_rows.size());
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) FluoClient(org.apache.fluo.api.client.FluoClient) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) DeleteFluoPcj(org.apache.rya.indexing.pcj.fluo.api.DeleteFluoPcj) ValueFactory(org.openrdf.model.ValueFactory) Test(org.junit.Test)

Example 33 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class CreateDeleteIT method deleteAggregation.

@Test
public void deleteAggregation() throws Exception {
    // A query that finds the maximum price for an item within the inventory.
    final String sparql = "SELECT (max(?price) as ?maxPrice) { " + "?item <urn:price> ?price . " + "}";
    // Create the Statements that will be loaded into Rya.
    final ValueFactory vf = new ValueFactoryImpl();
    final Collection<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:price"), vf.createLiteral(2.50)), vf.createStatement(vf.createURI("urn:gum"), vf.createURI("urn:price"), vf.createLiteral(0.99)), vf.createStatement(vf.createURI("urn:sandwich"), vf.createURI("urn:price"), vf.createLiteral(4.99)));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadData(sparql, statements);
    try (FluoClient fluoClient = FluoFactory.newClient(getFluoConfiguration())) {
        // Ensure the data was loaded.
        final List<Bytes> rows = getFluoTableEntries(fluoClient);
        assertEquals(11, rows.size());
        // Delete the PCJ from the Fluo application.
        new DeleteFluoPcj(1).deletePcj(fluoClient, pcjId);
        getMiniFluo().waitForObservers();
        // Ensure all data related to the query has been removed.
        final List<Bytes> empty_rows = getFluoTableEntries(fluoClient);
        assertEquals(1, empty_rows.size());
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) FluoClient(org.apache.fluo.api.client.FluoClient) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) DeleteFluoPcj(org.apache.rya.indexing.pcj.fluo.api.DeleteFluoPcj) ValueFactory(org.openrdf.model.ValueFactory) Test(org.junit.Test)

Example 34 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class BindingHashShardingFunctionTest method bindingSetRowTest.

@Test
public void bindingSetRowTest() {
    String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN);
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("entity", vf.createURI("urn:entity"));
    bs.addBinding("location", vf.createLiteral("location_1"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
    VariableOrder varOrder = new VariableOrder("entity", "location");
    Bytes row = RowKeyUtil.makeRowKey(nodeId, varOrder, vBs);
    Bytes shardedRow = BindingHashShardingFunction.addShard(nodeId, varOrder, vBs);
    BindingSetRow expected = BindingSetRow.make(row);
    BindingSetRow actual = BindingSetRow.makeFromShardedRow(Bytes.of(SP_PREFIX), shardedRow);
    Assert.assertEquals(expected, actual);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) BindingSetRow(org.apache.rya.indexing.pcj.fluo.app.BindingSetRow) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 35 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class VisibilityBindingSetSerDeTest method rountTrip.

@Test
public void rountTrip() throws Exception {
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("name", vf.createLiteral("Alice"));
    bs.addBinding("age", vf.createLiteral(5));
    final VisibilityBindingSet original = new VisibilityBindingSet(bs, "u");
    final VisibilityBindingSetSerDe serde = new VisibilityBindingSetSerDe();
    final Bytes bytes = serde.serialize(original);
    final VisibilityBindingSet result = serde.deserialize(bytes);
    assertEquals(original, result);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Aggregations

Bytes (org.apache.fluo.api.data.Bytes)43 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)16 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)14 Column (org.apache.fluo.api.data.Column)9 Test (org.junit.Test)9 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)8 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)8 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)8 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)6 FluoClient (org.apache.fluo.api.client.FluoClient)5 ColumnValue (org.apache.fluo.api.data.ColumnValue)5 RowColumn (org.apache.fluo.api.data.RowColumn)5 Span (org.apache.fluo.api.data.Span)5 Transaction (org.apache.fluo.api.client.Transaction)4 RyaStatement (org.apache.rya.api.domain.RyaStatement)4 HashSet (java.util.HashSet)3 Snapshot (org.apache.fluo.api.client.Snapshot)3 RyaURI (org.apache.rya.api.domain.RyaURI)3 JoinBatchInformation (org.apache.rya.indexing.pcj.fluo.app.batch.JoinBatchInformation)3 SpanBatchDeleteInformation (org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)3