Search in sources :

Example 1 with UniQuery

use of org.unipop.query.UniQuery in project unipop by unipop-graph.

the class RowController method search.

@SuppressWarnings("unchecked")
protected <E extends Element, R> Iterator<R> search(UniQuery query, Map<JdbcSchema<E>, Select> selects, SelectCollector<JdbcSchema<E>, Select, R> collector) {
    if (bulk.size() != 0) {
        contextManager.batch(bulk);
        bulk.clear();
    }
    MetricsRunner metrics = new MetricsRunner(this, query, selects.keySet().stream().map(s -> ((ElementSchema) s)).collect(Collectors.toList()));
    logger.info("mapped schemas for search, schemas: {}", selects);
    if (selects.size() == 0)
        return EmptyIterator.instance();
    Iterator<JdbcSchema<E>> schemaIterator = selects.keySet().iterator();
    Set<R> collect = selects.values().stream().map(select -> this.getContextManager().fetch(select)).flatMap(res -> collector.parse.apply(schemaIterator.next(), res).stream()).collect(Collectors.toSet());
    metrics.stop((children) -> fillChildren(children, selects));
    logger.info("results: {}", collect);
    return collect.iterator();
}
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) ElementSchema(org.unipop.schema.element.ElementSchema) JdbcSchema(org.unipop.jdbc.schemas.jdbc.JdbcSchema) MetricsRunner(org.unipop.util.MetricsRunner)

Example 2 with UniQuery

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

use of org.unipop.query.UniQuery in project unipop by unipop-graph.

the class RestController method fetchProperties.

@Override
public void fetchProperties(DeferredVertexQuery uniQuery) {
    RestCollector<RestVertexSchema, BaseRequest, Vertex> collector = new RestCollector<>(schema -> schema.getSearch(uniQuery), (schema, result) -> schema.parseResults(result, uniQuery));
    Map<RestVertexSchema, BaseRequest> schemas = vertexSchemas.stream().filter(schema -> this.traversalFilter.filter(schema, uniQuery.getTraversal())).collect(collector);
    Iterator<Vertex> iterator = search(uniQuery, schemas, collector);
    Map<Object, DeferredVertex> vertexMap = uniQuery.getVertices().stream().collect(Collectors.toMap(UniElement::id, Function.identity(), (a, b) -> a));
    iterator.forEachRemaining(newVertex -> {
        DeferredVertex deferredVertex = vertexMap.get(newVertex.id());
        if (deferredVertex != null)
            deferredVertex.loadProperties(newVertex);
    });
}
Also used : java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) 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) TraversalFilter(org.unipop.structure.traversalfilter.TraversalFilter) ElementSchema(org.unipop.schema.element.ElementSchema) UniEdge(org.unipop.structure.UniEdge) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Collector(java.util.stream.Collector) JsonNode(com.mashape.unirest.http.JsonNode) BaseRequest(com.mashape.unirest.request.BaseRequest) Edge(org.apache.tinkerpop.gremlin.structure.Edge) DeferredVertex(org.unipop.schema.reference.DeferredVertex) 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) Element(org.apache.tinkerpop.gremlin.structure.Element) HttpResponse(com.mashape.unirest.http.HttpResponse) UniGraph(org.unipop.structure.UniGraph) PropertyQuery(org.unipop.query.mutation.PropertyQuery) SearchQuery(org.unipop.query.search.SearchQuery) java.util.function(java.util.function) 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) BaseRequest(com.mashape.unirest.request.BaseRequest)

Aggregations

java.util (java.util)3 java.util.function (java.util.function)3 Collector (java.util.stream.Collector)3 Collectors (java.util.stream.Collectors)3 EmptyIterator (org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 UniQuery (org.unipop.query.UniQuery)3 SimpleController (org.unipop.query.controller.SimpleController)3 AddEdgeQuery (org.unipop.query.mutation.AddEdgeQuery)3 AddVertexQuery (org.unipop.query.mutation.AddVertexQuery)3 PropertyQuery (org.unipop.query.mutation.PropertyQuery)3 RemoveQuery (org.unipop.query.mutation.RemoveQuery)3 DeferredVertexQuery (org.unipop.query.search.DeferredVertexQuery)3 SearchQuery (org.unipop.query.search.SearchQuery)3 SearchVertexQuery (org.unipop.query.search.SearchVertexQuery)3 ElementSchema (org.unipop.schema.element.ElementSchema)3 DeferredVertex (org.unipop.schema.reference.DeferredVertex)3 UniEdge (org.unipop.structure.UniEdge)3 Maps (com.google.common.collect.Maps)2