Search in sources :

Example 16 with PredicatesHolder

use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.

the class DocEdgeSchema method getVertexPredicates.

protected PredicatesHolder getVertexPredicates(List<Vertex> vertices, Direction direction) {
    PredicatesHolder outPredicates = this.outVertexSchema.toPredicates(vertices);
    PredicatesHolder inPredicates = this.inVertexSchema.toPredicates(vertices);
    if (direction.equals(Direction.OUT) && outPredicates.notAborted())
        return outPredicates;
    if (direction.equals(Direction.IN) && inPredicates.notAborted())
        return inPredicates;
    if (outPredicates.notAborted() && inPredicates.notAborted())
        return PredicatesHolderFactory.or(inPredicates, outPredicates);
    else if (outPredicates.isAborted())
        return inPredicates;
    else if (inPredicates.isAborted())
        return outPredicates;
    else
        return PredicatesHolderFactory.abort();
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder)

Example 17 with PredicatesHolder

use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.

the class AbstractDocSchema method getSearch.

@Override
public QueryBuilder getSearch(SearchQuery<E> query) {
    PredicatesHolder predicatesHolder = this.toPredicates(query.getPredicates());
    if (predicatesHolder.getClause().equals(PredicatesHolder.Clause.Abort))
        return null;
    QueryBuilder queryBuilder = createQueryBuilder(predicatesHolder);
    return queryBuilder;
// return createSearch(query, queryBuilder);
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 18 with PredicatesHolder

use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.

the class AbstractRowSchema method getSearch.

@Override
public Select getSearch(SearchQuery<E> query, PredicatesHolder predicatesHolder) {
    if (predicatesHolder.isAborted()) {
        return null;
    }
    Condition conditions = new JdbcPredicatesTranslator().translate(predicatesHolder);
    int finalLimit = query.getLimit() < 0 ? Integer.MAX_VALUE : query.getLimit();
    SelectConditionStep<Record> where = createSqlQuery(query.getPropertyKeys()).where(conditions);
    List<Pair<String, Order>> orders = query.getOrders();
    if (orders != null) {
        List<SortField<Object>> orderValues = orders.stream().filter(order -> !order.getValue1().equals(Order.shuffle)).filter(order -> getFieldByPropertyKey(order.getValue0()) != null).map(order -> order.getValue1().equals(Order.incr) ? field(getFieldByPropertyKey(order.getValue0())).asc() : field(getFieldByPropertyKey(order.getValue0())).desc()).collect(Collectors.toList());
        if (orderValues.size() > 0)
            return where.orderBy(orderValues).limit(finalLimit);
    }
    return where.limit(finalLimit);
}
Also used : java.util(java.util) DSL(org.jooq.impl.DSL) ContextManager(org.unipop.jdbc.utils.ContextManager) DSL.field(org.jooq.impl.DSL.field) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Pair(org.javatuples.Pair) DSL.or(org.jooq.impl.DSL.or) Element(org.apache.tinkerpop.gremlin.structure.Element) JSONObject(org.json.JSONObject) Stream(java.util.stream.Stream) PredicateQuery(org.unipop.query.predicates.PredicateQuery) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) org.jooq(org.jooq) JdbcSchema(org.unipop.jdbc.schemas.jdbc.JdbcSchema) AbstractElementSchema(org.unipop.schema.element.AbstractElementSchema) UniGraph(org.unipop.structure.UniGraph) JdbcPredicatesTranslator(org.unipop.jdbc.utils.JdbcPredicatesTranslator) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) SearchQuery(org.unipop.query.search.SearchQuery) DSL.table(org.jooq.impl.DSL.table) JdbcPredicatesTranslator(org.unipop.jdbc.utils.JdbcPredicatesTranslator) Pair(org.javatuples.Pair)

Example 19 with PredicatesHolder

use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.

the class RowEdgeSchema method getVertexPredicates.

protected PredicatesHolder getVertexPredicates(List<Vertex> vertices, Direction direction) {
    PredicatesHolder outPredicates = this.outVertexSchema.toPredicates(vertices);
    PredicatesHolder inPredicates = this.inVertexSchema.toPredicates(vertices);
    if (direction.equals(Direction.OUT))
        return outPredicates;
    if (direction.equals(Direction.IN))
        return inPredicates;
    return PredicatesHolderFactory.or(inPredicates, outPredicates);
}
Also used : PredicatesHolder(org.unipop.query.predicates.PredicatesHolder)

Example 20 with PredicatesHolder

use of org.unipop.query.predicates.PredicatesHolder in project unipop by unipop-graph.

the class UniGraph method createIdPredicate.

public static <E extends Element> PredicatesHolder createIdPredicate(Object[] ids, Class<E> returnType) {
    ElementHelper.validateMixedElementIds(returnType, ids);
    // if (ids.length > 0 && Vertex.class.isAssignableFrom(ids[0].getClass()))  return new ArrayIterator<>(ids);
    if (ids.length > 0) {
        List<Object> collect = Stream.of(ids).map(id -> {
            if (id instanceof Element)
                return ((Element) id).id();
            return id;
        }).collect(Collectors.toList());
        HasContainer idPredicate = new HasContainer(T.id.getAccessor(), P.within(collect));
        return PredicatesHolderFactory.predicate(idPredicate);
    }
    return PredicatesHolderFactory.empty();
}
Also used : Configuration(org.apache.commons.configuration.Configuration) java.util(java.util) TraversalStrategies(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies) GraphComputer(org.apache.tinkerpop.gremlin.process.computer.GraphComputer) PropertyTypeFactory(org.unipop.util.PropertyTypeFactory) ElementHelper(org.apache.tinkerpop.gremlin.structure.util.ElementHelper) StandardStrategyProvider(org.unipop.process.strategyregistrar.StandardStrategyProvider) StringUtils(org.apache.commons.lang3.StringUtils) PredicatesHolderFactory(org.unipop.query.predicates.PredicatesHolderFactory) org.apache.tinkerpop.gremlin.structure(org.apache.tinkerpop.gremlin.structure) TraversalFilter(org.unipop.structure.traversalfilter.TraversalFilter) UnipopGraphProvider(org.unipop.test.UnipopGraphProvider) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) ConversionUtils(org.unipop.util.ConversionUtils) P(org.apache.tinkerpop.gremlin.process.traversal.P) PropertySchema(org.unipop.schema.property.PropertySchema) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AddVertexQuery(org.unipop.query.mutation.AddVertexQuery) Collectors(java.util.stream.Collectors) ConfigurationControllerManager(org.unipop.query.controller.ConfigurationControllerManager) StrategyProvider(org.unipop.process.strategyregistrar.StrategyProvider) DefaultTraversalFilter(org.unipop.structure.traversalfilter.DefaultTraversalFilter) Stream(java.util.stream.Stream) ControllerManager(org.unipop.query.controller.ControllerManager) StringFactory(org.apache.tinkerpop.gremlin.structure.util.StringFactory) SearchQuery(org.unipop.query.search.SearchQuery) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) org.unipop.schema.property.type(org.unipop.schema.property.type) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Aggregations

PredicatesHolder (org.unipop.query.predicates.PredicatesHolder)23 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)9 Collectors (java.util.stream.Collectors)7 java.util (java.util)6 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)6 Stream (java.util.stream.Stream)5 P (org.apache.tinkerpop.gremlin.process.traversal.P)5 JSONObject (org.json.JSONObject)5 PredicatesHolderFactory (org.unipop.query.predicates.PredicatesHolderFactory)4 SearchQuery (org.unipop.query.search.SearchQuery)4 AddVertexQuery (org.unipop.query.mutation.AddVertexQuery)3 ConversionUtils (org.unipop.util.ConversionUtils)3 Configuration (org.apache.commons.configuration.Configuration)2 StringUtils (org.apache.commons.lang3.StringUtils)2 GraphComputer (org.apache.tinkerpop.gremlin.process.computer.GraphComputer)2 TraversalStrategies (org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 org.apache.tinkerpop.gremlin.structure (org.apache.tinkerpop.gremlin.structure)2 Element (org.apache.tinkerpop.gremlin.structure.Element)2 JSONArray (org.json.JSONArray)2