static List<HasContainer> splitAndP(final List<HasContainer> hasContainers, final Iterable<HasContainer> has) { has.forEach(hasContainer -> { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { hasContainers.add(new HasContainer(hasContainer.getKey(), predicate)); } } else hasContainers.add(hasContainer); }); return hasContainers; }
static boolean validJanusGraphHas(HasContainer has) { if (has.getPredicate() instanceof ConnectiveP) { final List<? extends P<?>> predicates = ((ConnectiveP<?>) has.getPredicate()).getPredicates(); return predicates.stream().allMatch(p-> validJanusGraphHas(new HasContainer(has.getKey(), p))); } else { return JanusGraphPredicate.Converter.supports(has.getBiPredicate()); } }
private void addConstraint(final JanusGraphQuery query, final List<HasContainer> localContainers) { for (final HasContainer condition : hasContainers) { query.has(condition.getKey(), JanusGraphPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue()); } for (final HasContainer condition : localContainers) { query.has(condition.getKey(), JanusGraphPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue()); } }
public TitanGraphStep(final GraphStep<E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.getIds()); originalStep.getLabels().forEach(this::addLabel); this.setIteratorSupplier(() -> { TitanTransaction tx = TitanTraversalUtil.getTx(traversal); TitanGraphQuery query = tx.query(); for (HasContainer condition : hasContainers) { query.has(condition.getKey(), TitanPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue()); } for (OrderEntry order : orders) query.orderBy(order.key, order.order); if (limit != BaseQuery.NO_LIMIT) query.limit(limit); ((GraphCentricQueryBuilder) query).profiler(queryProfiler); return Vertex.class.isAssignableFrom(this.returnClass) ? query.vertices().iterator() : query.edges().iterator(); }); }
private <Q extends BaseVertexQuery> Q makeQuery(Q query) { String[] keys = getPropertyKeys(); query.keys(keys); for (HasContainer condition : hasContainers) { query.has(condition.getKey(), TitanPredicate.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; }
public static HasContainer convert(final 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))); }
private <Q extends BaseVertexQuery> Q makeQuery(Q query) { final String[] keys = getPropertyKeys(); query.keys(keys); for (final HasContainer condition : hasContainers) { query.has(condition.getKey(), JanusGraphPredicate.Converter.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; }
public <Q extends BaseVertexQuery> Q makeQuery(Q query) { query.labels(getEdgeLabels()); query.direction(getDirection()); for (HasContainer condition : hasContainers) { query.has(condition.getKey(), TitanPredicate.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; }
public <Q extends BaseVertexQuery> Q makeQuery(Q query) { query.labels(getEdgeLabels()); query.direction(getDirection()); for (final HasContainer condition : hasContainers) { query.has(condition.getKey(), JanusGraphPredicate.Converter.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; }
public static void retriveSysprop(List<HasContainer> hasContainers, Function<HasContainer, Boolean> func) { for (Iterator<HasContainer> itor = hasContainers.iterator(); itor.hasNext();) { HasContainer container = itor.next(); if (container.getKey().startsWith("~") && func.apply(container)) { itor.remove(); } } }
@Override public void addHasContainer(final HasContainer has) { if (SYSPROP_PAGE.equals(has.getKey())) { this.setPage((String) has.getValue()); return; } this.hasContainers.add(has); }
@Override public void addHasContainer(final HasContainer has) { if (SYSPROP_PAGE.equals(has.getKey())) { this.setPage((String) has.getValue()); return; } this.hasContainers.add(has); }
private HasContainer getIndexKey(final Class<? extends Element> indexedClass) { final Set<String> indexedKeys = ((TinkerGraph) this.getTraversal().getGraph().get()).getIndexedKeys(indexedClass); final Iterator<HasContainer> itty = IteratorUtils.filter(hasContainers.iterator(), c -> c.getPredicate().getBiPredicate() == Compare.eq && indexedKeys.contains(c.getKey())); return itty.hasNext() ? itty.next() : null; }
private static void convPredicateValue(HugeGraph graph, HasContainer has) { // No need to convert if key is sysprop if (isSysProp(has.getKey())) { return; } PropertyKey pkey = graph.propertyKey(has.getKey()); List<P<Object>> leafPredicates = new ArrayList<>(); collectPredicates(leafPredicates, ImmutableList.of(has.getPredicate())); for (P<Object> predicate : leafPredicates) { Object value = validPredicateValue(predicate.getValue(), pkey); predicate.setValue(value); } }
@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); }
@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); }
private Iterator<? extends Edge> edges() { final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get(); final HasContainer indexedContainer = getIndexKey(Edge.class); // 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 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(); }
private Iterator<? extends Vertex> vertices() { final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get(); final HasContainer indexedContainer = getIndexKey(Vertex.class); // 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 return null == indexedContainer ? this.iteratorList(graph.vertices()) : IteratorUtils.filter(TinkerHelper.queryVertexIndex(graph, indexedContainer.getKey(), indexedContainer.getPredicate().getValue()).iterator(), vertex -> HasContainer.testAll(vertex, this.hasContainers)); }
private static Relation convCompare2Relation(HugeGraph graph, HugeType type, HasContainer has) { assert type.isGraph(); BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; boolean isSyspropKey = true; try { string2HugeKey(has.getKey()); } catch (IllegalArgumentException ignored) { isSyspropKey = false; } return isSyspropKey ? convCompare2SyspropRelation(graph, type, has) : convCompare2UserpropRelation(graph, type, has); }
private static Condition convRelationType2Relation(HugeGraph graph, HugeType type, HasContainer has) { assert type.isGraph(); BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof RelationType; String key = has.getKey(); PropertyKey pkey = graph.propertyKey(key); Id pkeyId = pkey.id(); Object value = validPredicateValue(has.getValue(), pkey); return new Condition.UserpropRelation(pkeyId, (RelationType) bp, value); }