@Override public GraphCentricQueryBuilder orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) { Preconditions.checkArgument(tx.containsPropertyKey(keyName),"Provided key does not exist: %s",keyName); final PropertyKey key = tx.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(!orders.containsKey(key)); orders.add(key, Order.convert(order)); return this; }
public PropertyKeyDefinition(PropertyKey key) { this(key.name(),key.longId(),key.cardinality(),key.dataType()); }
public StandardKeyInformation(PropertyKey key, Parameter... parameters) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(parameters); this.dataType = key.dataType(); this.parameters = parameters; this.cardinality = key.cardinality(); }
private static long[] checkSignature(List<PropertyKey> sig) { Preconditions.checkArgument(sig.size() == (Sets.newHashSet(sig)).size(), "Signature and sort key cannot contain duplicate types"); long[] signature = new long[sig.size()]; for (int i = 0; i < sig.size(); i++) { PropertyKey key = sig.get(i); Preconditions.checkNotNull(key); Preconditions.checkArgument(!((PropertyKey) key).dataType().equals(Object.class), "Signature and sort keys must have a proper declared datatype: %s", key.name()); signature[i] = key.longId(); } return signature; }
@Override public String toString() { return "["+key.name()+"]"; }
assertNotNull(mgmt.getPropertyKey("weight")); assertNotNull(mgmt.getEdgeLabel("connect")); assertTrue(weight.isPropertyKey()); assertFalse(weight.isEdgeLabel()); assertEquals(Cardinality.SINGLE, weight.cardinality()); assertEquals(Cardinality.SINGLE, someId.cardinality()); assertEquals(Cardinality.SET, name.cardinality()); assertEquals(Cardinality.LIST, value.cardinality()); assertEquals(Object.class, someId.dataType()); assertEquals(Float.class, weight.dataType()); sig = ((InternalRelationType) value).getSignature(); assertEquals(1, sig.length); assertEquals(weight.longId(), sig[0]); assertTrue(mgmt.getGraphIndex(uid.name()).isUnique()); assertFalse(mgmt.getGraphIndex(someId.name()).isUnique()); sig = ((InternalRelationType) connect).getSignature(); assertEquals(1, sig.length); assertEquals(uid.longId(), sig[0]); assertEquals(0, ((InternalRelationType) friend).getSortKey().length); assertEquals(Order.DEFAULT, ((InternalRelationType) friend).getSortOrder()); assertNotNull(mgmt.getPropertyKey("weight")); assertNotNull(mgmt.getEdgeLabel("connect")); assertTrue(weight.isPropertyKey()); assertFalse(weight.isEdgeLabel()); assertEquals(Cardinality.SINGLE, weight.cardinality()); assertEquals(Cardinality.SINGLE, someId.cardinality()); assertEquals(Cardinality.SET, name.cardinality());
public JanusGraphVertexProperty addProperty(VertexProperty.Cardinality cardinality, JanusGraphVertex vertex, PropertyKey key, Object value) { if (key.cardinality().convert()!=cardinality && cardinality!=VertexProperty.Cardinality.single) throw new SchemaViolationException("Key is defined for %s cardinality which conflicts with specified: %s",key.cardinality(),cardinality); verifyWriteAccess(vertex); Preconditions.checkArgument(!(key instanceof ImplicitKey),"Cannot create a property of implicit type: %s",key.name()); vertex = ((InternalVertex) vertex).it(); Preconditions.checkNotNull(key); checkPropertyConstraintForVertexOrCreatePropertyConstraint(vertex, key); final Object normalizedValue = verifyAttribute(key, value); Cardinality keyCardinality = key.cardinality(); throw new SchemaViolationException("Adding this property for key [%s] and value [%s] violates a uniqueness constraint [%s]", key.name(), normalizedValue, lockTuple.getIndex());
@Override public EdgeLabel addProperties(EdgeLabel edgeLabel, PropertyKey... keys) { for (PropertyKey key : keys) { if (key.cardinality() != Cardinality.SINGLE) { throw new IllegalArgumentException(String.format("An Edge [%s] can not have a property [%s] with the cardinality [%s].", edgeLabel, key, key.cardinality())); } addSchemaEdge(edgeLabel, key, TypeDefinitionCategory.PROPERTY_KEY_EDGE, null); } return edgeLabel; }
@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 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(); }
public static boolean hasGenericDataType(PropertyKey key) { return key.dataType().equals(Object.class); } }
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);
/** * Very simple graph operation to ensure minimal functionality and cleanup */ @Test public void testBasic() throws BackendException { PropertyKey uid = makeVertexIndexedUniqueKey("name", String.class); finishSchema(); JanusGraphVertex n1 = tx.addVertex(); uid = tx.getPropertyKey("name"); n1.property(uid.name(), "abcd"); clopen(); long nid = n1.longId(); uid = tx.getPropertyKey("name"); assertTrue(getV(tx, nid) != null); assertTrue(getV(tx, uid.longId()) != null); assertMissing(tx, nid + 64); uid = tx.getPropertyKey(uid.name()); n1 = getV(tx, nid); assertEquals(n1, getOnlyVertex(tx.query().has(uid.name(), "abcd"))); assertEquals(1, Iterables.size(n1.query().relations())); //TODO: how to expose relations? assertEquals("abcd", n1.value(uid.name())); assertCount(1, tx.query().vertices()); close(); JanusGraphFactory.drop(graph); open(config); assertEmpty(tx.query().vertices()); }
assert propertyKey!=ImplicitKey.ADJACENT_ID || (i==sortKeyIDs.length); assert propertyKey!=ImplicitKey.JANUSGRAPHID || (!type.multiplicity().isConstrained() && (i==sortKeyIDs.length && propertyKey.isPropertyKey() || i==sortKeyIDs.length+1 && propertyKey.isEdgeLabel() )); assert colStart.getPosition()==colEnd.getPosition(); assert interval==null || interval.isPoints(); assert propertyKey.longId() == sortKeyIDs[i];
Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name()); if (addMappingParameter) extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter( graph.getIndexSerializer().getDefaultFieldName(key, parameters, indexType.getBackingIndexName())); extendedParas[arrPosition] = ParameterType.STATUS.getParameter(key.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED); throw new JanusGraphException("Could not register new index field '" + key.name() + "' with index backend as the data type, cardinality or parameter combination is not supported."); if (!key.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX);
@Nullable @Override public Long apply(@Nullable PropertyKey propertyKey) { return propertyKey.longId(); } }));
public GraphCentricQueryBuilder has(PropertyKey key, JanusGraphPredicate predicate, Object condition) { Preconditions.checkNotNull(key); return has(key.name(),predicate,condition); }
public AtlasJanusGraph() { //determine multi-properties once at startup JanusGraphManagement mgmt = null; try { mgmt = AtlasJanusGraphDatabase.getGraphInstance().openManagement(); Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class); for (PropertyKey key : keys) { if (key.cardinality() != Cardinality.SINGLE) { multiProperties.add(key.name()); } } } finally { if (mgmt != null) { mgmt.rollback(); } } }
public JanusGraphVertexProperty addProperty(JanusGraphVertex vertex, PropertyKey key, Object value) { return addProperty(key.cardinality().convert(), vertex, key, value); }
public final Object verifyAttribute(PropertyKey key, Object attribute) { if (attribute==null) throw new SchemaViolationException("Property value cannot be null"); Class<?> datatype = key.dataType(); if (datatype.equals(Object.class)) { if (!attributeHandler.validDataType(attribute.getClass())) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(attribute); } return attribute; } else { if (!attribute.getClass().equals(datatype)) { Object converted = null; try { converted = attributeHandler.convert(datatype, attribute); } catch (IllegalArgumentException e) { //Just means that data could not be converted } if (converted == null) throw new SchemaViolationException( "Value [%s] is not an instance of the expected data type for property key [%s] and cannot be converted. Expected: %s, found: %s", attribute, key.name(), datatype, attribute.getClass()); attribute = converted; } assert (attribute.getClass().equals(datatype)); attributeHandler.verifyAttribute(datatype, attribute); return attribute; } }