Search in sources :

Example 1 with DataType

use of ai.grakn.concept.AttributeType.DataType in project grakn by graknlabs.

the class ComparatorPredicate method applyPredicate.

@Override
public final <S, E> GraphTraversal<S, E> applyPredicate(GraphTraversal<S, E> traversal) {
    var.ifPresent(theVar -> {
        // Compare to another variable
        String thisVar = UUID.randomUUID().toString();
        Var otherVar = theVar.var();
        String otherValue = UUID.randomUUID().toString();
        Traversal[] traversals = Stream.of(VALUE_PROPERTIES).map(prop -> __.values(prop).as(otherValue).select(thisVar).values(prop).where(gremlinPredicate(otherValue))).toArray(Traversal[]::new);
        traversal.as(thisVar).select(otherVar.name()).or(traversals).select(thisVar);
    });
    persistedValue().ifPresent(theValue -> {
        // Compare to a given value
        DataType<?> dataType = DataType.SUPPORTED_TYPES.get(value().get().getClass().getTypeName());
        Schema.VertexProperty property = dataType.getVertexProperty();
        traversal.has(property.name(), gremlinPredicate(theValue));
    });
    return traversal;
}
Also used : GraqlQueryException(ai.grakn.exception.GraqlQueryException) VarPattern(ai.grakn.graql.VarPattern) StringUtil(ai.grakn.util.StringUtil) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) UUID(java.util.UUID) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ValuePredicate(ai.grakn.graql.ValuePredicate) Stream(java.util.stream.Stream) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Var(ai.grakn.graql.Var) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Optional(java.util.Optional) DataType(ai.grakn.concept.AttributeType.DataType) Schema(ai.grakn.util.Schema) P(org.apache.tinkerpop.gremlin.process.traversal.P) Var(ai.grakn.graql.Var) Schema(ai.grakn.util.Schema) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal)

Aggregations

DataType (ai.grakn.concept.AttributeType.DataType)1 GraqlQueryException (ai.grakn.exception.GraqlQueryException)1 ValuePredicate (ai.grakn.graql.ValuePredicate)1 Var (ai.grakn.graql.Var)1 VarPattern (ai.grakn.graql.VarPattern)1 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)1 Schema (ai.grakn.util.Schema)1 StringUtil (ai.grakn.util.StringUtil)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Stream (java.util.stream.Stream)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)1