Search in sources :

Example 1 with ValueConstant

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));
        }
    }
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Value(org.openrdf.model.Value) RangeValue(org.apache.rya.api.domain.RangeValue) FunctionCall(org.openrdf.query.algebra.FunctionCall) RangeValue(org.apache.rya.api.domain.RangeValue)

Example 2 with ValueConstant

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;
}
Also used : Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Literal(org.openrdf.model.Literal) ArrayList(java.util.ArrayList) List(java.util.List) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList)

Example 3 with ValueConstant

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);
}
Also used : Not(org.openrdf.query.algebra.Not) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) Test(org.junit.Test)

Example 4 with ValueConstant

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());
}
Also used : Extension(org.openrdf.query.algebra.Extension) StatementPattern(org.openrdf.query.algebra.StatementPattern) Not(org.openrdf.query.algebra.Not) QueryRoot(org.openrdf.query.algebra.QueryRoot) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 5 with ValueConstant

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());
}
Also used : Extension(org.openrdf.query.algebra.Extension) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryRoot(org.openrdf.query.algebra.QueryRoot) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) Test(org.junit.Test)

Aggregations

ValueConstant (org.openrdf.query.algebra.ValueConstant)17 Var (org.openrdf.query.algebra.Var)14 Test (org.junit.Test)9 ExtensionElem (org.openrdf.query.algebra.ExtensionElem)8 ValueExpr (org.openrdf.query.algebra.ValueExpr)8 StatementPattern (org.openrdf.query.algebra.StatementPattern)6 Value (org.openrdf.model.Value)5 Extension (org.openrdf.query.algebra.Extension)5 FunctionCall (org.openrdf.query.algebra.FunctionCall)4 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)4 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)4 Join (org.openrdf.query.algebra.Join)3 MultiProjection (org.openrdf.query.algebra.MultiProjection)3 SingletonSet (org.openrdf.query.algebra.SingletonSet)3 HashSet (java.util.HashSet)2 Literal (org.openrdf.model.Literal)2 Not (org.openrdf.query.algebra.Not)2 Projection (org.openrdf.query.algebra.Projection)2 QueryRoot (org.openrdf.query.algebra.QueryRoot)2 BasicDBObject (com.mongodb.BasicDBObject)1