Search in sources :

Example 1 with JdbcSchema

use of org.unipop.jdbc.schemas.jdbc.JdbcSchema 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 JdbcSchema

use of org.unipop.jdbc.schemas.jdbc.JdbcSchema 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 JdbcSchema

use of org.unipop.jdbc.schemas.jdbc.JdbcSchema in project unipop by unipop-graph.

the class JdbcSourceProvider method init.

@Override
public Set<UniQueryController> init(UniGraph graph, JSONObject configuration, TraversalFilter traversalFilter) throws Exception {
    this.contextManager = new ContextManager(configuration);
    this.graph = graph;
    Set<JdbcSchema> schemas = Sets.newHashSet();
    getList(configuration, "vertices").forEach(vertexJson -> schemas.add(createVertexSchema(vertexJson)));
    getList(configuration, "edges").forEach(edgeJson -> schemas.add(createEdgeSchema(edgeJson)));
    return createControllers(schemas, traversalFilter);
}
Also used : JdbcSchema(org.unipop.jdbc.schemas.jdbc.JdbcSchema) ContextManager(org.unipop.jdbc.utils.ContextManager)

Aggregations

JdbcSchema (org.unipop.jdbc.schemas.jdbc.JdbcSchema)3 ContextManager (org.unipop.jdbc.utils.ContextManager)3 Maps (com.google.common.collect.Maps)2 java.util (java.util)2 TimeUnit (java.util.concurrent.TimeUnit)2 java.util.function (java.util.function)2 Collector (java.util.stream.Collector)2 Collectors (java.util.stream.Collectors)2 DefaultMapEntry (org.apache.commons.collections4.keyvalue.DefaultMapEntry)2 P (org.apache.tinkerpop.gremlin.process.traversal.P)2 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 MutableMetrics (org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics)2 TraversalMetrics (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics)2 org.apache.tinkerpop.gremlin.structure (org.apache.tinkerpop.gremlin.structure)2 EmptyIterator (org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator)2 org.jooq (org.jooq)2 DataAccessException (org.jooq.exception.DataAccessException)2 DSL (org.jooq.impl.DSL)2 DSL.field (org.jooq.impl.DSL.field)2 DSL.table (org.jooq.impl.DSL.table)2