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;
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.
the class AndOrHasContainer method setParameterOnStatement.
public void setParameterOnStatement(Multimap<String, Object> keyValueMap) {
for (HasContainer hasContainer : this.hasContainers) {
WhereClause whereClause = WhereClause.from(hasContainer.getPredicate());
whereClause.putKeyValueMap(hasContainer, keyValueMap);
}
for (AndOrHasContainer andOrHasContainer : this.andOrHasContainers) {
andOrHasContainer.setParameterOnStatement(keyValueMap);
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.
the class ReplacedStep method groupIdsBySchemaTable.
/**
* Groups the idHasContainers by SchemaTable.
* Each SchemaTable has a list representing the idHasContainers with the relevant BiPredicate and RecordId
*
* @return
*/
private Map<SchemaTable, List<Multimap<BiPredicate, RecordId>>> groupIdsBySchemaTable() {
Map<SchemaTable, List<Multimap<BiPredicate, RecordId>>> result = new HashMap<>();
for (HasContainer idHasContainer : this.idHasContainers) {
Map<SchemaTable, Boolean> newHasContainerMap = new HashMap<>();
P<Object> idPredicate = (P<Object>) idHasContainer.getPredicate();
BiPredicate biPredicate = idHasContainer.getBiPredicate();
// This is statement is for g.V().hasId(Collection) where the logic is actually P.within not P.eq
if (biPredicate == Compare.eq && idPredicate.getValue() instanceof Collection && ((Collection) idPredicate.getValue()).size() > 1) {
biPredicate = Contains.within;
}
Multimap<BiPredicate, RecordId> biPredicateRecordIdMultimap;
if (idPredicate.getValue() instanceof Collection) {
Collection<Object> ids = (Collection<Object>) idPredicate.getValue();
for (Object id : ids) {
RecordId recordId = RecordId.from(id);
List<Multimap<BiPredicate, RecordId>> biPredicateRecordIdList = result.get(recordId.getSchemaTable());
Boolean newHasContainer = newHasContainerMap.get(recordId.getSchemaTable());
if (biPredicateRecordIdList == null) {
biPredicateRecordIdList = new ArrayList<>();
biPredicateRecordIdMultimap = LinkedListMultimap.create();
biPredicateRecordIdList.add(biPredicateRecordIdMultimap);
result.put(recordId.getSchemaTable(), biPredicateRecordIdList);
newHasContainerMap.put(recordId.getSchemaTable(), false);
} else if (newHasContainer == null) {
biPredicateRecordIdMultimap = LinkedListMultimap.create();
biPredicateRecordIdList.add(biPredicateRecordIdMultimap);
newHasContainerMap.put(recordId.getSchemaTable(), false);
}
biPredicateRecordIdMultimap = biPredicateRecordIdList.get(biPredicateRecordIdList.size() - 1);
biPredicateRecordIdMultimap.put(biPredicate, recordId);
}
} else {
Object id = idPredicate.getValue();
RecordId recordId = RecordId.from(id);
List<Multimap<BiPredicate, RecordId>> biPredicateRecordIdList = result.computeIfAbsent(recordId.getSchemaTable(), k -> new ArrayList<>());
biPredicateRecordIdMultimap = LinkedListMultimap.create();
biPredicateRecordIdList.add(biPredicateRecordIdMultimap);
biPredicateRecordIdMultimap.put(biPredicate, recordId);
}
}
return result;
}
Aggregations