use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class FilterRangeVisitor method meet.
@Override
public void meet(final Filter node) throws Exception {
super.meet(node);
final ValueExpr arg = node.getCondition();
if (arg instanceof FunctionCall) {
final FunctionCall fc = (FunctionCall) arg;
if (RANGE.stringValue().equals(fc.getURI())) {
// range(?var, start, end)
final List<ValueExpr> valueExprs = fc.getArgs();
if (valueExprs.size() != 3) {
throw new QueryEvaluationException("org.apache:range must have 3 parameters: variable, start, end");
}
final Var var = (Var) valueExprs.get(0);
final ValueConstant startVc = (ValueConstant) valueExprs.get(1);
final ValueConstant endVc = (ValueConstant) valueExprs.get(2);
final Value start = startVc.getValue();
final Value end = endVc.getValue();
rangeValues.put(var, new RangeValue(start, end));
node.setCondition(new ValueConstant(BooleanLiteralImpl.TRUE));
}
}
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class QueryVariableNormalizer method filterCommonVars.
private static List<List<String>> filterCommonVars(List<QueryModelNode> vars1, List<QueryModelNode> vars2) {
List<List<String>> varList = Lists.newArrayList();
List<String> varList1 = Lists.newArrayList();
List<String> varList2 = Lists.newArrayList();
for (int i = 0; i < vars1.size(); i++) {
if ((vars1.get(i) instanceof ValueConstant) && (vars2.get(i) instanceof Var)) {
ValueConstant vc = (ValueConstant) vars1.get(i);
String s = vc.getValue().toString();
if (vc.getValue() instanceof Literal) {
s = s.substring(1, s.length() - 1);
}
s = "-const-" + s;
varList1.add(s);
varList2.add(((Var) vars2.get(i)).getName());
} else if (!(vars1.get(i) instanceof ValueConstant)) {
if (!((Var) vars1.get(i)).isConstant() && (vars2.get(i) instanceof Var) && !((Var) vars2.get(i)).isConstant()) {
varList1.add(((Var) vars1.get(i)).getName());
varList2.add(((Var) vars2.get(i)).getName());
} else if (((Var) vars1.get(i)).isConstant() && (vars2.get(i) instanceof Var) && !((Var) vars2.get(i)).isConstant()) {
varList1.add(((Var) vars1.get(i)).getName());
varList2.add(((Var) vars2.get(i)).getName());
}
}
}
varList.add(varList1);
varList.add(varList2);
return varList;
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class AggregationPipelineQueryNodeTest method testExtend.
@Test
public void testExtend() {
final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode(collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create());
// Extend with a mix of variables and constants
List<ExtensionElem> extensionElements = Arrays.asList(new ExtensionElem(new Var("x"), "subject"), new ExtensionElem(new ValueConstant(RDF.TYPE), "predicate"), new ExtensionElem(new Var("y"), "object"));
AggregationPipelineQueryNode node = base.clone();
boolean success = node.extend(extensionElements);
Assert.assertTrue(success);
Assert.assertEquals(1, node.getPipeline().size());
Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object"), node.getAssuredBindingNames());
Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object", "opt"), node.getBindingNames());
// Attempt to extend with an unsupported expression
extensionElements = Arrays.asList(new ExtensionElem(new Var("x"), "subject"), new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"));
node = base.clone();
success = node.extend(extensionElements);
Assert.assertFalse(success);
Assert.assertEquals(base, node);
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testUnsupportedExtension.
@Test
public void testUnsupportedExtension() throws Exception {
StatementPattern sp = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
List<ExtensionElem> elements = Arrays.asList(new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"), new ExtensionElem(new ValueConstant(TAKES), "constant"));
Extension extensionNode = new Extension(sp, elements);
QueryRoot queryTree = new QueryRoot(extensionNode);
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Extension);
Assert.assertEquals(elements, ((Extension) queryTree.getArg()).getElements());
TupleExpr innerQuery = ((Extension) queryTree.getArg()).getArg();
Assert.assertTrue(innerQuery instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) innerQuery;
Assert.assertEquals(Sets.newHashSet("x", "c"), pipelineNode.getAssuredBindingNames());
}
use of org.openrdf.query.algebra.ValueConstant in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testExtension.
@Test
public void testExtension() throws Exception {
QueryRoot queryTree = new QueryRoot(new Extension(new StatementPattern(new Var("x"), constant(TAKES), new Var("c")), new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new ValueConstant(TAKES), "constant")));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("x", "c", "renamed", "constant"), pipelineNode.getAssuredBindingNames());
}
Aggregations