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; }
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; }
@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); }
/** * Helper method for providers that want to "fold in" {@link HasContainer}'s based on id checking into the ids of the {@link GraphStep}. * * @param graphStep the GraphStep to potentially {@link GraphStep#addIds(Object...)}. * @param hasContainer The {@link HasContainer} to check for id validation. * @return true if the {@link HasContainer} updated ids and thus, was processed. */ public static boolean processHasContainerIds(final GraphStep<?, ?> graphStep, final HasContainer hasContainer) { if (hasContainer.getKey().equals(T.id.getAccessor()) && graphStep.ids.length == 0 && (hasContainer.getBiPredicate() == Compare.eq || hasContainer.getBiPredicate() == Contains.within)) { graphStep.addIds(hasContainer.getValue()); return true; } return false; } }
.filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor())) .filter(hasContainer -> Compare.eq == hasContainer.getBiPredicate()) .map(hasContainer -> (String) hasContainer.getValue()) .findAny(); if (!label.isPresent()) .filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor())) .filter(hasContainer -> hasContainer.getPredicate() instanceof LabelP) .map(hasContainer -> (String) hasContainer.getValue()) .findAny(); if (Compare.eq == hasContainer.getBiPredicate() && !hasContainer.getKey().equals(T.label.getAccessor())) { if (graph.getBaseGraph().hasSchemaIndex(label.get(), hasContainer.getKey())) { return IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get(), hasContainer.getKey(), hasContainer.getValue())) .map(node -> (Vertex) new Neo4jVertex(node, graph)) .filter(vertex -> HasContainer.testAll(vertex, hasContainers)).iterator();
.filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor())) .filter(hasContainer -> Compare.eq == hasContainer.getBiPredicate()) .map(hasContainer -> (String) hasContainer.getValue()) .findAny(); if (!label.isPresent()) .filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor())) .filter(hasContainer -> hasContainer.getPredicate() instanceof LabelP) .map(hasContainer -> (String) hasContainer.getValue()) .findAny(); if (graph.getBaseGraph().hasSchemaIndex(label.get(), hasContainer.getKey())) { return Stream.concat( IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get(), hasContainer.getKey(), hasContainer.getValue())) .filter(getNodePredicate()) .map(node -> (Vertex) new Neo4jVertex(node, graph)) .filter(vertex -> HasContainer.testAll(vertex, hasContainers)), IteratorUtils.stream(graph.getBaseGraph().findNodes(VERTEX_PROPERTY_LABEL, hasContainer.getKey(), hasContainer.getValue())) // look up indexed vertex property nodes .map(node -> node.relationships(Neo4jDirection.INCOMING).iterator().next().start()) .map(node -> (Vertex) new Neo4jVertex(node, graph))
if (hasContainer.getKey().equals(T.label.getAccessor())) { if (hasContainer.getBiPredicate() == Compare.eq && hasContainer.getValue() instanceof String && edgeLabels.isEmpty()) { edgeLabels.add((String) hasContainer.getValue()); step.removeHasContainer(hasContainer); } else if (hasContainer.getBiPredicate() == Contains.within && hasContainer.getValue() instanceof Collection && ((Collection) hasContainer.getValue()).containsAll(edgeLabels)) { edgeLabels.addAll((Collection<String>) hasContainer.getValue()); step.removeHasContainer(hasContainer); } else if (hasContainer.getPredicate() instanceof OrP && edgeLabels.isEmpty()) {
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); }
BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Contains; List<?> values = (List<?>) has.getValue();
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 = string2HugeKey(has.getKey()); 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.contains(key, value); } }
protected List<String> extractLabels(HasContainer f) { Object value = f.getValue(); List<String> classLabels = new ArrayList<>(); if (value instanceof List) { ((List) value).forEach(label -> classLabels.add((String) label)); } else { classLabels.add((String) value); } return classLabels; }
private static Relation convCompare2SyspropRelation(HugeGraph graph, HugeType type, HasContainer has) { BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; HugeKeys key = string2HugeKey(has.getKey()); Object value = convSysValueIfNeeded(graph, type, key, has.getValue()); switch ((Compare) bp) { case eq: return Condition.eq(key, value); case gt: return Condition.gt(key, value); case gte: return Condition.gte(key, value); case lt: return Condition.lt(key, value); case lte: return Condition.lte(key, value); case neq: return Condition.neq(key, value); } throw newUnsupportedPredicate(has.getPredicate()); }
private static Relation convCompare2UserpropRelation(HugeGraph graph, HugeType type, HasContainer has) { BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; String key = has.getKey(); PropertyKey pkey = graph.propertyKey(key); Id pkeyId = pkey.id(); Object value = validPredicateValue(has.getValue(), pkey); switch ((Compare) bp) { case eq: return Condition.eq(pkeyId, value); case gt: return Condition.gt(pkeyId, value); case gte: return Condition.gte(pkeyId, value); case lt: return Condition.lt(pkeyId, value); case lte: return Condition.lte(pkeyId, value); case neq: return Condition.neq(pkeyId, value); } throw newUnsupportedPredicate(has.getPredicate()); }
/** * gets the requested values from the Has step. If it's a single value, wrap it in an array, otherwise return the array */ private Iterator<Object> getValueIterator(HasContainer c) { return c.getPredicate().getBiPredicate() == Contains.within ? ((Iterable<Object>) c.getValue()).iterator() : IteratorUtils.of(c.getValue()); }
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); }