Search in sources :

Example 41 with HasContainer

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;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP)

Example 42 with HasContainer

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;
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer)

Example 43 with HasContainer

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;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer)

Example 44 with HasContainer

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);
    }
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Example 45 with HasContainer

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;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) P(org.apache.tinkerpop.gremlin.process.traversal.P) Multimap(com.google.common.collect.Multimap) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) BiPredicate(java.util.function.BiPredicate)

Aggregations

HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)56 AndOrHasContainer (org.umlg.sqlg.sql.parse.AndOrHasContainer)13 P (org.apache.tinkerpop.gremlin.process.traversal.P)9 Collectors (java.util.stream.Collectors)7 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)6 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)6 FullText (org.umlg.sqlg.predicate.FullText)6 PredicatesHolder (org.unipop.query.predicates.PredicatesHolder)6 java.util (java.util)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 BiPredicate (java.util.function.BiPredicate)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)5 JSONObject (org.json.JSONObject)5 GraphStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep)4 BasicVertexCentricQueryBuilder (org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder)4 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)3 HasContainerHolder (org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder)3 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)3 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)3