public TitanPropertiesStep(PropertiesStep<E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnType(), originalStep.getPropertyKeys()); originalStep.getLabels().forEach(this::addLabel); this.hasContainers = new ArrayList<>(); this.limit = Query.NO_LIMIT; }
@Override public TitanPropertiesStep<E> clone() { final TitanPropertiesStep<E> clone = (TitanPropertiesStep<E>) super.clone(); clone.initialized = false; return clone; }
@Override protected Traverser<E> processNextStart() { if (!initialized) initialize(); return super.processNextStart(); }
private Optional<String> propertyFromPropertiesStep(PropertiesStep<Vertex> propertiesStep) { String[] propertyKeys = propertiesStep.getPropertyKeys(); if (propertyKeys.length != 1) return Optional.empty(); return Optional.of(propertyKeys[0]); }
if ('p' != propertyType) { final Traversal.Admin<?, ?> temp = new DefaultTraversal<>(); temp.addStep(new PropertiesStep<>(temp, PropertyType.PROPERTY, ((PropertyMapStep) step).getPropertyKeys())); if ('v' == propertyType) TraversalHelper.insertTraversal(0, nonCheckPropertyCriterion.clone(), temp); if ('p' != propertyType) { final Traversal.Admin<?, ?> temp = new DefaultTraversal<>(); temp.addStep(new PropertiesStep<>(temp, PropertyType.PROPERTY, ((ElementValueTraversal) t).getPropertyKey())); if ('v' == propertyType) TraversalHelper.insertTraversal(0, nonCheckPropertyCriterion.clone(), temp); final char propertyType = processesPropertyType(step.getPreviousStep()); if ('p' != propertyType) { if (PropertyType.PROPERTY == ((PropertiesStep) step).getReturnType()) { final Step propertiesStep = new PropertiesStep(traversal, PropertyType.PROPERTY, ((PropertiesStep) step).getPropertyKeys()); TraversalHelper.replaceStep(step, propertiesStep, traversal); final Step propertyValueStep = new PropertyValueStep(traversal);
propertiesSteps.forEach(step -> { if (step.getPropertyKeys().length > 0 && ElementHelper.keyExists(partitionKey, step.getPropertyKeys())) throw new IllegalStateException("Cannot explicitly request the partitionKey in the traversal"); if (step.getReturnType() == PropertyType.PROPERTY) { final Step next = step.getNextStep(); if (!(next instanceof HasStep) || !((HasContainer) ((HasStep) next).getHasContainers().get(0)).getKey().equals(partitionKey)) { TraversalHelper.insertTraversal(step, choose.asAdmin(), traversal); } else if (step.getReturnType() == PropertyType.VALUE) { __.properties(step.getPropertyKeys()).has(partitionKey, P.within(new ArrayList<>(readPartitions))).filter(new PartitionKeyHider()).value(), __.__().filter(new PartitionKeyHider())); TraversalHelper.insertTraversal(step, choose.asAdmin(), traversal); } else { throw new IllegalStateException(String.format("%s is not accounting for a particular %s %s", PartitionStrategy.class.getSimpleName(), PropertyType.class.toString(), step.getReturnType()));
/** * Optimizes the given step if possible. Basically this method converts <code>.out()</code> to <code>.outE()</code> * and <code>.values()</code> to <code>.properties()</code>. * * @param traversal the traversal that holds the given step * @param step the step to replace */ private static void optimizeStep(final Traversal.Admin traversal, final Step step) { final Step newStep; if (step instanceof VertexStep) { final VertexStep vs = (VertexStep) step; newStep = new VertexStep<>(traversal, Edge.class, vs.getDirection(), vs.getEdgeLabels()); } else if (step instanceof PropertiesStep) { final PropertiesStep ps = (PropertiesStep) step; newStep = new PropertiesStep(traversal, PropertyType.PROPERTY, ps.getPropertyKeys()); } else { return; } TraversalHelper.replaceStep(step, newStep, traversal); }
/** * Checks whether a given step is optimizable or not. * * @param step the step to check * @return <code>true</code> if the step is optimizable, otherwise <code>false</code> */ private static boolean isOptimizable(final Step step) { return ((step instanceof VertexStep && ((VertexStep) step).returnsVertex()) || (step instanceof PropertiesStep && PropertyType.VALUE.equals(((PropertiesStep) step).getReturnType()))) && (step.getTraversal().getEndStep().getLabels().isEmpty() || step.getNextStep() instanceof CountGlobalStep); }
@Override public void reset() { super.reset(); this.initialized = false; }
@Override public String toString() { return this.hasContainers.isEmpty() ? super.toString() : StringFactory.stepString(this, this.hasContainers); }
private Collection<String> getRestrictedProperties(Step<?, ?> step) { Collection<String> ret = null; if (step instanceof PropertiesStep<?>) { PropertiesStep<?> ps = (PropertiesStep<?>) step; ret = Arrays.asList(ps.getPropertyKeys()); } else if (step instanceof PropertyMapStep<?, ?>) { PropertyMapStep<?, ?> pms = (PropertyMapStep<?, ?>) step; ret = Arrays.asList(pms.getPropertyKeys()); } // if no property keys are provided, all properties should be returned if (ret != null && ret.isEmpty()) { ret = null; } return ret; }
if ('p' != propertyType) { final Traversal.Admin<?, ?> temp = new DefaultTraversal<>(); temp.addStep(new PropertiesStep<>(temp, PropertyType.PROPERTY, ((PropertyMapStep) step).getPropertyKeys())); if ('v' == propertyType) TraversalHelper.insertTraversal(0, nonCheckPropertyCriterion.clone(), temp); if ('p' != propertyType) { final Traversal.Admin<?, ?> temp = new DefaultTraversal<>(); temp.addStep(new PropertiesStep<>(temp, PropertyType.PROPERTY, ((ElementValueTraversal) t).getPropertyKey())); if ('v' == propertyType) TraversalHelper.insertTraversal(0, nonCheckPropertyCriterion.clone(), temp); final char propertyType = processesPropertyType(step.getPreviousStep()); if ('p' != propertyType) { if (PropertyType.PROPERTY == ((PropertiesStep) step).getReturnType()) { final Step propertiesStep = new PropertiesStep(traversal, PropertyType.PROPERTY, ((PropertiesStep) step).getPropertyKeys()); TraversalHelper.replaceStep(step, propertiesStep, traversal); final Step propertyValueStep = new PropertyValueStep(traversal);
propertiesSteps.forEach(step -> { if (step.getPropertyKeys().length > 0 && ElementHelper.keyExists(partitionKey, step.getPropertyKeys())) throw new IllegalStateException("Cannot explicitly request the partitionKey in the traversal"); if (step.getReturnType() == PropertyType.PROPERTY) { final Step next = step.getNextStep(); if (!(next instanceof HasStep) || !((HasContainer) ((HasStep) next).getHasContainers().get(0)).getKey().equals(partitionKey)) { TraversalHelper.insertTraversal(step, choose.asAdmin(), traversal); } else if (step.getReturnType() == PropertyType.VALUE) { __.properties(step.getPropertyKeys()).has(partitionKey, P.within(new ArrayList<>(readPartitions))).filter(new PartitionKeyHider()).value(), __.__().filter(new PartitionKeyHider())); TraversalHelper.insertTraversal(step, choose.asAdmin(), traversal); } else { throw new IllegalStateException(String.format("%s is not accounting for a particular %s %s", PartitionStrategy.class.getSimpleName(), PropertyType.class.toString(), step.getReturnType()));
/** * Optimizes the given step if possible. Basically this method converts <code>.out()</code> to <code>.outE()</code> * and <code>.values()</code> to <code>.properties()</code>. * * @param traversal the traversal that holds the given step * @param step the step to replace */ private static void optimizeStep(final Traversal.Admin traversal, final Step step) { final Step newStep; if (step instanceof VertexStep) { final VertexStep vs = (VertexStep) step; newStep = new VertexStep<>(traversal, Edge.class, vs.getDirection(), vs.getEdgeLabels()); } else if (step instanceof PropertiesStep) { final PropertiesStep ps = (PropertiesStep) step; newStep = new PropertiesStep(traversal, PropertyType.PROPERTY, ps.getPropertyKeys()); } else { return; } TraversalHelper.replaceStep(step, newStep, traversal); }
/** * Checks whether a given step is optimizable or not. * * @param step the step to check * @return <code>true</code> if the step is optimizable, otherwise <code>false</code> */ private static boolean isOptimizable(final Step step) { return ((step instanceof VertexStep && ((VertexStep) step).returnsVertex()) || (step instanceof PropertiesStep && PropertyType.VALUE.equals(((PropertiesStep) step).getReturnType()))) && (step.getTraversal().getEndStep().getLabels().isEmpty() || step.getNextStep() instanceof CountGlobalStep); }
@Override public void reset() { super.reset(); this.initialized = false; }
@Override public String toString() { return this.hasContainers.isEmpty() ? super.toString() : StringFactory.stepString(this, this.hasContainers); }
public JanusGraphPropertiesStep(PropertiesStep<E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnType(), originalStep.getPropertyKeys()); originalStep.getLabels().forEach(this::addLabel); this.hasContainers = new ArrayList<>(); this.limit = Query.NO_LIMIT; }
private Collection<String> getRestrictedProperties(Step<?, ?> step) { Collection<String> ret = null; if (step instanceof PropertiesStep<?>) { PropertiesStep<?> ps = (PropertiesStep<?>) step; ret = Arrays.asList(ps.getPropertyKeys()); } else if (step instanceof PropertyMapStep<?, ?>) { PropertyMapStep<?, ?> pms = (PropertyMapStep<?, ?>) step; ret = Arrays.asList(pms.getPropertyKeys()); } // if no property keys are provided, all properties should be returned if (ret != null && ret.isEmpty()) { ret = null; } return ret; }
@Override protected Traverser.Admin<E> processNextStart() { if (!initialized) initialize(); return super.processNextStart(); }