use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.
the class BaseStrategy method optimizeLabelHas.
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;
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.
the class BaseStrategy method handleHasSteps.
protected void handleHasSteps(ListIterator<Step<?, ?>> iterator, int pathCount) {
// Collect the hasSteps
int countToGoPrevious = 0;
while (iterator.hasNext()) {
Step<?, ?> currentStep = iterator.next();
countToGoPrevious++;
String notNullKey;
String nullKey;
if (currentStep instanceof HasContainerHolder) {
HasContainerHolder hasContainerHolder = (HasContainerHolder) currentStep;
List<HasContainer> hasContainers = hasContainerHolder.getHasContainers();
List<HasContainer> toRemoveHasContainers = new ArrayList<>();
if (isNotWithMultipleColumnValue(hasContainerHolder)) {
toRemoveHasContainers.addAll(optimizeLabelHas(this.currentReplacedStep, hasContainers));
// important to do optimizeIdHas after optimizeLabelHas as it might add its labels to the previous labelHasContainers labels.
// i.e. for neq and without 'or' logic
toRemoveHasContainers.addAll(optimizeIdHas(this.currentReplacedStep, hasContainers));
toRemoveHasContainers.addAll(optimizeHas(this.currentReplacedStep, hasContainers));
toRemoveHasContainers.addAll(optimizeWithInOut(this.currentReplacedStep, hasContainers));
toRemoveHasContainers.addAll(optimizeBetween(this.currentReplacedStep, hasContainers));
toRemoveHasContainers.addAll(optimizeInside(this.currentReplacedStep, hasContainers));
toRemoveHasContainers.addAll(optimizeOutside(this.currentReplacedStep, hasContainers));
toRemoveHasContainers.addAll(optimizeTextContains(this.currentReplacedStep, hasContainers));
if (toRemoveHasContainers.size() == hasContainers.size()) {
if (!currentStep.getLabels().isEmpty()) {
final IdentityStep identityStep = new IdentityStep<>(this.traversal);
currentStep.getLabels().forEach(label -> this.currentReplacedStep.addLabel(pathCount + BaseStrategy.PATH_LABEL_SUFFIX + label));
TraversalHelper.insertAfterStep(identityStep, currentStep, this.traversal);
}
if (this.traversal.getSteps().contains(currentStep)) {
this.traversal.removeStep(currentStep);
}
iterator.remove();
countToGoPrevious--;
}
}
} else if ((notNullKey = isNotNullStep(currentStep)) != null) {
this.currentReplacedStep.addHasContainer(new HasContainer(notNullKey, new P<>(Existence.NOTNULL, null)));
if (!currentStep.getLabels().isEmpty()) {
final IdentityStep identityStep = new IdentityStep<>(this.traversal);
currentStep.getLabels().forEach(label -> this.currentReplacedStep.addLabel(pathCount + BaseStrategy.PATH_LABEL_SUFFIX + label));
TraversalHelper.insertAfterStep(identityStep, currentStep, this.traversal);
}
if (this.traversal.getSteps().contains(currentStep)) {
this.traversal.removeStep(currentStep);
}
iterator.remove();
countToGoPrevious--;
} else if ((nullKey = isNullStep(currentStep)) != null) {
this.currentReplacedStep.addHasContainer(new HasContainer(nullKey, new P<>(Existence.NULL, null)));
if (!currentStep.getLabels().isEmpty()) {
final IdentityStep identityStep = new IdentityStep<>(this.traversal);
currentStep.getLabels().forEach(label -> this.currentReplacedStep.addLabel(pathCount + BaseStrategy.PATH_LABEL_SUFFIX + label));
TraversalHelper.insertAfterStep(identityStep, currentStep, this.traversal);
}
if (this.traversal.getSteps().contains(currentStep)) {
this.traversal.removeStep(currentStep);
}
iterator.remove();
countToGoPrevious--;
} else if (currentStep instanceof IdentityStep) {
// do nothing
} else {
for (int i = 0; i < countToGoPrevious; i++) {
iterator.previous();
}
break;
}
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.
the class BaseStrategy method optimizeOutside.
private List<HasContainer> optimizeOutside(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
List<HasContainer> result = new ArrayList<>();
for (HasContainer hasContainer : hasContainers) {
if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof OrP) {
OrP<?> orP = (OrP) hasContainer.getPredicate();
List<? extends P<?>> predicates = orP.getPredicates();
if (predicates.size() == 2) {
if (predicates.get(0).getBiPredicate() == Compare.lt && predicates.get(1).getBiPredicate() == Compare.gt) {
replacedStep.addHasContainer(hasContainer);
result.add(hasContainer);
}
}
}
}
return result;
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.
the class BaseStrategy method optimizeBetween.
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;
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.
the class BaseStrategy method optimizeIdHas.
private List<HasContainer> optimizeIdHas(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
List<HasContainer> result = new ArrayList<>();
for (HasContainer hasContainer : hasContainers) {
if (hasContainer.getKey().equals(T.id.getAccessor()) && SUPPORTED_ID_BI_PREDICATE.contains(hasContainer.getBiPredicate())) {
replacedStep.addIdHasContainer(hasContainer);
result.add(hasContainer);
}
}
return result;
}
Aggregations