public static boolean validTitanHas(HasContainer has) { return TitanPredicate.Converter.supports(has.getBiPredicate()); }
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; }
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; }
/** * 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 -> Compare.eq == hasContainer.getBiPredicate()) .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()))
.filter(hasContainer -> Compare.eq == hasContainer.getBiPredicate()) .map(hasContainer -> (String) hasContainer.getValue()) .findAny(); if (Compare.eq == hasContainer.getBiPredicate()) { if (graph.getBaseGraph().hasSchemaIndex(label.get(), hasContainer.getKey())) { return Stream.concat(
for (final HasContainer hasContainer : new ArrayList<>(step.getHasContainers())) { 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)) {
private List<HasContainer> optimizeTextContains(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) { List<HasContainer> result = new ArrayList<>(); for (HasContainer hasContainer : hasContainers) { if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getBiPredicate() instanceof Text || hasContainer.getBiPredicate() instanceof FullText ) { replacedStep.addHasContainer(hasContainer); result.add(hasContainer); } } return result; }
private List<HasContainer> optimizeTextContains(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) { List<HasContainer> result = new ArrayList<>(); for (HasContainer hasContainer : hasContainers) { if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getBiPredicate() instanceof Text || hasContainer.getBiPredicate() instanceof FullText ) { replacedStep.addHasContainer(hasContainer); result.add(hasContainer); } } return result; }
private List<HasContainer> optimizeWithInOut(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) { List<HasContainer> result = new ArrayList<>(); for (HasContainer hasContainer : hasContainers) { if (hasContainerKeyNotIdOrLabel(hasContainer) && (hasContainer.getBiPredicate() == Contains.without || hasContainer.getBiPredicate() == Contains.within)) { replacedStep.addHasContainer(hasContainer); result.add(hasContainer); } } return result; }
/** * @param hasContainer A hasContainers with {@link T#label} as key for this step. Copied from the original step. */ public void addLabelHasContainer(HasContainer hasContainer) { Preconditions.checkState(hasContainer.getKey().equals(T.label.getAccessor()), "ReplacedStep.addLabelHasContainer may only be called for HasContainers with T.label as key."); Preconditions.checkState(BaseStrategy.SUPPORTED_LABEL_BI_PREDICATE.contains(hasContainer.getBiPredicate())); this.labelHasContainers.add(hasContainer); }
private List<HasContainer> optimizeLabelHas(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) { List<HasContainer> result = new ArrayList<>(); for (HasContainer hasContainer : hasContainers) { if (hasContainer.getKey().equals(T.label.getAccessor()) && SUPPORTED_LABEL_BI_PREDICATE.contains(hasContainer.getBiPredicate())) { replacedStep.addLabelHasContainer(hasContainer); result.add(hasContainer); } } return result; }
protected boolean isLabelFilter(HasContainer f) { boolean labelFilter = f.getKey().equals("~label"); BiPredicate<?, ?> predicate = f.getBiPredicate(); if (predicate instanceof Compare) { return labelFilter && Compare.eq.equals(predicate); } if (predicate instanceof Contains) { return labelFilter && Contains.within.equals(predicate); } return false; }
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 <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; }