org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TinkerGraphStepStrategy.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;

    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal);
        Step<?, ?> currentStep = tinkerGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer))
                        tinkerGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
Example #2
Source File: TinkerGraphStep.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
private Iterator<? extends Vertex> vertices() {
    final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get();
    final HasContainer indexedContainer = getIndexKey(Vertex.class);
    final Optional<HasContainer> hasLabelContainer = findHasLabelStep();
    // ids are present, filter on them first
    if (null == this.ids)
        return Collections.emptyIterator();
    else if (this.ids.length > 0)
        return this.iteratorList(graph.vertices(this.ids));
    else if (graph.ondiskOverflowEnabled && hasLabelContainer.isPresent())
        return graph.verticesByLabel((P<String>) hasLabelContainer.get().getPredicate());
    else
        return null == indexedContainer ?
                this.iteratorList(graph.vertices()) :
                IteratorUtils.filter(TinkerHelper.queryVertexIndex(graph, indexedContainer.getKey(), indexedContainer.getPredicate().getValue()).iterator(),
                        vertex -> HasContainer.testAll(vertex, this.hasContainers));
}
 
Example #3
Source File: TinkerGraphStep.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
private Iterator<? extends Edge> edges() {
    final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get();
    final HasContainer indexedContainer = getIndexKey(Edge.class);
    final Optional<HasContainer> hasLabelContainer = findHasLabelStep();
    // ids are present, filter on them first
    if (null == this.ids)
        return Collections.emptyIterator();
    else if (this.ids.length > 0)
        return this.iteratorList(graph.edges(this.ids));
    else if (graph.ondiskOverflowEnabled && hasLabelContainer.isPresent())
        return graph.edgesByLabel((P<String>) hasLabelContainer.get().getPredicate());
    else
        return null == indexedContainer ?
                this.iteratorList(graph.edges()) :
                TinkerHelper.queryEdgeIndex(graph, indexedContainer.getKey(), indexedContainer.getPredicate().getValue()).stream()
                        .filter(edge -> HasContainer.testAll(edge, this.hasContainers))
                        .collect(Collectors.<Edge>toList()).iterator();
}
 
Example #4
Source File: BaseStrategy.java    From sqlg with MIT License 6 votes vote down vote up
private boolean isNotWithMultipleColumnValue(HasContainerHolder currentStep) {
    for (HasContainer h : currentStep.getHasContainers()) {
        P<?> predicate = h.getPredicate();
        //noinspection unchecked
        if (predicate.getValue() instanceof ZonedDateTime ||
                predicate.getValue() instanceof Period ||
                predicate.getValue() instanceof Duration ||
                (predicate.getValue() instanceof List && containsWithMultipleColumnValue((List<Object>) predicate.getValue())) ||
                (predicate instanceof ConnectiveP && isConnectivePWithMultipleColumnValue((ConnectiveP) h.getPredicate()))) {


            return false;
        }

    }
    return true;
}
 
Example #5
Source File: BaseStrategy.java    From sqlg with MIT License 6 votes vote down vote up
private List<HasContainer> optimizeInside(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
    List<HasContainer> result = new ArrayList<>();
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof AndP) {
            AndP<?> andP = (AndP) hasContainer.getPredicate();
            List<? extends P<?>> predicates = andP.getPredicates();
            if (predicates.size() == 2) {
                if (predicates.get(0).getBiPredicate() == Compare.gt && predicates.get(1).getBiPredicate() == Compare.lt) {
                    replacedStep.addHasContainer(hasContainer);
                    result.add(hasContainer);
                }
            }
        }
    }
    return result;
}
 
Example #6
Source File: GraphTraversal.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Filters vertices, edges and vertex properties based on their value.
 *
 * @param value       the value of the {@link Element}
 * @param otherValues additional values of the {@link Element}
 * @return the traversal with an appended {@link HasStep}
 * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#has-step" target="_blank">Reference Documentation - Has Step</a>
 */
public default GraphTraversal<S, E> hasValue(final Object value, final Object... otherValues) {
    if (value instanceof P)
        return this.hasValue((P) value);
    else {
        final List<Object> values = new ArrayList<>();
        if (value instanceof Object[]) {
            Collections.addAll(values, (Object[]) value);
        } else
            values.add(value);
        for (final Object v : otherValues) {
            if (v instanceof Object[]) {
                Collections.addAll(values, (Object[]) v);
            } else
                values.add(v);
        }
        this.asAdmin().getBytecode().addStep(Symbols.hasValue, values.toArray());
        return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.value.getAccessor(), values.size() == 1 ? P.eq(values.get(0)) : P.within(values)));
    }
}
 
Example #7
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static Condition convContains2Relation(HugeGraph graph,
                                              HasContainer has) {
    // Convert contains-key or contains-value
    BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate();
    E.checkArgument(bp == Compare.eq, "CONTAINS query with relation " +
                    "'%s' is not supported", bp);

    HugeKeys key = token2HugeKey(has.getKey());
    E.checkNotNull(key, "token key");
    Object value = has.getValue();

    if (keyForContainsKey(has.getKey())) {
        if (value instanceof String) {
            value = graph.propertyKey((String) value).id();
        }
        return Condition.containsKey(key, value);
    } else {
        assert keyForContainsValue(has.getKey());
        return Condition.containsValue(key, value);
    }
}
 
Example #8
Source File: HasStepFolder.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
static void foldInRange(HasStepFolder janusgraphStep, Step<?, ?> tinkerpopStep, Traversal.Admin<?, ?> traversal, List<HasContainer> hasContainers) {
    Step<?, ?> nextStep = tinkerpopStep instanceof IdentityStep ? JanusGraphTraversalUtil.getNextNonIdentityStep(tinkerpopStep) : tinkerpopStep;
    if (nextStep instanceof RangeGlobalStep) {
        RangeGlobalStep range = (RangeGlobalStep) nextStep;
        int low = 0;
        if (janusgraphStep instanceof JanusGraphStep) {
            low = QueryUtil.convertLimit(range.getLowRange());
            low = QueryUtil.mergeLowLimits(low, hasContainers == null ? janusgraphStep.getLowLimit() : janusgraphStep.getLocalLowLimit(hasContainers));
        }
        int high = QueryUtil.convertLimit(range.getHighRange());
        high = QueryUtil.mergeHighLimits(high, hasContainers == null ? janusgraphStep.getHighLimit() : janusgraphStep.getLocalHighLimit(hasContainers));
        if (hasContainers == null) {
            janusgraphStep.setLimit(low, high);
        } else {
            janusgraphStep.setLocalLimit(hasContainers, low, high);
        }
        if (janusgraphStep instanceof JanusGraphStep || range.getLowRange() == 0) { //Range can be removed since there is JanusGraphStep or no offset
            nextStep.getLabels().forEach(janusgraphStep::addLabel);
            traversal.removeStep(nextStep);
        }
    }
}
 
Example #9
Source File: HBaseGraphStepStrategy.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final HBaseGraphStep<?, ?> hbaseGraphStep = new HBaseGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, hbaseGraphStep, traversal);
        Step<?, ?> currentStep = hbaseGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(hbaseGraphStep, hasContainer))
                        hbaseGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
Example #10
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static Condition convOr(HugeGraph graph,
                               HugeType type,
                               HasContainer has) {
    P<?> p = has.getPredicate();
    assert p instanceof OrP;
    @SuppressWarnings("unchecked")
    List<P<Object>> predicates = ((OrP<Object>) p).getPredicates();
    if (predicates.size() < 2) {
        throw newUnsupportedPredicate(p);
    }

    Condition cond = null;
    for (P<Object> predicate : predicates) {
        HasContainer newHas = new HasContainer(has.getKey(), predicate);
        Condition newCond = convHas2Condition(newHas, type, graph);
        if (cond == null) {
            cond = newCond;
        } else {
            cond = Condition.or(newCond, cond);
        }
    }
    return cond;
}
 
Example #11
Source File: BaseStrategy.java    From sqlg with MIT License 6 votes vote down vote up
private List<HasContainer> optimizeBetween(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
    List<HasContainer> result = new ArrayList<>();
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof AndP) {
            AndP<?> andP = (AndP) hasContainer.getPredicate();
            List<? extends P<?>> predicates = andP.getPredicates();
            if (predicates.size() == 2) {
                if (predicates.get(0).getBiPredicate() == Compare.gte && predicates.get(1).getBiPredicate() == Compare.lt) {
                    replacedStep.addHasContainer(hasContainer);
                    result.add(hasContainer);
                }
            }
        }
    }
    return result;
}
 
Example #12
Source File: HasStepFolder.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public static void foldInHasContainer(final HasStepFolder titanStep, final Traversal.Admin<?, ?> traversal) {

        Step<?, ?> currentStep = titanStep.getNextStep();
        while (true) {
            if (currentStep instanceof HasContainerHolder) {
                Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers();
                if (validTitanHas(containers)) {
                    titanStep.addAll(containers);
                    currentStep.getLabels().forEach(titanStep::addLabel);
                    traversal.removeStep(currentStep);
                }
            } else if (currentStep instanceof IdentityStep) {
                // do nothing, has no impact
            } else {
                break;
            }
            currentStep = currentStep.getNextStep();
        }
    }
 
Example #13
Source File: TinkerGraphStep.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private Iterator<? extends Edge> edges() {
    final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get();
    final HasContainer indexedContainer = getIndexKey(Edge.class);
    Iterator<Edge> iterator;
    // ids are present, filter on them first
    if (null == this.ids)
        iterator = Collections.emptyIterator();
    else if (this.ids.length > 0)
        iterator = this.iteratorList(graph.edges(this.ids));
    else
        iterator = null == indexedContainer ?
                this.iteratorList(graph.edges()) :
                TinkerHelper.queryEdgeIndex(graph, indexedContainer.getKey(), indexedContainer.getPredicate().getValue()).stream()
                            .filter(edge -> HasContainer.testAll(edge, this.hasContainers))
                            .collect(Collectors.<Edge>toList()).iterator();


    iterators.add(iterator);

    return iterator;
}
 
Example #14
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static void extractHasContainer(HugeGraphStep<?, ?> newStep,
                                       Traversal.Admin<?, ?> traversal) {
    Step<?, ?> step = newStep;
    do {
        step = step.getNextStep();
        if (step instanceof HasStep) {
            HasContainerHolder holder = (HasContainerHolder) step;
            for (HasContainer has : holder.getHasContainers()) {
                if (!GraphStep.processHasContainerIds(newStep, has)) {
                    newStep.addHasContainer(has);
                }
            }
            TraversalHelper.copyLabels(step, step.getPreviousStep(), false);
            traversal.removeStep(step);
        }
    } while (step instanceof HasStep || step instanceof NoOpBarrierStep);
}
 
Example #15
Source File: HBaseVertexStep.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
private Iterator<Edge> lookupEdges(final Traverser.Admin<Vertex> traverser, final List<HasContainer> hasContainers) {
    final HBaseGraph graph = (HBaseGraph) this.getTraversal().getGraph().get();
    if (getEdgeLabels().length == 1) {
        final String label = getEdgeLabels()[0];
        // find an edge by label and key/value
        for (final HasContainer hasContainer : hasContainers) {
            if (Compare.eq == hasContainer.getBiPredicate() && !hasContainer.getKey().equals(T.label.getAccessor())) {
                if (graph.hasIndex(OperationType.READ, ElementType.EDGE, label, hasContainer.getKey())) {
                    return IteratorUtils.stream(((HBaseVertex) traverser.get()).edges(getDirection(), label, hasContainer.getKey(), hasContainer.getValue()))
                            .filter(vertex -> HasContainer.testAll(vertex, hasContainers)).iterator();
                }
            }
        }
    }

    // linear scan
    return CloseableIteratorUtils.filter(traverser.get().edges(getDirection(), getEdgeLabels()),
            edge -> HasContainer.testAll(edge, hasContainers));
}
 
Example #16
Source File: JanusGraphStep.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private <A extends Element> Iterator<A> iteratorList(Iterator<A> iterator) {
    List<A> list = new ArrayList<>();
    while (iterator.hasNext()) {
        A e = iterator.next();
        if (HasContainer.testAll(e, this.getHasContainers())) {
            list.add(e);
        }
    }
    return list.iterator();
}
 
Example #17
Source File: TinkerGraphStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void addHasContainer(final HasContainer hasContainer) {
    if (hasContainer.getPredicate() instanceof AndP) {
        for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) {
            this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate));
        }
    } else
        this.hasContainers.add(hasContainer);
}
 
Example #18
Source File: BaseStrategy.java    From sqlg with MIT License 5 votes vote down vote up
private List<HasContainer> optimizeHas(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
    List<HasContainer> result = new ArrayList<>();
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainerKeyNotIdOrLabel(hasContainer) && SUPPORTED_BI_PREDICATE.contains(hasContainer.getBiPredicate())) {
            replacedStep.addHasContainer(hasContainer);
            result.add(hasContainer);
        }
    }
    return result;
}
 
Example #19
Source File: BitsyGraphStep.java    From bitsy with Apache License 2.0 5 votes vote down vote up
@Override
    public void addHasContainer(final HasContainer hasContainer) {
    if (hasContainer.getPredicate() instanceof AndP) {
        for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) {
            this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate));
        }
    } else
        this.hasContainers.add(hasContainer);
}
 
Example #20
Source File: JanusGraphPredicate.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
public static HasContainer convert(HasContainer container) {
    if (!(container.getPredicate() instanceof ConnectiveP)) {
        return container;
    }
    final ConnectiveJanusPredicate connectivePredicate = instanceConnectiveJanusPredicate(container.getPredicate());
    return new HasContainer(container.getKey(), new ConnectiveJanusGraphP(connectivePredicate, convert(((ConnectiveP<?>) container.getPredicate()), connectivePredicate)));
}
 
Example #21
Source File: JanusGraphVertexStep.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private <Q extends BaseVertexQuery> Q makeQuery(Q query) {
    query.labels(getEdgeLabels());
    query.direction(getDirection());
    for (HasContainer condition : hasContainers) {
        query.has(condition.getKey(), JanusGraphPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue());
    }
    for (OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (limit != BaseQuery.NO_LIMIT) query.limit(limit);
    ((BasicVertexCentricQueryBuilder) query).profiler(queryProfiler);
    return query;
}
 
Example #22
Source File: TinkerGraphStepStrategyTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
private static GraphTraversal.Admin<?, ?> g_V(final Object... hasKeyValues) {
    final GraphTraversal.Admin<?, ?> traversal = new DefaultGraphTraversal<>();
    final TinkerGraphStep<Vertex, Vertex> graphStep = new TinkerGraphStep<>(new GraphStep<>(traversal, Vertex.class, true));
    for (int i = 0; i < hasKeyValues.length; i = i + 2) {
        graphStep.addHasContainer(new HasContainer((String) hasKeyValues[i], (P) hasKeyValues[i + 1]));
    }
    return traversal.addStep(graphStep);
}
 
Example #23
Source File: TinkerGraphStepStrategyTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static GraphTraversal.Admin<?, ?> g_V(final Object... hasKeyValues) {
    final GraphTraversal.Admin<?, ?> traversal = new DefaultGraphTraversal<>();
    final TinkerGraphStep<Vertex, Vertex> graphStep = new TinkerGraphStep<>(new GraphStep<>(traversal, Vertex.class, true));
    for (int i = 0; i < hasKeyValues.length; i = i + 2) {
        graphStep.addHasContainer(new HasContainer((String) hasKeyValues[i], (P) hasKeyValues[i + 1]));
    }
    return traversal.addStep(graphStep);
}
 
Example #24
Source File: BaseStrategy.java    From sqlg with MIT License 5 votes vote down vote up
private List<HasContainer> optimizeArray(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
    List<HasContainer> result = new ArrayList<>();
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainerKeyNotIdOrLabel(hasContainer)
            && ( hasContainer.getBiPredicate() instanceof ArrayContains
                || hasContainer.getBiPredicate() instanceof ArrayOverlaps)) {
            replacedStep.addHasContainer(hasContainer);
            result.add(hasContainer);
        }
    }
    return result;
}
 
Example #25
Source File: BaseStrategy.java    From sqlg with MIT License 5 votes vote down vote up
private List<HasContainer> isForGuiSchema(ReplacedStep<?, ?> currentReplacedStep, List<HasContainer> hasContainers) {
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainer.getKey().equals(TopologyStrategy.TOPOLOGY_SELECTION_GLOBAL_UNIQUE_INDEX)) {
            currentReplacedStep.markForGuiSchema();
            return Collections.singletonList(hasContainer);
        }
    }
    return Collections.emptyList();
}
 
Example #26
Source File: GraphTraversal.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Filters vertices, edges and vertex properties based on their properties.
 *
 * @param accessor the {@link T} accessor of the property to filter on
 * @param value    the value to compare the accessor value to for equality
 * @return the traversal with an appended {@link HasStep}
 * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#has-step" target="_blank">Reference Documentation - Has Step</a>
 * @since 3.0.0-incubating
 */
public default GraphTraversal<S, E> has(final T accessor, final Object value) {
    if (value instanceof P)
        return this.has(accessor, (P) value);
    else if (value instanceof Traversal)
        return this.has(accessor, (Traversal) value);
    else {
        this.asAdmin().getBytecode().addStep(Symbols.has, accessor, value);
        return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(accessor.getAccessor(), P.eq(value)));
    }
}
 
Example #27
Source File: JanusGraphPropertiesStep.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private <Q extends BaseVertexQuery> Q makeQuery(Q query) {
    String[] keys = getPropertyKeys();
    query.keys(keys);
    for (HasContainer condition : hasContainers) {
        query.has(condition.getKey(), JanusGraphPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue());
    }
    for (OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (limit != BaseQuery.NO_LIMIT) query.limit(limit);
    ((BasicVertexCentricQueryBuilder) query).profiler(queryProfiler);
    return query;
}
 
Example #28
Source File: JanusGraphStep.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private GraphCentricQuery buildGlobalGraphCentricQuery(JanusGraphTransaction tx) {
    //If a query have a local offset or have a local order without a global order and if a query have a limit lower than the global different from other query we can not build globalquery
    Iterator<QueryInfo> itQueryInfo = hasLocalContainers.values().iterator();
    QueryInfo queryInfo = itQueryInfo.next();
    if (queryInfo.getLowLimit() > 0 || orders.isEmpty() && !queryInfo.getOrders().isEmpty()) {
        return null;
    }
    Integer limit = queryInfo.getHighLimit();
    while (itQueryInfo.hasNext()) {
        queryInfo = itQueryInfo.next();
        if (queryInfo.getLowLimit() > 0 || (orders.isEmpty() && !queryInfo.getOrders().isEmpty()) || (queryInfo.getHighLimit() < highLimit && !limit.equals(queryInfo.getHighLimit()))) {
            return null;
        }
    }
    JanusGraphQuery query = tx.query();
    for (List<HasContainer> localContainers : hasLocalContainers.keySet()) {
        JanusGraphQuery localQuery = tx.query();
        addConstraint(localQuery, localContainers);
        query.or(localQuery);
    }
    for (OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (highLimit != BaseQuery.NO_LIMIT || limit != BaseQuery.NO_LIMIT) query.limit(Math.min(limit, highLimit));
    Preconditions.checkArgument(query instanceof GraphCentricQueryBuilder);
    GraphCentricQueryBuilder centricQueryBuilder = ((GraphCentricQueryBuilder) query);
    centricQueryBuilder.profiler(queryProfiler);
    GraphCentricQuery graphCentricQuery = centricQueryBuilder.constructQuery(Vertex.class.isAssignableFrom(this.returnClass) ? ElementCategory.VERTEX : ElementCategory.EDGE);
    return graphCentricQuery;
}
 
Example #29
Source File: HasStepFolder.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
static List<HasContainer> splitAndP(List<HasContainer> hasContainers, Iterable<HasContainer> has) {
    has.forEach(hasContainer -> {
        if (hasContainer.getPredicate() instanceof AndP) {
            for (P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) {
                hasContainers.add(new HasContainer(hasContainer.getKey(), predicate));
            }
        } else {
            hasContainers.add(hasContainer);
        }
    });
    return hasContainers;
}
 
Example #30
Source File: SchemaTableTree.java    From sqlg with MIT License 5 votes vote down vote up
/**
 * remove "has" containers that are not valid anymore
 * transform "has" containers that are equivalent to simpler statements.
 *
 * @param schemaTableTree the current table tree
 */
private void removeOrTransformHasContainers(final SchemaTableTree schemaTableTree) {
    Set<HasContainer> toRemove = new HashSet<>();
    Set<HasContainer> toAdd = new HashSet<>();
    for (HasContainer hasContainer : schemaTableTree.hasContainers) {
        if (hasContainer.getKey().equals(label.getAccessor())) {
            toRemove.add(hasContainer);
        }

        if (Existence.NULL.equals(hasContainer.getBiPredicate())) {
            // we checked that a non existing property was null, that's fine
            if (!this.getFilteredAllTables().get(schemaTableTree.getSchemaTable().toString()).containsKey(hasContainer.getKey())) {
                toRemove.add(hasContainer);
            }
        }
        if (Contains.without.equals(hasContainer.getBiPredicate())) {
            Object o = hasContainer.getValue();
            if (o instanceof Collection && ((Collection<?>) o).size() == 0) {
                //P.without(Collections.emptySet()) translates to the sql IS NOT NULL
                toRemove.add(hasContainer);
                toAdd.add(new HasContainer(hasContainer.getKey(), new P<>(Existence.NOTNULL, null)));
            }
        }
    }
    schemaTableTree.hasContainers.removeAll(toRemove);
    schemaTableTree.hasContainers.addAll(toAdd);
}