Search in sources :

Example 1 with Namifiable

use of org.janusgraph.core.Namifiable in project grakn by graknlabs.

the class TxFactoryJanus method makeIndicesVertexCentric.

private static void makeIndicesVertexCentric(JanusGraphManagement management) {
    ResourceBundle keys = ResourceBundle.getBundle("indices-edges");
    Set<String> edgeLabels = keys.keySet();
    for (String edgeLabel : edgeLabels) {
        String[] propertyKeyStrings = keys.getString(edgeLabel).split(",");
        // Get all the property keys we need
        Set<PropertyKey> propertyKeys = stream(propertyKeyStrings).map(keyId -> {
            PropertyKey key = management.getPropertyKey(keyId);
            if (key == null) {
                throw new RuntimeException("Trying to create edge index on label [" + edgeLabel + "] but the property [" + keyId + "] does not exist");
            }
            return key;
        }).collect(Collectors.toSet());
        // Get the edge and indexing information
        RelationType relationType = management.getRelationType(edgeLabel);
        EdgeLabel label = management.getEdgeLabel(edgeLabel);
        // Create index on each property key
        for (PropertyKey key : propertyKeys) {
            if (management.getRelationIndex(relationType, edgeLabel + "by" + key.name()) == null) {
                management.buildEdgeIndex(label, edgeLabel + "by" + key.name(), Direction.BOTH, Order.decr, key);
            }
        }
        // Create index on all property keys
        String propertyKeyId = propertyKeys.stream().map(Namifiable::name).collect(Collectors.joining("_"));
        if (management.getRelationIndex(relationType, edgeLabel + "by" + propertyKeyId) == null) {
            PropertyKey[] allKeys = propertyKeys.toArray(new PropertyKey[propertyKeys.size()]);
            management.buildEdgeIndex(label, edgeLabel + "by" + propertyKeyId, Direction.BOTH, Order.decr, allKeys);
        }
    }
}
Also used : TraversalStrategies(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResourceBundle(java.util.ResourceBundle) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) GraknTx(ai.grakn.GraknTx) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) Map(java.util.Map) ErrorMessage(ai.grakn.util.ErrorMessage) PathRetractionStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathRetractionStrategy) Transaction(org.apache.tinkerpop.gremlin.structure.Transaction) RelationType(org.janusgraph.core.RelationType) Namifiable(org.janusgraph.core.Namifiable) Logger(org.slf4j.Logger) Properties(java.util.Properties) ImmutableMap(com.google.common.collect.ImmutableMap) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Set(java.util.Set) IOException(java.io.IOException) LazyBarrierStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.LazyBarrierStrategy) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraph(org.janusgraph.core.JanusGraph) Collectors(java.util.stream.Collectors) GraknConfigKey(ai.grakn.GraknConfigKey) Direction(org.apache.tinkerpop.gremlin.structure.Direction) VertexLabel(org.janusgraph.core.VertexLabel) Schema(ai.grakn.util.Schema) Arrays.stream(java.util.Arrays.stream) GraknTxJanus(ai.grakn.kb.internal.GraknTxJanus) InputStream(java.io.InputStream) RelationType(org.janusgraph.core.RelationType) EdgeLabel(org.janusgraph.core.EdgeLabel) ResourceBundle(java.util.ResourceBundle) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

GraknConfigKey (ai.grakn.GraknConfigKey)1 GraknTx (ai.grakn.GraknTx)1 GraknTxJanus (ai.grakn.kb.internal.GraknTxJanus)1 ErrorMessage (ai.grakn.util.ErrorMessage)1 Schema (ai.grakn.util.Schema)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Arrays.stream (java.util.Arrays.stream)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)1 TraversalStrategies (org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies)1 LazyBarrierStrategy (org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.LazyBarrierStrategy)1 PathRetractionStrategy (org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathRetractionStrategy)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1