Search in sources :

Example 21 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.

the class SqlgUtil method filterSqlgSchemaHasContainers.

/**
 * return tables in their schema with their properties, matching the given hasContainers
 *
 * @param topology
 * @param hasContainers
 * @param withSqlgSchema do we want the sqlg schema tables too?
 * @return
 */
public static Map<String, Map<String, PropertyType>> filterSqlgSchemaHasContainers(Topology topology, List<HasContainer> hasContainers, boolean withSqlgSchema) {
    HasContainer fromHasContainer = null;
    HasContainer withoutHasContainer = null;
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainer.getKey().equals(TopologyStrategy.TOPOLOGY_SELECTION_FROM)) {
            fromHasContainer = hasContainer;
            break;
        } else if (hasContainer.getKey().equals(TopologyStrategy.TOPOLOGY_SELECTION_WITHOUT)) {
            withoutHasContainer = hasContainer;
            break;
        }
    }
    // from and without are mutually exclusive, only one will ever be set.
    Map<String, Map<String, PropertyType>> filteredAllTables;
    if (fromHasContainer != null) {
        filteredAllTables = topology.getAllTablesFrom((Set<TopologyInf>) fromHasContainer.getPredicate().getValue());
    } else if (withoutHasContainer != null) {
        filteredAllTables = topology.getAllTablesWithout((Set<TopologyInf>) withoutHasContainer.getPredicate().getValue());
    } else {
        filteredAllTables = topology.getAllTables(withSqlgSchema);
    }
    return filteredAllTables;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 22 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project janusgraph by JanusGraph.

the class JanusGraphPropertiesStep method makeQuery.

private <Q extends BaseVertexQuery> Q makeQuery(Q query) {
    final String[] keys = getPropertyKeys();
    query.keys(keys);
    for (final HasContainer condition : hasContainers) {
        query.has(condition.getKey(), JanusGraphPredicateUtils.convert(condition.getBiPredicate()), condition.getValue());
    }
    for (final OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (limit != BaseQuery.NO_LIMIT)
        query.limit(limit);
    ((BasicVertexCentricQueryBuilder) query).profiler(queryProfiler);
    return query;
}
Also used : BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Example 23 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project janusgraph by JanusGraph.

the class JanusGraphVertexStep method makeQuery.

public <Q extends BaseVertexQuery> Q makeQuery(Q query) {
    query.labels(getEdgeLabels());
    query.direction(getDirection());
    for (final HasContainer condition : hasContainers) {
        query.has(condition.getKey(), JanusGraphPredicateUtils.convert(condition.getBiPredicate()), condition.getValue());
    }
    for (final OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (limit != BaseQuery.NO_LIMIT)
        query.limit(limit);
    ((BasicVertexCentricQueryBuilder) query).profiler(queryProfiler);
    return query;
}
Also used : BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Example 24 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project janusgraph by JanusGraph.

the class AdjacentVertexFilterOptimizerStrategy method replaceStep.

private void replaceStep(Traversal.Admin<?, ?> traversal, OptimizableQueryType type, TraversalFilterStep originalStep, List<Step> steps) {
    // Get the direction in which we filter on the adjacent vertex (or null if not a valid
    // adjacency filter)
    Direction direction = parseDirection(steps);
    P predicate = parsePredicate(type, steps);
    // Check that we have a valid direction and a valid vertex filter predicate
    if (direction != null && isValidPredicate(type, predicate) && isPreviousStepValid(originalStep, direction)) {
        // Now replace the step with a has condition
        HasContainer hc = new HasContainer(ImplicitKey.ADJACENT_ID.name(), P.eq(predicate.getValue()));
        TraversalHelper.replaceStep(originalStep, new HasStep(traversal, hc), traversal);
    }
}
Also used : P(org.apache.tinkerpop.gremlin.process.traversal.P) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) Direction(org.apache.tinkerpop.gremlin.structure.Direction)

Example 25 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project janusgraph by JanusGraph.

the class JanusGraphStep method addLocalHasContainersConvertingAndPContainers.

@Override
public List<HasContainer> addLocalHasContainersConvertingAndPContainers(TraversalParent parent, List<HasContainer> unconvertedHasContainers) {
    List<HasContainer> localHasContainers = new ArrayList<>(unconvertedHasContainers.size());
    for (HasContainer hasContainer : unconvertedHasContainers) {
        localHasContainers.add(JanusGraphPredicateUtils.convert(hasContainer));
    }
    Map<List<HasContainer>, QueryInfo> hasContainers = hasLocalContainers.computeIfAbsent(parent.asStep().getId(), k -> new LinkedHashMap<>());
    hasContainers.put(localHasContainers, new QueryInfo(new ArrayList<>(), 0, BaseQuery.NO_LIMIT));
    return localHasContainers;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QueryInfo(org.janusgraph.graphdb.tinkerpop.optimize.QueryInfo)

Aggregations

HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)56 AndOrHasContainer (org.umlg.sqlg.sql.parse.AndOrHasContainer)13 P (org.apache.tinkerpop.gremlin.process.traversal.P)9 Collectors (java.util.stream.Collectors)7 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)6 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)6 FullText (org.umlg.sqlg.predicate.FullText)6 PredicatesHolder (org.unipop.query.predicates.PredicatesHolder)6 java.util (java.util)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 BiPredicate (java.util.function.BiPredicate)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)5 JSONObject (org.json.JSONObject)5 GraphStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep)4 BasicVertexCentricQueryBuilder (org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder)4 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)3 HasContainerHolder (org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder)3 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)3 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)3