use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class ConstructQueryResultUpdater method updateConstructQueryResults.
/**
* Updates the Construct Query results by applying the {@link ConnstructGraph} to
* create a {@link RyaSubGraph} and then writing the subgraph to {@link FluoQueryColumns#CONSTRUCT_STATEMENTS}.
* @param tx - transaction used to write the subgraph
* @param bs - BindingSet that the ConstructProjection expands into a subgraph
* @param metadata - metadata that the ConstructProjection is extracted from
*/
public void updateConstructQueryResults(TransactionBase tx, VisibilityBindingSet bs, ConstructQueryMetadata metadata) {
String nodeId = metadata.getNodeId();
VariableOrder varOrder = metadata.getVariableOrder();
Column column = FluoQueryColumns.CONSTRUCT_STATEMENTS;
ConstructGraph graph = metadata.getConstructGraph();
String parentId = metadata.getParentNodeId();
// Create the Row Key for the emitted binding set. It does not contain visibilities.
final Bytes resultRow = makeRowKey(nodeId, varOrder, bs);
// If this is a new binding set, then emit it.
if (tx.get(resultRow, column) == null || varOrder.getVariableOrders().size() < bs.size()) {
Set<RyaStatement> statements = graph.createGraphFromBindingSet(bs);
RyaSubGraph subgraph = new RyaSubGraph(parentId, statements);
final Bytes nodeValueBytes = Bytes.of(serializer.toBytes(subgraph));
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Binding Set: " + subgraph + "\n");
tx.set(resultRow, column, nodeValueBytes);
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class PCJKeyToCrossProductBindingSetIterator method getBindingSet.
/**
* @param key
* - Accumulo key obtained from scan
* @return - BindingSet satisfying any specified constant constraints
* @throws BindingSetConversionException
* @throws QueryEvaluationException
*/
private BindingSet getBindingSet(Key key) throws BindingSetConversionException, QueryEvaluationException {
byte[] row = key.getRow().getBytes();
String[] varOrder = key.getColumnFamily().toString().split(ExternalTupleSet.VAR_ORDER_DELIM);
BindingSet bindingSet = converter.convert(row, new VariableOrder(varOrder));
QueryBindingSet bs = new QueryBindingSet();
for (String var : bindingSet.getBindingNames()) {
String mappedVar = null;
if (pcjVarMap.containsKey(var)) {
mappedVar = pcjVarMap.get(var);
} else {
throw new QueryEvaluationException("PCJ Variable has no mapping to query variable.");
}
if (constantConstraintsExist) {
if (mappedVar.startsWith(ExternalTupleSet.CONST_PREFIX) && constantConstraints.containsKey(mappedVar) && !constantConstraints.get(mappedVar).equals(bindingSet.getValue(var))) {
return EMPTY_BINDINGSET;
}
}
if (!mappedVar.startsWith(ExternalTupleSet.CONST_PREFIX)) {
bs.addBinding(mappedVar, bindingSet.getValue(var));
}
}
return bs;
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class PCJKeyToJoinBindingSetIterator method getBindingSetEntryAndMatchConstants.
/**
* @param key
* - Accumulo key obtained from scan
* @return - Entry<String,BindingSet> satisfying the constant constraints
* @throws BindingSetConversionException
*/
private Map.Entry<String, BindingSet> getBindingSetEntryAndMatchConstants(Key key) throws BindingSetConversionException {
byte[] row = key.getRow().getBytes();
String[] varOrder = key.getColumnFamily().toString().split(ExternalTupleSet.VAR_ORDER_DELIM);
BindingSet bindingSet = converter.convert(row, new VariableOrder(varOrder));
QueryBindingSet bs = new QueryBindingSet();
for (String var : bindingSet.getBindingNames()) {
String mappedVar = pcjVarMap.get(var);
if (mappedVar.startsWith(ExternalTupleSet.CONST_PREFIX) && constantConstraints.containsKey(mappedVar) && !constantConstraints.get(mappedVar).equals(bindingSet.getValue(var))) {
return EMPTY_ENTRY;
} else {
bs.addBinding(mappedVar, bindingSet.getValue(var));
}
}
String orderedValueString = bindingSet.getValue(varOrder[0]).toString();
for (int i = 1; i < maxPrefixLen; i++) {
Value value = bindingSet.getValue(varOrder[i]);
if (value != null) {
orderedValueString = orderedValueString + ExternalTupleSet.VALUE_DELIM + value.toString();
}
}
return new RdfCloudTripleStoreUtils.CustomEntry<String, BindingSet>(orderedValueString, bs);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class MongoPcjDocumentsTest method metadataExists.
@Test
public void metadataExists() throws Exception {
final List<VariableOrder> varOrders = Lists.newArrayList(new VariableOrder("b", "a"), new VariableOrder("a", "b"));
final MongoPcjDocuments docConverter = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
docConverter.createPcj("pcjTest", sparql);
PcjMetadata actual = docConverter.getPcjMetadata("pcjTest");
PcjMetadata expected = new PcjMetadata(sparql, 0, varOrders);
assertEquals(expected, actual);
// Setup the binding set that will be converted.
final MapBindingSet originalBindingSet1 = new MapBindingSet();
originalBindingSet1.addBinding("x", new URIImpl("http://a"));
originalBindingSet1.addBinding("y", new URIImpl("http://b"));
originalBindingSet1.addBinding("z", new URIImpl("http://c"));
final VisibilityBindingSet results1 = new VisibilityBindingSet(originalBindingSet1, "A&B&C");
// Setup the binding set that will be converted.
final MapBindingSet originalBindingSet2 = new MapBindingSet();
originalBindingSet2.addBinding("x", new URIImpl("http://1"));
originalBindingSet2.addBinding("y", new URIImpl("http://2"));
originalBindingSet2.addBinding("z", new URIImpl("http://3"));
final VisibilityBindingSet results2 = new VisibilityBindingSet(originalBindingSet2, "A&B&C");
final List<VisibilityBindingSet> bindingSets = new ArrayList<>();
bindingSets.add(results1);
bindingSets.add(results2);
docConverter.addResults("pcjTest", bindingSets);
actual = docConverter.getPcjMetadata("pcjTest");
expected = new PcjMetadata(sparql, 2, varOrders);
assertEquals(expected, actual);
docConverter.purgePcjs("pcjTest");
actual = docConverter.getPcjMetadata("pcjTest");
expected = new PcjMetadata(sparql, 0, varOrders);
assertEquals(expected, actual);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method dropPcj.
@Test(expected = PCJStorageException.class)
public void dropPcj() throws Exception {
// Create a PCJ index.
final String pcjTableName = "testPcj";
final String sparql = "SELECT x WHERE ?x <http://isA> <http://Food>";
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createPcj(pcjTableName, sparql);
// Fetch its metadata to show that it has actually been created.
final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, new ArrayList<VariableOrder>());
PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
assertEquals(expectedMetadata, metadata);
// Drop it.
pcjs.dropPcj(pcjTableName);
// Show the metadata is no longer present.
metadata = pcjs.getPcjMetadata(pcjTableName);
}
Aggregations