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();
}
}
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());
}
}
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());
}
}
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);
}
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);
}
Aggregations