Search in sources :

Example 1 with StatementPatternCollector

use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project QueryAnalysis by Wikidata.

the class OpenRDFQueryHandler method computeTripleCountWithService.

/**
 * {@inheritDoc}
 */
@Override
protected final void computeTripleCountWithService() {
    if (getValidityStatus() != QueryHandler.Validity.VALID) {
        this.tripleCountWithService = -1;
        return;
    }
    TupleExpr expr = this.query.getTupleExpr();
    StatementPatternCollector collector = new StatementPatternCollector();
    expr.visit(collector);
    this.tripleCountWithService = collector.getStatementPatterns().size();
}
Also used : StatementPatternCollector(org.openrdf.query.algebra.helpers.StatementPatternCollector)

Example 2 with StatementPatternCollector

use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project QueryAnalysis by Wikidata.

the class OpenRDFQueryHandler method computeVariableCountPattern.

/**
 * {@inheritDoc}
 */
@Override
protected final void computeVariableCountPattern() {
    if (getValidityStatus() != QueryHandler.Validity.VALID) {
        this.variableCountPattern = -1;
        return;
    }
    final Set<Var> variables = new HashSet<>();
    TupleExpr expr = this.query.getTupleExpr();
    StatementPatternCollector collector = new StatementPatternCollector();
    expr.visit(collector);
    List<StatementPattern> statementPatterns = collector.getStatementPatterns();
    for (StatementPattern statementPattern : statementPatterns) {
        List<Var> statementVariables = statementPattern.getVarList();
        for (Var statementVariable : statementVariables) {
            if (!statementVariable.isConstant()) {
                variables.add(statementVariable);
            }
        }
    }
    this.variableCountPattern = variables.size();
}
Also used : StatementPatternCollector(org.openrdf.query.algebra.helpers.StatementPatternCollector)

Example 3 with StatementPatternCollector

use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project incubator-rya by apache.

the class MongoDbSmartUriIT method testStorage.

@Test
public void testStorage() throws SmartUriException, MalformedQueryException, RuntimeException, QueryEvaluationException {
    smartUriConverter.storeEntity(BOB_ENTITY);
    final String sparql = "SELECT * WHERE { " + "<" + BOB.getData() + "> <" + RDF.TYPE + "> <" + PERSON_TYPE.getId().getData() + "> . " + "<" + BOB.getData() + "> <" + HAS_SSN.getData() + "> ?ssn . " + "<" + BOB.getData() + "> <" + HAS_AGE.getData() + "> ?age . " + "<" + BOB.getData() + "> <" + HAS_WEIGHT.getData() + "> ?weight . " + "<" + BOB.getData() + "> <" + HAS_ADDRESS.getData() + "> ?address . " + "}";
    final StatementPatternCollector spCollector = new StatementPatternCollector();
    new SPARQLParser().parseQuery(sparql, null).getTupleExpr().visit(spCollector);
    final List<StatementPattern> patterns = spCollector.getStatementPatterns();
    final EntityQueryNode entityQueryNode = new EntityQueryNode(PERSON_TYPE, patterns, smartUriConverter.getEntityStorage());
    final QueryBindingSet queryBindingSet = new QueryBindingSet();
    final Property ssnProperty = BOB_ENTITY.lookupTypeProperty(PERSON_TYPE, HAS_SSN).get();
    queryBindingSet.addBinding(HAS_SSN.getData(), RyaToRdfConversions.convertValue(ssnProperty.getValue()));
    final CloseableIteration<BindingSet, QueryEvaluationException> iter = entityQueryNode.evaluate(queryBindingSet);
    int count = 0;
    // These should match what was used in the SPARQL query.
    final List<String> queryParamNames = Lists.newArrayList("ssn", "age", "weight", "address");
    while (iter.hasNext()) {
        final BindingSet bs = iter.next();
        assertTrue(bs.getBindingNames().containsAll(queryParamNames));
        count++;
    }
    assertEquals(count, 1);
}
Also used : StatementPatternCollector(org.openrdf.query.algebra.helpers.StatementPatternCollector) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 4 with StatementPatternCollector

use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project incubator-rya by apache.

the class GeoTemporalTestUtils method getSps.

public static List<StatementPattern> getSps(final String query) throws Exception {
    final StatementPatternCollector collector = new StatementPatternCollector();
    new SPARQLParser().parseQuery(query, null).getTupleExpr().visit(collector);
    return collector.getStatementPatterns();
}
Also used : StatementPatternCollector(org.openrdf.query.algebra.helpers.StatementPatternCollector) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser)

Example 5 with StatementPatternCollector

use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project incubator-rya by apache.

the class GeneralizedExternalProcessor method getQNodes.

private static Set<QueryModelNode> getQNodes(QueryModelNode queryNode) {
    Set<QueryModelNode> rtns = new HashSet<QueryModelNode>();
    StatementPatternCollector spc = new StatementPatternCollector();
    queryNode.visit(spc);
    rtns.addAll(spc.getStatementPatterns());
    FilterCollector fvis = new FilterCollector();
    queryNode.visit(fvis);
    rtns.addAll(fvis.getFilters());
    ExternalTupleCollector eVis = new ExternalTupleCollector();
    queryNode.visit(eVis);
    rtns.addAll(eVis.getExtTup());
    return rtns;
}
Also used : StatementPatternCollector(org.openrdf.query.algebra.helpers.StatementPatternCollector) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) HashSet(java.util.HashSet)

Aggregations

StatementPatternCollector (org.openrdf.query.algebra.helpers.StatementPatternCollector)8 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)4 HashSet (java.util.HashSet)2 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)2 StatementPattern (org.openrdf.query.algebra.StatementPattern)2 Property (org.apache.rya.indexing.entity.model.Property)1 EntityQueryNode (org.apache.rya.indexing.entity.query.EntityQueryNode)1 Test (org.junit.Test)1 BindingSet (org.openrdf.query.BindingSet)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)1