public static boolean hasGenericDataType(PropertyKey key) { return key.dataType().equals(Object.class); } }
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; }
private void writePropertyValue(DataOutput out, PropertyKey key, Object value, InlineType inlineType) { if (AttributeUtil.hasGenericDataType(key)) { assert !inlineType.writeByteOrdered(); out.writeClassAndObject(value); } else { assert value==null || value.getClass().equals(key.dataType()); if (inlineType.writeByteOrdered()) out.writeObjectByteOrder(value, key.dataType()); else out.writeObject(value, key.dataType()); } }
private long[] checkSortKey(List<PropertyKey> sig) { for (PropertyKey key : sig) { Preconditions.checkArgument(attributeHandler.isOrderPreservingDatatype(key.dataType()), "Key must have an order-preserving data type to be used as sort key: " + key); } return checkSignature(sig); }
@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); 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; }
private Object readPropertyValue(ReadBuffer read, PropertyKey key, InlineType inlineType) { if (AttributeUtil.hasGenericDataType(key)) { return serializer.readClassAndObject(read); } else { if (inlineType.writeByteOrdered()) return serializer.readObjectByteOrder(read, key.dataType()); else return serializer.readObject(read, key.dataType()); } }
@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(); }
public PropertyKeyDefinition(PropertyKey key) { this(key.name(),key.longId(),key.cardinality(),key.dataType()); }
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; } }
public static GraphCentricQueryBuilder getQuery(CompositeIndexType index, Object[] values, StandardTitanTx tx) { Preconditions.checkArgument(index != null && values != null && values.length > 0 && tx != null); Preconditions.checkArgument(values.length==index.getFieldKeys().length); GraphCentricQueryBuilder gb = tx.query(); IndexField[] fields = index.getFieldKeys(); for (int i = 0; i <fields.length; i++) { IndexField f = fields[i]; Object value = values[i]; Preconditions.checkNotNull(value); PropertyKey key = f.getFieldKey(); Preconditions.checkArgument(key.dataType().equals(value.getClass()),"Incompatible data types for: " + value); gb.has(key, Cmp.EQUAL,value); } if (index.hasSchemaTypeConstraint()) { gb.has(ImplicitKey.LABEL,Cmp.EQUAL,index.getSchemaTypeConstraint().name()); } return gb; } }
private final StaticBuffer getIndexKey(CompositeIndexType index, Object[] values) { DataOutput out = serializer.getDataOutput(8*DEFAULT_OBJECT_BYTELEN + 8); VariableLong.writePositive(out, index.getID()); IndexField[] fields = index.getFieldKeys(); Preconditions.checkArgument(fields.length>0 && fields.length==values.length); for (int i = 0; i < fields.length; i++) { IndexField f = fields[i]; Object value = values[i]; Preconditions.checkNotNull(value); if (AttributeUtil.hasGenericDataType(f.getFieldKey())) { out.writeClassAndObject(value); } else { assert value.getClass().equals(f.getFieldKey().dataType()) : value.getClass() + " - " + f.getFieldKey().dataType(); out.writeObjectNotNull(value); } } StaticBuffer key = out.getStaticBuffer(); if (hashKeys) key = HashingUtil.hashPrefixKey(hashLength,key); return key; }
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; }
PropertyKey key = (PropertyKey) type; assert predicate.isValidCondition(value); Preconditions.checkArgument(key.dataType()==Object.class || predicate.isValidValueType(key.dataType()), "Data type of key is not compatible with condition"); } else { //its a label Preconditions.checkArgument(((EdgeLabel) type).isUnidirected());
public IndexQuery getQuery(final MixedIndexType index, final Condition condition, final OrderList orders) { Condition newCondition = ConditionUtil.literalTransformation(condition, new Function<Condition<TitanElement>, Condition<TitanElement>>() { @Nullable @Override public Condition<TitanElement> apply(@Nullable Condition<TitanElement> condition) { Preconditions.checkArgument(condition instanceof PredicateCondition); PredicateCondition pc = (PredicateCondition) condition; PropertyKey key = (PropertyKey) pc.getKey(); return new PredicateCondition<String, TitanElement>(key2Field(index,key), pc.getPredicate(), pc.getValue()); } }); ImmutableList<IndexQuery.OrderEntry> newOrders = IndexQuery.NO_ORDER; if (!orders.isEmpty() && GraphCentricQueryBuilder.indexCoversOrder(index,orders)) { ImmutableList.Builder<IndexQuery.OrderEntry> lb = ImmutableList.builder(); for (int i = 0; i < orders.size(); i++) { lb.add(new IndexQuery.OrderEntry(key2Field(index,orders.getKey(i)), orders.getOrder(i), orders.getKey(i).dataType())); } newOrders = lb.build(); } return new IndexQuery(index.getStoreName(), newCondition, newOrders); } //
assert direction == Direction.OUT; StandardPropertyKeyMaker lm = (StandardPropertyKeyMaker) transaction.makePropertyKey(composedName); lm.dataType(((PropertyKey) type).dataType()); maker = lm;
assert key.dataType().equals(p.value().getClass()) : key + " -> " + p; values.add(new RecordEntry(p));
if (!o1.equals(o2)) { int objectcompare = 0; if (Comparable.class.isAssignableFrom(((PropertyKey) t1).dataType())) { objectcompare = ((Comparable) o1).compareTo(o2); } else {
Preconditions.checkNotNull(value); PropertyKey key = (PropertyKey) type; assert key.dataType().isInstance(value);
assertEquals(Multiplicity.MULTI,knows.multiplicity()); assertFalse(person.isPartitioned()); assertEquals(Integer.class,uid.dataType());