Search in sources :

Example 71 with QueryModelNode

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

the class EntityIndexSetProvider method getExternalSets.

@Override
public List<EntityQueryNode> getExternalSets(final QuerySegment<EntityQueryNode> node) {
    typeMap = HashMultimap.create();
    subjectTypeMap = new HashMap<>();
    // discover entities
    final List<StatementPattern> unused = new ArrayList<>();
    for (final QueryModelNode pattern : node.getOrderedNodes()) {
        if (pattern instanceof StatementPattern) {
            discoverEntities((StatementPattern) pattern, unused);
        }
    }
    final List<EntityQueryNode> nodes = new ArrayList<>();
    for (final Type type : typeMap.keySet()) {
        // replace all nodes in the tupleExpr of the collection of statement patterns with this node.
        final EntityQueryNode entity = new EntityQueryNode(type, typeMap.get(type), entityStorage);
        nodes.add(entity);
    }
    return nodes;
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Type(org.apache.rya.indexing.entity.model.Type) EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode)

Example 72 with QueryModelNode

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

the class TupleExecutionPlanGenerator method getPlans.

private List<TupleExpr> getPlans(final TupleExpr te) {
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    final Set<QueryModelNode> nodeSet = nc.getNodeSet();
    final List<Filter> filterList = nc.getFilterSet();
    final Projection projection = nc.getProjection().clone();
    final List<TupleExpr> queryPlans = Lists.newArrayList();
    final Collection<List<QueryModelNode>> plans = Collections2.permutations(nodeSet);
    for (final List<QueryModelNode> p : plans) {
        if (p.size() == 0) {
            throw new IllegalArgumentException("Tuple must contain at least one node!");
        } else if (p.size() == 1) {
            queryPlans.add(te);
        } else {
            queryPlans.add(buildTuple(p, filterList, projection));
        }
    }
    return queryPlans;
}
Also used : Filter(org.openrdf.query.algebra.Filter) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) Projection(org.openrdf.query.algebra.Projection) List(java.util.List) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Example 73 with QueryModelNode

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

the class AbstractExternalSetMatcher method updateTupleAndNodes.

protected void updateTupleAndNodes() {
    segmentNodeList = segment.getOrderedNodes();
    final TupleExprAndNodes tupAndNodes = segment.getQuery();
    tuple = tupAndNodes.getTupleExpr();
    filters = tupAndNodes.getFilters();
    unmatched = new HashSet<>();
    final List<QueryModelNode> nodes = tupAndNodes.getNodes();
    for (final QueryModelNode q : nodes) {
        if (q instanceof UnaryTupleOperator || q instanceof BinaryTupleOperator) {
            unmatched.add((TupleExpr) q);
        } else if (q instanceof FlattenedOptional) {
            final FlattenedOptional opt = (FlattenedOptional) q;
            final TupleExpr rightArg = opt.getRightArg();
            if (rightArg instanceof UnaryTupleOperator || rightArg instanceof BinaryTupleOperator) {
                unmatched.add(rightArg);
            }
        }
    }
}
Also used : TupleExprAndNodes(org.apache.rya.indexing.external.matching.QueryNodesToTupleExpr.TupleExprAndNodes) UnaryTupleOperator(org.openrdf.query.algebra.UnaryTupleOperator) BinaryTupleOperator(org.openrdf.query.algebra.BinaryTupleOperator) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Example 74 with QueryModelNode

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

the class BasicRater method getConnectedComponentRating.

private double getConnectedComponentRating(List<QueryModelNode> eNodes) {
    Multimap<String, Integer> commonVarBin = HashMultimap.create();
    // bin QueryModelNode positions according to variable names
    for (int i = 0; i < eNodes.size(); i++) {
        QueryModelNode node = eNodes.get(i);
        if (node instanceof TupleExpr) {
            TupleExpr tup = (TupleExpr) node;
            Set<String> bindingNames = tup.getAssuredBindingNames();
            for (String name : bindingNames) {
                if (!name.startsWith("-const-")) {
                    commonVarBin.put(name, i);
                }
            }
        }
    }
    Set<List<Integer>> pairs = new HashSet<>();
    for (String var : commonVarBin.keySet()) {
        Set<Integer> pos = Sets.newHashSet(commonVarBin.get(var));
        pairs.addAll(Sets.cartesianProduct(pos, pos));
    }
    int numComponents = countComponents(eNodes.size(), pairs);
    return ((double) numComponents) / eNodes.size();
}
Also used : QueryModelNode(org.openrdf.query.algebra.QueryModelNode) List(java.util.List) TupleExpr(org.openrdf.query.algebra.TupleExpr) HashSet(java.util.HashSet)

Example 75 with QueryModelNode

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

the class OptionalJoinSegment method clone.

@Override
public OptionalJoinSegment<T> clone() {
    List<QueryModelNode> order = new ArrayList<>();
    for (QueryModelNode node : orderedNodes) {
        order.add(node.clone());
    }
    Set<QueryModelNode> unorder = Sets.newHashSet(order);
    Map<ValueExpr, Filter> map = new HashMap<>();
    for (ValueExpr expr : conditionMap.keySet()) {
        map.put(expr.clone(), conditionMap.get(expr).clone());
    }
    return new OptionalJoinSegment<T>(unorder, order, map);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Filter(org.openrdf.query.algebra.Filter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode)

Aggregations

QueryModelNode (org.openrdf.query.algebra.QueryModelNode)98 TupleExpr (org.openrdf.query.algebra.TupleExpr)74 Test (org.junit.Test)68 ArrayList (java.util.ArrayList)63 ParsedQuery (org.openrdf.query.parser.ParsedQuery)63 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)62 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)56 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)48 StatementPattern (org.openrdf.query.algebra.StatementPattern)33 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)27 HashSet (java.util.HashSet)26 Projection (org.openrdf.query.algebra.Projection)23 Filter (org.openrdf.query.algebra.Filter)15 LeftJoin (org.openrdf.query.algebra.LeftJoin)12 Join (org.openrdf.query.algebra.Join)11 ValueExpr (org.openrdf.query.algebra.ValueExpr)11 QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)8 Configuration (org.apache.hadoop.conf.Configuration)7 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)7 BatchWriter (org.apache.accumulo.core.client.BatchWriter)6