use of org.openrdf.query.algebra.evaluation.QueryBindingSet 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.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class PipelineQueryIT method testNoVariableSP.
@Test
public void testNoVariableSP() throws Exception {
// Insert data
insert(OWL.THING, RDF.TYPE, OWL.CLASS);
insert(FOAF.PERSON, RDF.TYPE, OWL.CLASS, 1);
insert(FOAF.PERSON, RDFS.SUBCLASSOF, OWL.THING);
insert(VF.createURI("urn:Alice"), RDF.TYPE, FOAF.PERSON);
dao.flush();
// Define query and expected results
final String query = "SELECT * WHERE {\n" + " owl:Thing a owl:Class .\n" + "}";
Multiset<BindingSet> expectedSolutions = HashMultiset.create();
expectedSolutions.add(new EmptyBindingSet());
// Execute pipeline and verify results
QueryRoot queryTree = new QueryRoot(PARSER.parseQuery(query, null).getTupleExpr());
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(getRyaCollection());
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Projection);
Projection projection = (Projection) queryTree.getArg();
Assert.assertTrue(projection.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projection.getArg();
Multiset<BindingSet> solutions = HashMultiset.create();
CloseableIteration<BindingSet, QueryEvaluationException> iter = pipelineNode.evaluate(new QueryBindingSet());
while (iter.hasNext()) {
solutions.add(iter.next());
}
Assert.assertEquals(expectedSolutions, solutions);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet 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.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class AccumuloPeriodicQueryResultStorage method getRowPrefix.
private Text getRowPrefix(final long binId) throws BindingSetConversionException {
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding(PeriodicQueryResultStorage.PeriodicBinId, new LiteralImpl(Long.toString(binId), XMLSchema.LONG));
return new Text(converter.convert(bs, new VariableOrder(PeriodicQueryResultStorage.PeriodicBinId)));
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class BindingSetStringConverter method convert.
@Override
public BindingSet convert(final String bindingSetString, final VariableOrder varOrder) {
requireNonNull(bindingSetString);
requireNonNull(varOrder);
// If both are empty, return an empty binding set.
if (bindingSetString.isEmpty() && varOrder.toString().isEmpty()) {
return new MapBindingSet();
}
// Otherwise parse it.
final String[] bindingStrings = bindingSetString.split(BINDING_DELIM);
final String[] varOrderArr = varOrder.toArray();
checkArgument(varOrderArr.length == bindingStrings.length, "The number of Bindings must match the length of the VariableOrder.");
final QueryBindingSet bindingSet = new QueryBindingSet();
for (int i = 0; i < bindingStrings.length; i++) {
final String bindingString = bindingStrings[i];
if (!NULL_VALUE_STRING.equals(bindingString)) {
final String name = varOrderArr[i];
final Value value = toValue(bindingStrings[i]);
bindingSet.addBinding(name, value);
}
}
return bindingSet;
}
Aggregations