Search in sources :

Example 1 with SearchQuery

use of org.unipop.query.search.SearchQuery in project unipop by unipop-graph.

the class UniGraph method query.

private <E extends Element, C extends Comparable> Iterator<E> query(Class<E> returnType, Object[] ids) {
    PredicatesHolder idPredicate = createIdPredicate(ids, returnType);
    SearchQuery<E> uniQuery = new SearchQuery<>(returnType, idPredicate, -1, null, null, null, null);
    return queryControllers.stream().<E>flatMap(controller -> ConversionUtils.asStream(controller.search(uniQuery))).iterator();
}
Also used : SearchQuery(org.unipop.query.search.SearchQuery) 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) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder)

Example 2 with SearchQuery

use of org.unipop.query.search.SearchQuery 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 3 with SearchQuery

use of org.unipop.query.search.SearchQuery in project unipop by unipop-graph.

the class VirtualController method search.

@Override
public <E extends Element> Iterator<E> search(SearchQuery<E> uniQuery) {
    if (uniQuery.getReturnType() != Vertex.class)
        return EmptyIterator.instance();
    PredicatesHolder predicates = uniQuery.getPredicates();
    List<? extends VirtualVertexSchema> filteredSchemas = vertexSchemas.stream().filter(schema -> !schema.toPredicates(predicates).getClause().equals(PredicatesHolder.Clause.Abort)).collect(Collectors.toList());
    Optional<HasContainer> ids = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.id.getAccessor())).findFirst();
    Optional<HasContainer> labels = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.label.getAccessor())).findFirst();
    if (!ids.isPresent() || !labels.isPresent()) {
        return EmptyIterator.instance();
    }
    ArrayList<Map<String, Object>> elements = new ArrayList<>();
    Object idObject = ids.get().getValue();
    Collection<Object> idsCol = idObject instanceof Collection ? ((Collection) idObject) : Collections.singleton(idObject);
    Object labelObject = labels.get().getValue();
    Collection<Object> labelCol = labelObject instanceof Collection ? ((Collection) labelObject) : Collections.singleton(labelObject);
    idsCol.forEach(id -> labelCol.forEach(label -> elements.add(createElement(id, label.toString()))));
    return (Iterator<E>) elements.stream().flatMap(fields -> filteredSchemas.stream().flatMap(schema -> Stream.of(schema.createElement(fields)))).filter(v -> v != null).iterator();
}
Also used : java.util(java.util) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AddVertexQuery(org.unipop.query.mutation.AddVertexQuery) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SimpleController(org.unipop.query.controller.SimpleController) T(org.apache.tinkerpop.gremlin.structure.T) Maps(com.google.common.collect.Maps) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) Collectors(java.util.stream.Collectors) AddEdgeQuery(org.unipop.query.mutation.AddEdgeQuery) Element(org.apache.tinkerpop.gremlin.structure.Element) Stream(java.util.stream.Stream) RemoveQuery(org.unipop.query.mutation.RemoveQuery) NotImplementedException(org.apache.commons.lang.NotImplementedException) ElementSchema(org.unipop.schema.element.ElementSchema) UniGraph(org.unipop.structure.UniGraph) PropertyQuery(org.unipop.query.mutation.PropertyQuery) UniEdge(org.unipop.structure.UniEdge) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) SearchQuery(org.unipop.query.search.SearchQuery) Edge(org.apache.tinkerpop.gremlin.structure.Edge) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator)

Aggregations

java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 PredicatesHolder (org.unipop.query.predicates.PredicatesHolder)3 SearchQuery (org.unipop.query.search.SearchQuery)3 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 Element (org.apache.tinkerpop.gremlin.structure.Element)2 AddVertexQuery (org.unipop.query.mutation.AddVertexQuery)2 UniGraph (org.unipop.structure.UniGraph)2 Maps (com.google.common.collect.Maps)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 Configuration (org.apache.commons.configuration.Configuration)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 GraphComputer (org.apache.tinkerpop.gremlin.process.computer.GraphComputer)1 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 TraversalStrategies (org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies)1 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 org.apache.tinkerpop.gremlin.structure (org.apache.tinkerpop.gremlin.structure)1