public static List<Object> convert(final ConnectiveP<?> predicate, final ConnectiveJanusPredicate connectivePredicate) { final List<Object> toReturn = new ArrayList<>(); for (final P<?> p : predicate.getPredicates()){ if (p instanceof ConnectiveP) { final ConnectiveJanusPredicate subPredicate = instanceConnectiveJanusPredicate(p); toReturn.add(convert((ConnectiveP<?>)p, subPredicate)); connectivePredicate.add(subPredicate); } else { connectivePredicate.add(Converter.convert(p.getBiPredicate())); toReturn.add(p.getValue()); } } return toReturn; } }
@Override public void write(Kryo kryo, Output output, P p) { output.writeString( p instanceof ConnectiveP ? (p instanceof AndP ? "and" : "or") : p.getBiPredicate().toString()); if (p instanceof ConnectiveP || p.getValue() instanceof Collection) { output.writeByte((byte) 0); final Collection<?> coll = p instanceof ConnectiveP ? ((ConnectiveP<?>) p).getPredicates() : (Collection) p.getValue(); output.writeInt(coll.size()); coll.forEach(v -> kryo.writeClassAndObject(output, v)); } else { output.writeByte((byte) 1); kryo.writeClassAndObject(output, p.getValue()); } }
if (direction!=null && predicate.getBiPredicate()== Compare.eq && predicate.getValue() instanceof Vertex) { TitanVertex vertex = TitanTraversalUtil.getTitanVertex((Vertex)predicate.getValue());
if (direction != null && predicate.getBiPredicate() == Compare.eq && predicate.getValue() instanceof Vertex) { JanusGraphVertex vertex = JanusGraphTraversalUtil.getJanusGraphVertex((Vertex) predicate.getValue());
public final BiPredicate<?, ?> getBiPredicate() { return this.predicate.getBiPredicate(); }
@Override public boolean equals(final Object other) { return other instanceof P && ((P) other).getClass().equals(this.getClass()) && ((P) other).getBiPredicate().equals(this.biPredicate) && ((((P) other).getOriginalValue() == null && this.originalValue == null) || ((P) other).getOriginalValue().equals(this.originalValue)); }
protected StringBuilder convertPToString(final P p, final StringBuilder current) { if (p instanceof TextP) return convertTextPToString((TextP) p, current); if (p instanceof ConnectiveP) { final List<P<?>> list = ((ConnectiveP) p).getPredicates(); for (int i = 0; i < list.size(); i++) { convertPToString(list.get(i), current); if (i < list.size() - 1) current.append(p instanceof OrP ? ".or(" : ".and("); } current.append(")"); } else current.append("P.").append(p.getBiPredicate().toString()).append("(").append(convertToString(p.getValue())).append(")"); return current; }
private StringBuilder convertPToString(final P p, final StringBuilder current) { if (p instanceof TextP) return convertTextPToString((TextP) p, current); if (p instanceof ConnectiveP) { final List<P<?>> list = ((ConnectiveP) p).getPredicates(); for (int i = 0; i < list.size(); i++) { convertPToString(list.get(i), current); if (i < list.size() - 1) current.append(p instanceof OrP ? ".or_(" : ".and_("); } current.append(")"); } else current.append(convertStatic("P.")).append(p.getBiPredicate().toString()).append("(").append(convertToString(p.getValue())).append(")"); return current; }
private HasContainer getIndexKey(final Class<? extends Element> indexedClass) { final Set<String> indexedKeys = ((TinkerGraph) this.getTraversal().getGraph().get()).getIndexedKeys(indexedClass); final Iterator<HasContainer> itty = IteratorUtils.filter(hasContainers.iterator(), c -> c.getPredicate().getBiPredicate() == Compare.eq && indexedKeys.contains(c.getKey())); return itty.hasNext() ? itty.next() : null; }
@Override protected ByteBuf writeValue(final T value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { // the predicate name is either a static method of P or an instance method when a type ConnectiveP final boolean isConnectedP = value instanceof ConnectiveP; final String predicateName = isConnectedP ? (value instanceof AndP ? "and" : "or") : value.getBiPredicate().toString(); final Object args = isConnectedP ? ((ConnectiveP<?>) value).getPredicates() : value.getValue(); final List<Object> argsAsList = args instanceof Collection ? new ArrayList<>((Collection) args) : Collections.singletonList(args); final int length = argsAsList.size(); final CompositeByteBuf result = allocator.compositeBuffer(2 + length); result.addComponent(true, context.writeValue(predicateName, allocator, false)); result.addComponent(true, context.writeValue(length, allocator, false)); for (Object o : argsAsList) { result.addComponent(true, context.write(o, allocator)); } return result; } }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final P p) { output.writeString(p instanceof ConnectiveP ? (p instanceof AndP ? "and" : "or") : p.getBiPredicate().toString()); if (p instanceof ConnectiveP || p.getValue() instanceof Collection) { output.writeByte((byte) 0); final Collection<?> coll = p instanceof ConnectiveP ? ((ConnectiveP<?>) p).getPredicates() : (Collection) p.getValue(); output.writeInt(coll.size()); coll.forEach(v -> kryo.writeClassAndObject(output, v)); } else { output.writeByte((byte) 1); kryo.writeClassAndObject(output, p.getValue()); } }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final P p) { output.writeString(p instanceof ConnectiveP ? (p instanceof AndP ? "and" : "or") : p.getBiPredicate().toString()); if (p instanceof ConnectiveP || p.getValue() instanceof Collection) { output.writeByte((byte) 0); final Collection<?> coll = p instanceof ConnectiveP ? ((ConnectiveP<?>) p).getPredicates() : (Collection) p.getValue(); output.writeInt(coll.size()); coll.forEach(v -> kryo.writeClassAndObject(output, v)); } else { output.writeByte((byte) 1); kryo.writeClassAndObject(output, p.getValue()); } }
private static Relation convCompare2Relation(HugeGraph graph, HugeType type, HasContainer has) { assert type.isGraph(); BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; boolean isSyspropKey = true; try { string2HugeKey(has.getKey()); } catch (IllegalArgumentException ignored) { isSyspropKey = false; } return isSyspropKey ? convCompare2SyspropRelation(graph, type, has) : convCompare2UserpropRelation(graph, type, has); }
private static Condition convRelationType2Relation(HugeGraph graph, HugeType type, HasContainer has) { assert type.isGraph(); BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof RelationType; String key = has.getKey(); PropertyKey pkey = graph.propertyKey(key); Id pkeyId = pkey.id(); Object value = validPredicateValue(has.getValue(), pkey); return new Condition.UserpropRelation(pkeyId, (RelationType) bp, value); }
@Override public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.PREDICATE, p instanceof ConnectiveP ? p instanceof AndP ? GraphSONTokens.AND : GraphSONTokens.OR : p.getBiPredicate().toString()); if (p instanceof ConnectiveP) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) { jsonGenerator.writeObject(predicate); } jsonGenerator.writeEndArray(); } else jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue()); jsonGenerator.writeEndObject(); }
@Override public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.PREDICATE, p instanceof ConnectiveP ? p instanceof AndP ? GraphSONTokens.AND : GraphSONTokens.OR : p.getBiPredicate().toString()); if (p instanceof ConnectiveP) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) { jsonGenerator.writeObject(predicate); } jsonGenerator.writeEndArray(); } else { if (p.getValue() instanceof Collection) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final Object object : (Collection) p.getValue()) { jsonGenerator.writeObject(object); } jsonGenerator.writeEndArray(); } else jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue()); } jsonGenerator.writeEndObject(); }
public static Condition convHas2Condition(HasContainer has, HugeType type, HugeGraph graph) { P<?> p = has.getPredicate(); E.checkArgument(p != null, "The predicate of has(%s) is null", has); BiPredicate<?, ?> bp = p.getBiPredicate(); Condition condition; if (keyForContainsKeyOrValue(has.getKey())) { condition = convContains2Relation(graph, has); } else if (bp instanceof Compare) { condition = convCompare2Relation(graph, type, has); } else if (bp instanceof RelationType) { condition = convRelationType2Relation(graph, type, has); } else if (bp instanceof Contains) { condition = convIn2Relation(graph, type, has); } else if (p instanceof AndP) { condition = convAnd(graph, type, has); } else if (p instanceof OrP) { condition = convOr(graph, type, has); } else { // TODO: deal with other Predicate throw newUnsupportedPredicate(p); } return condition; }
public static Condition convContains2Relation(HugeGraph graph, HasContainer has) { // Convert contains-key or contains-value BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); E.checkArgument(bp == Compare.eq, "CONTAINS query with relation '%s' is not supported", bp); HugeKeys key = string2HugeKey(has.getKey()); Object value = has.getValue(); if (keyForContainsKey(has.getKey())) { if (value instanceof String) { value = graph.propertyKey((String) value).id(); } return Condition.containsKey(key, value); } else { assert keyForContainsValue(has.getKey()); return Condition.contains(key, value); } }
private static Relation convCompare2SyspropRelation(HugeGraph graph, HugeType type, HasContainer has) { BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; HugeKeys key = string2HugeKey(has.getKey()); Object value = convSysValueIfNeeded(graph, type, key, has.getValue()); switch ((Compare) bp) { case eq: return Condition.eq(key, value); case gt: return Condition.gt(key, value); case gte: return Condition.gte(key, value); case lt: return Condition.lt(key, value); case lte: return Condition.lte(key, value); case neq: return Condition.neq(key, value); } throw newUnsupportedPredicate(has.getPredicate()); }
private static Relation convCompare2UserpropRelation(HugeGraph graph, HugeType type, HasContainer has) { BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate(); assert bp instanceof Compare; String key = has.getKey(); PropertyKey pkey = graph.propertyKey(key); Id pkeyId = pkey.id(); Object value = validPredicateValue(has.getValue(), pkey); switch ((Compare) bp) { case eq: return Condition.eq(pkeyId, value); case gt: return Condition.gt(pkeyId, value); case gte: return Condition.gte(pkeyId, value); case lt: return Condition.lt(pkeyId, value); case lte: return Condition.lte(pkeyId, value); case neq: return Condition.neq(pkeyId, value); } throw newUnsupportedPredicate(has.getPredicate()); }