use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataCacheTest method testCache.
@Test
public void testCache() {
FluoQueryMetadataDAO mockDAO = Mockito.mock(FluoQueryMetadataDAO.class);
Transaction mockTx = Mockito.mock(Transaction.class);
String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN);
StatementPatternMetadata metadata = StatementPatternMetadata.builder(nodeId).setParentNodeId("parent").setStatementPattern("pattern").setVarOrder(new VariableOrder("xyz")).build();
when(mockDAO.readStatementPatternMetadata(mockTx, nodeId)).thenReturn(metadata);
FluoQueryMetadataCache cache = new FluoQueryMetadataCache(mockDAO, 20, 2);
assertEquals(metadata, cache.readStatementPatternMetadata(mockTx, nodeId));
cache.readStatementPatternMetadata(mockTx, nodeId);
cache.readStatementPatternMetadata(mockTx, nodeId);
cache.readStatementPatternMetadata(mockTx, nodeId);
cache.readStatementPatternMetadata(mockTx, nodeId);
Mockito.verify(mockDAO, Mockito.times(1)).readStatementPatternMetadata(mockTx, nodeId);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FilterResultUpdater method updateFilterResults.
/**
* Updates the results of a Filter node when one of its child has added a
* new Binding Set to its results.
*
* @param tx - The transaction all Fluo queries will use. (not null)
* @param childBindingSet - A binding set that the query's child node has emitted. (not null)
* @param filterMetadata - The metadata of the Filter whose results will be updated. (not null)
* @throws Exception Something caused the update to fail.
*/
public void updateFilterResults(final TransactionBase tx, final VisibilityBindingSet childBindingSet, final FilterMetadata filterMetadata) throws Exception {
checkNotNull(tx);
checkNotNull(childBindingSet);
checkNotNull(filterMetadata);
log.trace("Transaction ID: {}\nFilter Node ID: {}\nBinding Set:\n{}\n", tx.getStartTimestamp(), filterMetadata.getNodeId(), childBindingSet);
// Parse the original query and find the Filter that represents filterId.
final String sparql = filterMetadata.getFilterSparql();
final Filter filter = FilterSerializer.deserialize(sparql);
// Evaluate whether the child BindingSet satisfies the filter's condition.
final ValueExpr condition = filter.getCondition();
if (isTrue(condition, childBindingSet)) {
// Create the Row Key for the emitted binding set. It does not contain visibilities.
final VariableOrder filterVarOrder = filterMetadata.getVariableOrder();
final Bytes resultRow = makeRowKey(filterMetadata.getNodeId(), filterVarOrder, childBindingSet);
// Serialize and emit BindingSet
final Bytes nodeValueBytes = BS_SERDE.serialize(childBindingSet);
log.trace("Transaction ID: {}\nNew Binding Set: {}\n", tx.getStartTimestamp(), childBindingSet);
tx.set(resultRow, FluoQueryColumns.FILTER_BINDING_SET, nodeValueBytes);
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class JoinResultUpdater method getSpan.
/**
* Creates a Span for the sibling node to retrieve BindingSets to join with
* @param tx
* @param childId - Id of the node that was updated
* @param childBindingSet - BindingSet update
* @param siblingId - Id of the sibling node whose BindingSets will be retrieved and joined with the update
* @return Span to retrieve sibling node's BindingSets to form join results
*/
private Span getSpan(TransactionBase tx, final String childId, final VisibilityBindingSet childBindingSet, final String siblingId) {
// Get the common variable orders. These are used to build the prefix.
final VariableOrder childVarOrder = getVarOrder(tx, childId);
final VariableOrder siblingVarOrder = getVarOrder(tx, siblingId);
final List<String> commonVars = getCommonVars(childVarOrder, siblingVarOrder);
Bytes siblingScanPrefix = null;
if (!commonVars.isEmpty()) {
siblingScanPrefix = makeRowKey(siblingId, new VariableOrder(commonVars), childBindingSet);
} else {
siblingScanPrefix = makeRowKey(siblingId, siblingVarOrder, childBindingSet);
}
return Span.prefix(siblingScanPrefix);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class JoinResultUpdater method updateJoinResults.
/**
* Updates the results of a Join node when one of its children has added a
* new Binding Set to its results.
*
* @param tx - The transaction all Fluo queries will use. (not null)
* @param childNodeId - The Node ID of the child whose results received a new Binding Set. (not null)
* @param childBindingSet - The Binding Set that was just emitted by child node. (not null)
* @param joinMetadata - The metadata for the Join that has been notified. (not null)
* @throws Exception The update could not be successfully performed.
*/
public void updateJoinResults(final TransactionBase tx, final String childNodeId, final VisibilityBindingSet childBindingSet, final JoinMetadata joinMetadata) throws Exception {
checkNotNull(tx);
checkNotNull(childNodeId);
checkNotNull(childBindingSet);
checkNotNull(joinMetadata);
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "Join Node ID: " + joinMetadata.getNodeId() + "\n" + "Child Node ID: " + childNodeId + "\n" + "Child Binding Set:\n" + childBindingSet + "\n");
// Figure out which join algorithm we are going to use.
final IterativeJoin joinAlgorithm;
switch(joinMetadata.getJoinType()) {
case NATURAL_JOIN:
joinAlgorithm = new NaturalJoin();
break;
case LEFT_OUTER_JOIN:
joinAlgorithm = new LeftOuterJoin();
break;
default:
throw new RuntimeException("Unsupported JoinType: " + joinMetadata.getJoinType());
}
// Figure out which side of the join the new binding set appeared on.
final Side emittingSide;
final String siblingId;
if (childNodeId.equals(joinMetadata.getLeftChildNodeId())) {
emittingSide = Side.LEFT;
siblingId = joinMetadata.getRightChildNodeId();
} else {
emittingSide = Side.RIGHT;
siblingId = joinMetadata.getLeftChildNodeId();
}
// Iterates over the sibling node's BindingSets that join with the new binding set.
final Set<VisibilityBindingSet> siblingBindingSets = new HashSet<>();
final Span siblingSpan = getSpan(tx, childNodeId, childBindingSet, siblingId);
final Column siblingColumn = getScanColumnFamily(siblingId);
final Optional<RowColumn> rowColumn = fillSiblingBatch(tx, siblingSpan, siblingColumn, siblingBindingSets, joinMetadata.getJoinBatchSize());
// Iterates over the resulting BindingSets from the join.
final Iterator<VisibilityBindingSet> newJoinResults;
if (emittingSide == Side.LEFT) {
newJoinResults = joinAlgorithm.newLeftResult(childBindingSet, siblingBindingSets.iterator());
} else {
newJoinResults = joinAlgorithm.newRightResult(siblingBindingSets.iterator(), childBindingSet);
}
// Insert the new join binding sets to the Fluo table.
final VariableOrder joinVarOrder = joinMetadata.getVariableOrder();
while (newJoinResults.hasNext()) {
final VisibilityBindingSet newJoinResult = newJoinResults.next();
// Create the Row Key for the emitted binding set. It does not contain visibilities.
final Bytes resultRow = makeRowKey(joinMetadata.getNodeId(), joinVarOrder, newJoinResult);
// Only insert the join Binding Set if it is new or BindingSet contains values not used in resultRow.
if (tx.get(resultRow, FluoQueryColumns.JOIN_BINDING_SET) == null || joinVarOrder.getVariableOrders().size() < newJoinResult.size()) {
// Create the Node Value. It does contain visibilities.
final Bytes nodeValueBytes = BS_SERDE.serialize(newJoinResult);
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Join Result:\n" + newJoinResult + "\n");
tx.set(resultRow, FluoQueryColumns.JOIN_BINDING_SET, nodeValueBytes);
}
}
// update the span and register updated batch job
if (rowColumn.isPresent()) {
final Span newSpan = AbstractBatchBindingSetUpdater.getNewSpan(rowColumn.get(), siblingSpan);
final JoinBatchInformation joinBatch = JoinBatchInformation.builder().setBatchSize(joinMetadata.getJoinBatchSize()).setBs(childBindingSet).setColumn(siblingColumn).setJoinType(joinMetadata.getJoinType()).setSide(emittingSide).setSpan(newSpan).setTask(Task.Add).build();
BatchInformationDAO.addBatch(tx, joinMetadata.getNodeId(), joinBatch);
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class PcjMetadataRendererTest method formatSingleMetadata.
@Test
public void formatSingleMetadata() throws Exception {
// Create the PcjMetadata that will be formatted as a report.
final PcjMetadata metadata = new PcjMetadata("SELECT ?x ?y " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?y <http://worksAt> <http://Chipotle>." + "}", 12233423L, Sets.<VariableOrder>newHashSet(new VariableOrder("x", "y"), new VariableOrder("y", "x")));
// Run the test.
final String expected = "---------------------------------------------------------------------\n" + "| Query ID | query1 |\n" + "| Cardinality | 12,233,423 |\n" + "| Export Variable Orders | y;x |\n" + "| | x;y |\n" + "| SPARQL | select ?x ?y |\n" + "| | where { |\n" + "| | ?x <http://talksTo> <http://Eve>. |\n" + "| | ?y <http://worksAt> <http://Chipotle>. |\n" + "| | } |\n" + "---------------------------------------------------------------------\n";
final PcjMetadataRenderer formatter = new PcjMetadataRenderer();
assertEquals(expected, formatter.render("query1", metadata));
}
Aggregations