com.thinkaurelius.titan.core.PropertyKey Java Examples

The following examples show how to use com.thinkaurelius.titan.core.PropertyKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardVertexProperty.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public void setPropertyDirect(PropertyKey key, Object value) {
    Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot use implicit type [%s] when setting property", key.name());
    if (properties == EMPTY_PROPERTIES) {
        if (tx().getConfiguration().isSingleThreaded()) {
            properties = new HashMap<PropertyKey, Object>(5);
        } else {
            synchronized (this) {
                if (properties == EMPTY_PROPERTIES) {
                    properties = Collections.synchronizedMap(new HashMap<PropertyKey, Object>(5));
                }
            }
        }
    }
    properties.put(key, value);
}
 
Example #2
Source File: SchemaContainer.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.openManagement();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example #3
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public <T extends RelationType> Iterable<T> getRelationTypes(Class<T> clazz) {
    Preconditions.checkNotNull(clazz);
    Iterable<? extends TitanVertex> types = null;
    if (PropertyKey.class.equals(clazz)) {
        types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.PROPERTYKEY);
    } else if (EdgeLabel.class.equals(clazz)) {
        types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.EDGELABEL);
    } else if (RelationType.class.equals(clazz)) {
        types = Iterables.concat(getRelationTypes(EdgeLabel.class), getRelationTypes(PropertyKey.class));
    } else throw new IllegalArgumentException("Unknown type class: " + clazz);
    return Iterables.filter(Iterables.filter(types, clazz), new Predicate<T>() {
        @Override
        public boolean apply(@Nullable T t) {
            //Filter out all relation type indexes
            return ((InternalRelationType) t).getBaseType() == null;
        }
    });
}
 
Example #4
Source File: StandardEdge.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public void setPropertyDirect(PropertyKey key, Object value) {
    Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot use implicit type [%s] when setting property", key.name());
    if (properties == EMPTY_PROPERTIES) {
        if (tx().getConfiguration().isSingleThreaded()) {
            properties = new HashMap<PropertyKey, Object>(5);
        } else {
            synchronized (this) {
                if (properties == EMPTY_PROPERTIES) {
                    properties = Collections.synchronizedMap(new HashMap<PropertyKey, Object>(5));
                }
            }
        }
    }
    properties.put(key, value);
}
 
Example #5
Source File: Titan1Graph.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public Titan1Graph() {
    //determine multi-properties once at startup
    TitanManagement mgmt = null;
    try {
        mgmt = Titan1GraphDatabase.getGraphInstance().openManagement();
        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
        multiProperties = new HashSet<>();
        for (PropertyKey key : keys) {
            if (key.cardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.name());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }
}
 
Example #6
Source File: Titan0GraphManagement.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
public AtlasPropertyKey makePropertyKey(String propertyName, Class propertyClass, AtlasCardinality cardinality) {

    if (cardinality.isMany()) {
        newMultProperties.add(propertyName);
    }

    PropertyKeyMaker propertyKeyBuilder = management.makePropertyKey(propertyName).dataType(propertyClass);

    if (cardinality != null) {
        Cardinality titanCardinality = TitanObjectFactory.createCardinality(cardinality);
        propertyKeyBuilder.cardinality(titanCardinality);
    }
    PropertyKey propertyKey = propertyKeyBuilder.make();
    return GraphDbObjectFactory.createPropertyKey(propertyKey);
}
 
Example #7
Source File: Titan0Graph.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public Titan0Graph() {
    //determine multi-properties once at startup
    TitanManagement mgmt = null;
    try {
        mgmt = Titan0GraphDatabase.getGraphInstance().getManagementSystem();
        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
        multiProperties = Collections.synchronizedSet(new HashSet<String>());
        for(PropertyKey key : keys) {
            if (key.getCardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.getName());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }
}
 
Example #8
Source File: SimpleIndexCache.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<TitanVertexProperty> get(final Object value, final PropertyKey key) {
    return Iterables.filter(map.get(value),new Predicate<TitanVertexProperty>() {
        @Override
        public boolean apply(@Nullable TitanVertexProperty titanProperty) {
            return titanProperty.propertyKey().equals(key);
        }
    });
}
 
Example #9
Source File: Titan1GraphManagement.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public AtlasPropertyKey makePropertyKey(String propertyName, Class propertyClass, AtlasCardinality cardinality) {

    if (cardinality.isMany()) {
        newMultProperties.add(propertyName);
    }
    PropertyKeyMaker propertyKeyBuilder = management.makePropertyKey(propertyName).dataType(propertyClass);
    if (cardinality != null) {
        Cardinality titanCardinality = TitanObjectFactory.createCardinality(cardinality);
        propertyKeyBuilder.cardinality(titanCardinality);
    }
    PropertyKey propertyKey = propertyKeyBuilder.make();
    return GraphDbObjectFactory.createPropertyKey(propertyKey);
}
 
Example #10
Source File: Titan0GraphManagement.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void createExactMatchIndex(String propertyName, boolean enforceUniqueness,
        List<AtlasPropertyKey> propertyKeys) {

    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for(AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    if (enforceUniqueness) {
        indexBuilder.unique();
    }
    indexBuilder.buildCompositeIndex();
}
 
Example #11
Source File: CacheVertexProperty.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<PropertyKey> getPropertyKeysDirect() {
    RelationCache map = getPropertyMap();
    List<PropertyKey> types = new ArrayList<>(map.numProperties());

    for (LongObjectCursor<Object> entry : map) {
        types.add(tx().getExistingPropertyKey(entry.key));
    }
    return types;
}
 
Example #12
Source File: AbstractIndexManagementIT.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepairRelationIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();

    // Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);

    // Create and enable a relation index on lives edges by reason
    TitanManagement m = graph.openManagement();
    PropertyKey reason = m.getPropertyKey("reason");
    EdgeLabel lives = m.getEdgeLabel("lives");
    m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason);
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to REGISTERED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives")
            .status(SchemaStatus.REGISTERED).call().getSucceeded());

    m = graph.openManagement();
    RelationTypeIndex index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    m.updateIndex(index, SchemaAction.ENABLE_INDEX);
    m.commit();
    graph.tx().commit();

    // Block until the SchemaStatus transitions to ENABLED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives")
            .status(SchemaStatus.ENABLED).call().getSucceeded());

    // Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
    //assertFalse(graph.query().has("reason", "no fear of death").edges().iterator().hasNext());

    // Repair
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
    assertEquals(8, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
}
 
Example #13
Source File: GraphDbObjectFactory.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * @param propertyKey The Gremlin propertyKey.
 *
 */
public static Titan1PropertyKey createPropertyKey(PropertyKey propertyKey) {
    if (propertyKey == null) {
        return null;
    }
    return new Titan1PropertyKey(propertyKey);
}
 
Example #14
Source File: CacheVertexProperty.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private void copyProperties(InternalRelation to) {
    for (LongObjectCursor<Object> entry : getPropertyMap()) {
        PropertyKey type = tx().getExistingPropertyKey(entry.key);
        if (!(type instanceof ImplicitKey))
            to.setPropertyDirect(type, entry.value);
    }
}
 
Example #15
Source File: GraphDbObjectFactory.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * @param propertyKey The Gremlin propertyKey.
 *
 */
public static Titan0PropertyKey createPropertyKey(PropertyKey propertyKey) {
    if (propertyKey == null) {
        return null;
    }
    return new Titan0PropertyKey(propertyKey);
}
 
Example #16
Source File: BaseVertexCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public Q orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) {
    Preconditions.checkArgument(schemaInspector.containsPropertyKey(keyName), "Provided key does not exist: %s", keyName);
    PropertyKey key = schemaInspector.getPropertyKey(keyName);
    Preconditions.checkArgument(key != null && order != null, "Need to specify and key and an order");
    Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.dataType()),
            "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.name(), key.dataType());
    Preconditions.checkArgument(key.cardinality() == Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.name());
    Preconditions.checkArgument(!(key instanceof SystemRelationType), "Cannot use system types in ordering: %s", key);
    Preconditions.checkArgument(!orders.containsKey(key));
    Preconditions.checkArgument(orders.isEmpty(), "Only a single sort order is supported on vertex queries");
    orders.add(key, Order.convert(order));
    return getThis();
}
 
Example #17
Source File: HasStepFolder.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static boolean validTitanOrder(OrderGlobalStep ostep, Traversal rootTraversal,
                                      boolean isVertexOrder) {
    for (Comparator comp : (List<Comparator>) ostep.getComparators()) {
        if (!(comp instanceof ElementValueComparator)) return false;
        ElementValueComparator evc = (ElementValueComparator) comp;
        if (!(evc.getValueComparator() instanceof Order)) return false;

        TitanTransaction tx = TitanTraversalUtil.getTx(rootTraversal.asAdmin());
        String key = evc.getPropertyKey();
        PropertyKey pkey = tx.getPropertyKey(key);
        if (pkey == null || !(Comparable.class.isAssignableFrom(pkey.dataType()))) return false;
        if (isVertexOrder && pkey.cardinality() != Cardinality.SINGLE) return false;
    }
    return true;
}
 
Example #18
Source File: RelationIdentifier.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
TitanRelation findRelation(TitanTransaction tx) {
    TitanVertex v = ((StandardTitanTx)tx).getInternalVertex(outVertexId);
    if (v == null || v.isRemoved()) return null;
    TitanVertex typeVertex = tx.getVertex(typeId);
    if (typeVertex == null) return null;
    if (!(typeVertex instanceof RelationType))
        throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type");

    RelationType type = (RelationType) typeVertex;
    Iterable<? extends TitanRelation> rels;
    if (((RelationType) typeVertex).isEdgeLabel()) {
        Direction dir = Direction.OUT;
        TitanVertex other = ((StandardTitanTx)tx).getInternalVertex(inVertexId);
        if (other==null || other.isRemoved()) return null;
        if (((StandardTitanTx) tx).isPartitionedVertex(v) && !((StandardTitanTx) tx).isPartitionedVertex(other)) { //Swap for likely better performance
            TitanVertex tmp = other;
            other = v;
            v = tmp;
            dir = Direction.IN;
        }
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges();
    } else {
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties();
    }

    for (TitanRelation r : rels) {
        //Find current or previous relation
        if (r.longId() == relationId ||
                ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId)) return r;
    }
    return null;
}
 
Example #19
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
/**
 * Tests indexing boolean
 */
@Test
public void testBooleanIndexing() {
    PropertyKey name = makeKey("visible", Boolean.class);
    mgmt.buildIndex("booleanIndex", Vertex.class).
            addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();

    TitanVertex v1 = graph.addVertex();
    v1.property("visible", true);

    TitanVertex v2 = graph.addVertex();
    v2.property("visible", false);

    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));

    clopen();//Flush the index
    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
}
 
Example #20
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private UpdateStatusTrigger(StandardTitanGraph graph, TitanSchemaVertex vertex, SchemaStatus newStatus, Iterable<PropertyKeyVertex> keys) {
    this.graph = graph;
    this.schemaVertexId = vertex.longId();
    this.newStatus = newStatus;
    this.propertyKeys = Sets.newHashSet(Iterables.transform(keys, new Function<PropertyKey, Long>() {
        @Nullable
        @Override
        public Long apply(@Nullable PropertyKey propertyKey) {
            return propertyKey.longId();
        }
    }));
}
 
Example #21
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private TitanGraphIndex createCompositeIndex(String indexName, ElementCategory elementCategory, boolean unique, TitanSchemaType constraint, PropertyKey... keys) {
    checkIndexName(indexName);
    Preconditions.checkArgument(keys != null && keys.length > 0, "Need to provide keys to index [%s]", indexName);
    Preconditions.checkArgument(!unique || elementCategory == ElementCategory.VERTEX, "Unique indexes can only be created on vertices [%s]", indexName);
    boolean allSingleKeys = true;
    boolean oneNewKey = false;
    for (PropertyKey key : keys) {
        Preconditions.checkArgument(key != null && key instanceof PropertyKeyVertex, "Need to provide valid keys: %s", key);
        if (key.cardinality() != Cardinality.SINGLE) allSingleKeys = false;
        if (key.isNew()) oneNewKey = true;
        else updatedTypes.add((PropertyKeyVertex) key);
    }

    Cardinality indexCardinality;
    if (unique) indexCardinality = Cardinality.SINGLE;
    else indexCardinality = (allSingleKeys ? Cardinality.SET : Cardinality.LIST);

    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, true);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, Token.INTERNAL_INDEX_NAME);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, indexCardinality);
    def.setValue(TypeDefinitionCategory.STATUS, oneNewKey ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
    TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);
    for (int i = 0; i < keys.length; i++) {
        Parameter[] paras = {ParameterType.INDEX_POSITION.getParameter(i)};
        addSchemaEdge(indexVertex, keys[i], TypeDefinitionCategory.INDEX_FIELD, paras);
    }

    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    TitanGraphIndexWrapper index = new TitanGraphIndexWrapper(indexVertex.asIndexType());
    if (!oneNewKey) updateIndex(index, SchemaAction.REGISTER_INDEX);
    return index;
}
 
Example #22
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public TitanGraphIndex buildCompositeIndex() {
    Preconditions.checkArgument(!keys.isEmpty(), "Need to specify at least one key for the composite index");
    PropertyKey[] keyArr = new PropertyKey[keys.size()];
    int pos = 0;
    for (Map.Entry<PropertyKey, Parameter[]> entry : keys.entrySet()) {
        Preconditions.checkArgument(entry.getValue() == null, "Cannot specify parameters for composite index: %s", entry.getKey());
        keyArr[pos++] = entry.getKey();
    }
    return createCompositeIndex(indexName, elementCategory, unique, constraint, keyArr);
}
 
Example #23
Source File: ConcurrentIndexCache.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized Iterable<TitanVertexProperty> get(final Object value, final PropertyKey key) {
    List<TitanVertexProperty> result = new ArrayList<TitanVertexProperty>(4);
    for (TitanVertexProperty p : map.get(value)) {
        if (p.propertyKey().equals(key)) result.add(p);
    }
    return result;
}
 
Example #24
Source File: IndexField.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
IndexField(PropertyKey key) {
    Preconditions.checkNotNull(key);
    this.key = key;
}
 
Example #25
Source File: OrderList.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public void add(PropertyKey key, Order order) {
    Preconditions.checkArgument(!immutable, "This OrderList has been closed");
    list.add(new OrderEntry(key, order));
}
 
Example #26
Source File: IndexField.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public PropertyKey getFieldKey() {
    return key;
}
 
Example #27
Source File: MixedIndexTypeWrapper.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public ParameterIndexField getField(PropertyKey key) {
    return (ParameterIndexField)super.getField(key);
}
 
Example #28
Source File: StandardVertexProperty.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public <O> O getValueDirect(PropertyKey key) {
    return (O) properties.get(key);
}
 
Example #29
Source File: Titan0PropertyKey.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public Titan0PropertyKey(PropertyKey toWrap) {
    wrappedPropertyKey = toWrap;
}
 
Example #30
Source File: IndexField.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static IndexField of(PropertyKey key) {
    return new IndexField(key);
}