Search in sources :

Example 1 with DeferredVertexQuery

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

the class RowController method fetchProperties.

@Override
public void fetchProperties(DeferredVertexQuery uniQuery) {
    SelectCollector<JdbcSchema<Vertex>, Select, Vertex> collector = new SelectCollector<>(schema -> schema.getSearch(uniQuery, schema.toPredicates(uniQuery.getPredicates())), (schema, results) -> schema.parseResults(results, uniQuery));
    Map<JdbcSchema<Vertex>, Select> selects = vertexSchemas.stream().filter(schema -> this.traversalFilter.filter(schema, uniQuery.getTraversal())).collect(collector);
    Iterator<Vertex> searchIterator = this.search(uniQuery, selects, collector);
    Map<Object, DeferredVertex> vertexMap = uniQuery.getVertices().stream().collect(Collectors.toMap(UniElement::id, Function.identity(), (a, b) -> a));
    searchIterator.forEachRemaining(newVertex -> {
        DeferredVertex deferredVertex = vertexMap.get(newVertex.id());
        if (deferredVertex != null) {
            deferredVertex.loadProperties(newVertex);
        }
    });
}
Also used : java.util(java.util) DSL(org.jooq.impl.DSL) ContextManager(org.unipop.jdbc.utils.ContextManager) LoggerFactory(org.slf4j.LoggerFactory) DSL.field(org.jooq.impl.DSL.field) SimpleController(org.unipop.query.controller.SimpleController) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) UniQuery(org.unipop.query.UniQuery) AddEdgeQuery(org.unipop.query.mutation.AddEdgeQuery) RemoveQuery(org.unipop.query.mutation.RemoveQuery) DefaultMapEntry(org.apache.commons.collections4.keyvalue.DefaultMapEntry) org.apache.tinkerpop.gremlin.structure(org.apache.tinkerpop.gremlin.structure) org.jooq(org.jooq) TraversalFilter(org.unipop.structure.traversalfilter.TraversalFilter) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) TimingExecuterListener(org.unipop.jdbc.utils.TimingExecuterListener) ElementSchema(org.unipop.schema.element.ElementSchema) UniEdge(org.unipop.structure.UniEdge) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Collector(java.util.stream.Collector) RowVertexSchema(org.unipop.jdbc.schemas.RowVertexSchema) P(org.apache.tinkerpop.gremlin.process.traversal.P) DeferredVertex(org.unipop.schema.reference.DeferredVertex) DataAccessException(org.jooq.exception.DataAccessException) Logger(org.slf4j.Logger) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) UniElement(org.unipop.structure.UniElement) AddVertexQuery(org.unipop.query.mutation.AddVertexQuery) RowEdgeSchema(org.unipop.jdbc.schemas.RowEdgeSchema) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) JdbcEdgeSchema(org.unipop.jdbc.schemas.jdbc.JdbcEdgeSchema) PredicatesTranslator(org.unipop.common.util.PredicatesTranslator) JdbcSchema(org.unipop.jdbc.schemas.jdbc.JdbcSchema) UniGraph(org.unipop.structure.UniGraph) PropertyQuery(org.unipop.query.mutation.PropertyQuery) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) SearchQuery(org.unipop.query.search.SearchQuery) java.util.function(java.util.function) MetricsRunner(org.unipop.util.MetricsRunner) DSL.table(org.jooq.impl.DSL.table) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) UniVertex(org.unipop.structure.UniVertex) JdbcSchema(org.unipop.jdbc.schemas.jdbc.JdbcSchema) DeferredVertex(org.unipop.schema.reference.DeferredVertex)

Example 2 with DeferredVertexQuery

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

the class DocumentController method fetchProperties.

@Override
public void fetchProperties(DeferredVertexQuery uniQuery) {
    Map<DocumentVertexSchema, QueryBuilder> schemas = vertexSchemas.stream().filter(schema -> this.traversalFilter.filter(schema, uniQuery.getTraversal())).collect(new SearchCollector<>((schema) -> schema.getSearch(uniQuery)));
    Iterator<Vertex> search = search(uniQuery, schemas);
    Map<Object, DeferredVertex> vertexMap = uniQuery.getVertices().stream().collect(Collectors.toMap(UniElement::id, Function.identity(), (a, b) -> a));
    search.forEachRemaining(newVertex -> {
        DeferredVertex deferredVertex = vertexMap.get(newVertex.id());
        if (deferredVertex != null)
            deferredVertex.loadProperties(newVertex);
    });
}
Also used : java.util(java.util) ElasticClient(org.unipop.elastic.common.ElasticClient) LoggerFactory(org.slf4j.LoggerFactory) SimpleController(org.unipop.query.controller.SimpleController) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AddEdgeQuery(org.unipop.query.mutation.AddEdgeQuery) RemoveQuery(org.unipop.query.mutation.RemoveQuery) Gson(com.google.gson.Gson) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) TraversalFilter(org.unipop.structure.traversalfilter.TraversalFilter) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) BiConsumer(java.util.function.BiConsumer) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) ElementSchema(org.unipop.schema.element.ElementSchema) UniEdge(org.unipop.structure.UniEdge) io.searchbox.core(io.searchbox.core) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Collector(java.util.stream.Collector) Edge(org.apache.tinkerpop.gremlin.structure.Edge) DeferredVertex(org.unipop.schema.reference.DeferredVertex) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Logger(org.slf4j.Logger) UniElement(org.unipop.structure.UniElement) AddVertexQuery(org.unipop.query.mutation.AddVertexQuery) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) BinaryOperator(java.util.function.BinaryOperator) TimeUnit(java.util.concurrent.TimeUnit) Element(org.apache.tinkerpop.gremlin.structure.Element) Stream(java.util.stream.Stream) SortOrder(org.elasticsearch.search.sort.SortOrder) UniGraph(org.unipop.structure.UniGraph) BulkableAction(io.searchbox.action.BulkableAction) PropertyQuery(org.unipop.query.mutation.PropertyQuery) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) SearchQuery(org.unipop.query.search.SearchQuery) MetricsRunner(org.unipop.util.MetricsRunner) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UniVertex(org.unipop.structure.UniVertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 3 with DeferredVertexQuery

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

the class UniGraphEdgeVertexStep method process.

@Override
protected Iterator<Traverser.Admin<Vertex>> process(List<Traverser.Admin<Edge>> traversers) {
    List<Traverser.Admin<Vertex>> vertices = new ArrayList<>();
    traversers.forEach(travrser -> {
        travrser.get().vertices(direction).forEachRemaining(vertex -> vertices.add(travrser.split(vertex, this)));
    });
    if (propertyKeys == null || propertyKeys.size() > 1) {
        List<DeferredVertex> v = vertices.stream().map(Attachable::get).filter(vertex -> vertex instanceof DeferredVertex).map(vertex -> ((DeferredVertex) vertex)).filter(DeferredVertex::isDeferred).collect(Collectors.toList());
        if (v.size() > 0) {
            DeferredVertexQuery query = new DeferredVertexQuery(v, propertyKeys, orders, this.stepDescriptor, traversal);
            deferredVertexControllers.forEach(deferredVertexController -> deferredVertexController.fetchProperties(query));
        }
    }
    return vertices.iterator();
}
Also used : DeferredVertex(org.unipop.schema.reference.DeferredVertex) java.util(java.util) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) StepDescriptor(org.unipop.query.StepDescriptor) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Orderable(org.unipop.process.order.Orderable) Profiling(org.apache.tinkerpop.gremlin.process.traversal.step.Profiling) TraverserRequirement(org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) ControllerManager(org.unipop.query.controller.ControllerManager) UniGraph(org.unipop.structure.UniGraph) StringFactory(org.apache.tinkerpop.gremlin.structure.util.StringFactory) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) UniPredicatesStep(org.unipop.process.UniPredicatesStep) Edge(org.apache.tinkerpop.gremlin.structure.Edge) DeferredVertex(org.unipop.schema.reference.DeferredVertex) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable)

Example 4 with DeferredVertexQuery

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

the class UniGraphEdgeOtherVertexStep method process.

@Override
protected Iterator<Traverser.Admin<Vertex>> process(List<Traverser.Admin<Edge>> traversers) {
    List<Traverser.Admin<Vertex>> vertices = new ArrayList<>();
    traversers.forEach(traverser -> {
        final List<Object> objects = traverser.path().objects();
        if (objects.get(objects.size() - 2) instanceof Vertex) {
            Vertex vertex = ElementHelper.areEqual((Vertex) objects.get(objects.size() - 2), traverser.get().outVertex()) ? traverser.get().inVertex() : traverser.get().outVertex();
            vertices.add(traverser.split(vertex, this));
        }
    });
    if (propertyKeys == null || propertyKeys.size() > 0) {
        List<DeferredVertex> v = vertices.stream().map(Attachable::get).filter(vertex -> vertex instanceof DeferredVertex).map(vertex -> ((DeferredVertex) vertex)).filter(DeferredVertex::isDeferred).collect(Collectors.toList());
        if (v.size() > 0) {
            DeferredVertexQuery query = new DeferredVertexQuery(v, propertyKeys, orders, stepDescriptor, traversal);
            deferredVertexControllers.forEach(deferredVertexController -> deferredVertexController.fetchProperties(query));
        }
    }
    return vertices.iterator();
}
Also used : DeferredVertex(org.unipop.schema.reference.DeferredVertex) java.util(java.util) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ElementHelper(org.apache.tinkerpop.gremlin.structure.util.ElementHelper) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) StepDescriptor(org.unipop.query.StepDescriptor) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Orderable(org.unipop.process.order.Orderable) Profiling(org.apache.tinkerpop.gremlin.process.traversal.step.Profiling) TraverserRequirement(org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) ControllerManager(org.unipop.query.controller.ControllerManager) UniGraph(org.unipop.structure.UniGraph) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) UniPredicatesStep(org.unipop.process.UniPredicatesStep) Edge(org.apache.tinkerpop.gremlin.structure.Edge) DeferredVertex(org.unipop.schema.reference.DeferredVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable)

Example 5 with DeferredVertexQuery

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

the class UniGraphVertexStep method getTraversersWithProperties.

private Iterator<Traverser.Admin<E>> getTraversersWithProperties(Iterator<Traverser.Admin<E>> traversers) {
    List<Traverser.Admin<E>> copyTraversers = ConversionUtils.asStream(traversers).collect(Collectors.toList());
    List<DeferredVertex> deferredVertices = copyTraversers.stream().map(Attachable::get).filter(vertex -> vertex instanceof DeferredVertex).map(vertex -> ((DeferredVertex) vertex)).filter(DeferredVertex::isDeferred).collect(Collectors.toList());
    if (deferredVertices.size() > 0) {
        DeferredVertexQuery query = new DeferredVertexQuery(deferredVertices, propertyKeys, orders, this.stepDescriptor, traversal);
        deferredVertexControllers.stream().forEach(controller -> controller.fetchProperties(query));
    }
    return copyTraversers.iterator();
}
Also used : org.apache.tinkerpop.gremlin.process.traversal(org.apache.tinkerpop.gremlin.process.traversal) java.util(java.util) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable) LoggerFactory(org.slf4j.LoggerFactory) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) org.apache.tinkerpop.gremlin.process.traversal.step.util(org.apache.tinkerpop.gremlin.process.traversal.step.util) PredicatesHolderFactory(org.unipop.query.predicates.PredicatesHolderFactory) Orderable(org.unipop.process.order.Orderable) Profiling(org.apache.tinkerpop.gremlin.process.traversal.step.Profiling) org.apache.tinkerpop.gremlin.structure(org.apache.tinkerpop.gremlin.structure) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) ConversionUtils(org.unipop.util.ConversionUtils) DeferredVertex(org.unipop.schema.reference.DeferredVertex) Logger(org.slf4j.Logger) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) ReceivesPredicatesHolder(org.unipop.process.predicate.ReceivesPredicatesHolder) StepDescriptor(org.unipop.query.StepDescriptor) Stream(java.util.stream.Stream) TraverserRequirement(org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement) ControllerManager(org.unipop.query.controller.ControllerManager) UniGraph(org.unipop.structure.UniGraph) StringFactory(org.apache.tinkerpop.gremlin.structure.util.StringFactory) UniPredicatesStep(org.unipop.process.UniPredicatesStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable)

Aggregations

DeferredVertexQuery (org.unipop.query.search.DeferredVertexQuery)7 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 DeferredVertex (org.unipop.schema.reference.DeferredVertex)6 UniGraph (org.unipop.structure.UniGraph)6 MutableMetrics (org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics)5 EmptyIterator (org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 SearchVertexQuery (org.unipop.query.search.SearchVertexQuery)4 UniVertex (org.unipop.structure.UniVertex)4 Collector (java.util.stream.Collector)3 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)3 Profiling (org.apache.tinkerpop.gremlin.process.traversal.step.Profiling)3 TraverserRequirement (org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement)3 Edge (org.apache.tinkerpop.gremlin.structure.Edge)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 Attachable (org.apache.tinkerpop.gremlin.structure.util.Attachable)3 Pair (org.javatuples.Pair)3 UniPredicatesStep (org.unipop.process.UniPredicatesStep)3