Java Code Examples for com.thinkaurelius.titan.core.attribute.Cmp

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.attribute.Cmp. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 6 votes vote down vote up
private void testInstant(Instant firstTimestamp, Instant secondTimestamp, TitanVertex v1, TitanVertex v2) {
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp)));


    clopen();//Flush the index
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp)));
}
 
Example 2
Project: titan1withtp3.1   File: TitanPredicate.java   Source Code and License 6 votes vote down vote up
/**
 * Convert Tinkerpop's comparison operators to Titan's
 *
 * @param p Any predicate
 * @return A TitanPredicate equivalent to the given predicate
 * @throws IllegalArgumentException if the given Predicate is unknown
 */
public static final TitanPredicate convertInternal(BiPredicate p) {
    if (p instanceof TitanPredicate) {
        return (TitanPredicate)p;
    } else if (p instanceof Compare) {
        Compare comp = (Compare)p;
        switch(comp) {
            case eq: return Cmp.EQUAL;
            case neq: return Cmp.NOT_EQUAL;
            case gt: return Cmp.GREATER_THAN;
            case gte: return Cmp.GREATER_THAN_EQUAL;
            case lt: return Cmp.LESS_THAN;
            case lte: return Cmp.LESS_THAN_EQUAL;
            default: throw new IllegalArgumentException("Unexpected comparator: " + comp);
        }
    } else if (p instanceof Contains) {
        Contains con = (Contains)p;
        switch (con) {
            case within: return Contain.IN;
            case without: return Contain.NOT_IN;
            default: throw new IllegalArgumentException("Unexpected container: " + con);

        }
    } else return null;
}
 
Example 3
Project: titan1withtp3.1   File: BaseVertexCentricQueryBuilder.java   Source Code and License 6 votes vote down vote up
private Q addConstraint(String type, TitanPredicate rel, Object value) {
    Preconditions.checkArgument(type != null && StringUtils.isNotBlank(type) && rel != null);
    //Treat special cases
    if (type.equals(ImplicitKey.ADJACENT_ID.name())) {
        Preconditions.checkArgument(rel == Cmp.EQUAL, "Only equality constraints are supported for %s", type);
        long vertexId = ElementUtils.getVertexId(value);
        Preconditions.checkArgument(vertexId > 0, "Expected valid vertex id: %s", value);
        return adjacent(getVertex(vertexId));
    } else if (type.equals(ImplicitKey.ID.name())) {
        RelationIdentifier rid = ElementUtils.getEdgeId(value);
        Preconditions.checkArgument(rid != null, "Expected valid relation id: %s", value);
        return addConstraint(ImplicitKey.TITANID.name(), rel, rid.getRelationId());
    } else {
        Preconditions.checkArgument(rel.isValidCondition(value), "Invalid condition provided: " + value);
    }
    if (constraints == NO_CONSTRAINTS) constraints = new ArrayList<PredicateCondition<String, TitanRelation>>(5);
    constraints.add(new PredicateCondition<String, TitanRelation>(type, rel, value));
    return getThis();
}
 
Example 4
Project: titan1withtp3.1   File: GraphCentricQueryBuilder.java   Source Code and License 6 votes vote down vote up
private static final Map.Entry<Condition,Collection<Object>> getEqualityConditionValues(Condition<TitanElement> condition, RelationType type) {
    for (Condition c : condition.getChildren()) {
        if (c instanceof Or) {
            Map.Entry<RelationType,Collection> orEqual = QueryUtil.extractOrCondition((Or)c);
            if (orEqual!=null && orEqual.getKey().equals(type) && !orEqual.getValue().isEmpty()) {
                return new AbstractMap.SimpleImmutableEntry(c,orEqual.getValue());
            }
        } else if (c instanceof PredicateCondition) {
            PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c;
            if (atom.getKey().equals(type) && atom.getPredicate()==Cmp.EQUAL && atom.getValue()!=null) {
                return new AbstractMap.SimpleImmutableEntry(c,ImmutableList.of(atom.getValue()));
            }
        }

    }
    return null;
}
 
Example 5
Project: titan1withtp3.1   File: IndexHelper.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 6
Project: incubator-atlas   File: GraphCentricQueryBuilder.java   Source Code and License 6 votes vote down vote up
private static final Map.Entry<Condition, Collection<Object>> getEqualityConditionValues(Condition<TitanElement> condition, RelationType type) {
    for (Condition c : condition.getChildren()) {
        if (c instanceof Or) {
            Map.Entry<RelationType, Collection> orEqual = QueryUtil.extractOrCondition((Or)c);
            if (orEqual!=null && orEqual.getKey().equals(type) && !orEqual.getValue().isEmpty()) {
                return new AbstractMap.SimpleImmutableEntry(c, orEqual.getValue());
            }
        } else if (c instanceof PredicateCondition) {
            PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c;
            if (atom.getKey().equals(type) && atom.getPredicate()==Cmp.EQUAL && atom.getValue()!=null) {
                return new AbstractMap.SimpleImmutableEntry(c, ImmutableList.of(atom.getValue()));
            }
        }

    }
    return null;
}
 
Example 7
Project: titan1.0.1.kafka   File: TitanIndexTest.java   Source Code and License 6 votes vote down vote up
private void testInstant(Instant firstTimestamp, Instant secondTimestamp, TitanVertex v1, TitanVertex v2) {
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp)));


    clopen();//Flush the index
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp)));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp)));
}
 
Example 8
Project: titan1.0.1.kafka   File: TitanPredicate.java   Source Code and License 6 votes vote down vote up
/**
 * Convert Tinkerpop's comparison operators to Titan's
 *
 * @param p Any predicate
 * @return A TitanPredicate equivalent to the given predicate
 * @throws IllegalArgumentException if the given Predicate is unknown
 */
public static final TitanPredicate convertInternal(BiPredicate p) {
    if (p instanceof TitanPredicate) {
        return (TitanPredicate)p;
    } else if (p instanceof Compare) {
        Compare comp = (Compare)p;
        switch(comp) {
            case eq: return Cmp.EQUAL;
            case neq: return Cmp.NOT_EQUAL;
            case gt: return Cmp.GREATER_THAN;
            case gte: return Cmp.GREATER_THAN_EQUAL;
            case lt: return Cmp.LESS_THAN;
            case lte: return Cmp.LESS_THAN_EQUAL;
            default: throw new IllegalArgumentException("Unexpected comparator: " + comp);
        }
    } else if (p instanceof Contains) {
        Contains con = (Contains)p;
        switch (con) {
            case within: return Contain.IN;
            case without: return Contain.NOT_IN;
            default: throw new IllegalArgumentException("Unexpected container: " + con);

        }
    } else return null;
}
 
Example 9
Project: titan1.0.1.kafka   File: BaseVertexCentricQueryBuilder.java   Source Code and License 6 votes vote down vote up
private Q addConstraint(String type, TitanPredicate rel, Object value) {
    Preconditions.checkArgument(type != null && StringUtils.isNotBlank(type) && rel != null);
    //Treat special cases
    if (type.equals(ImplicitKey.ADJACENT_ID.name())) {
        Preconditions.checkArgument(rel == Cmp.EQUAL, "Only equality constraints are supported for %s", type);
        long vertexId = ElementUtils.getVertexId(value);
        Preconditions.checkArgument(vertexId > 0, "Expected valid vertex id: %s", value);
        return adjacent(getVertex(vertexId));
    } else if (type.equals(ImplicitKey.ID.name())) {
        RelationIdentifier rid = ElementUtils.getEdgeId(value);
        Preconditions.checkArgument(rid != null, "Expected valid relation id: %s", value);
        return addConstraint(ImplicitKey.TITANID.name(), rel, rid.getRelationId());
    } else {
        Preconditions.checkArgument(rel.isValidCondition(value), "Invalid condition provided: " + value);
    }
    if (constraints == NO_CONSTRAINTS) constraints = new ArrayList<PredicateCondition<String, TitanRelation>>(5);
    constraints.add(new PredicateCondition<String, TitanRelation>(type, rel, value));
    return getThis();
}
 
Example 10
Project: titan1.0.1.kafka   File: GraphCentricQueryBuilder.java   Source Code and License 6 votes vote down vote up
private static final Map.Entry<Condition,Collection<Object>> getEqualityConditionValues(Condition<TitanElement> condition, RelationType type) {
    for (Condition c : condition.getChildren()) {
        if (c instanceof Or) {
            Map.Entry<RelationType,Collection> orEqual = QueryUtil.extractOrCondition((Or)c);
            if (orEqual!=null && orEqual.getKey().equals(type) && !orEqual.getValue().isEmpty()) {
                return new AbstractMap.SimpleImmutableEntry(c,orEqual.getValue());
            }
        } else if (c instanceof PredicateCondition) {
            PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c;
            if (atom.getKey().equals(type) && atom.getPredicate()==Cmp.EQUAL && atom.getValue()!=null) {
                return new AbstractMap.SimpleImmutableEntry(c,ImmutableList.of(atom.getValue()));
            }
        }

    }
    return null;
}
 
Example 11
Project: titan1.0.1.kafka   File: IndexHelper.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 12
Project: titan0.5.4-hbase1.1.1-custom   File: GraphCentricQueryBuilder.java   Source Code and License 6 votes vote down vote up
private static final Map.Entry<Condition,Collection<Object>> getEqualityConditionValues(Condition<TitanElement> condition, RelationType type) {
    for (Condition c : condition.getChildren()) {
        if (c instanceof Or) {
            Map.Entry<RelationType,Collection> orEqual = QueryUtil.extractOrCondition((Or)c);
            if (orEqual!=null && orEqual.getKey().equals(type) && !orEqual.getValue().isEmpty()) {
                return new AbstractMap.SimpleImmutableEntry(c,orEqual.getValue());
            }
        } else if (c instanceof PredicateCondition) {
            PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition)c;
            if (atom.getKey().equals(type) && atom.getPredicate()==Cmp.EQUAL && atom.getValue()!=null) {
                return new AbstractMap.SimpleImmutableEntry(c,ImmutableList.of(atom.getValue()));
            }
        }

    }
    return null;
}
 
Example 13
Project: titan0.5.4-hbase1.1.1-custom   File: IndexHelper.java   Source Code and License 6 votes vote down vote up
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.getDataType().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().getName());
    }
    return gb;
}
 
Example 14
Project: ldbc_snb_implementations   File: TitanFTMDb.java   Source Code and License 6 votes vote down vote up
/**
 * Gets the specified vertices or null if no such vertex is found
 *
 * @param property name
 * @param label    vertex type label
 * @param value    value in property field
 * @param limit    int value limiting the result. use Integer.MAX_VALUE for unlimited
 * @return the specified vertices or null if no such vertex is found
 */
public Set<Vertex> getVertices(String label, String property, Object value, int limit) throws SchemaViolationException {
    Integer suffix = s.getVertexTypes().get(label);
    Set<Vertex> res = new HashSet<>();
    if (suffix == null)
        throw new SchemaViolationException(label + " vertex type is not defined in the schema for " + s.getClass().getSimpleName());

    Iterable<Vertex> qres;
    GraphQuery q = g.query().has("label", label).has(property, Cmp.EQUAL, value);
    if (limit == Integer.MAX_VALUE)
        qres = q.vertices();
    else
        qres = q.limit(limit).vertices();

    for (Vertex v : qres)
        res.add(v);

    return res;
}
 
Example 15
Project: incubator-blur   File: BlurIndex.java   Source Code and License 6 votes vote down vote up
private final String getQueryString(String family, String key, Cmp relation, Number value) {
  String columnName = getColumnName(family, key);
  switch (relation) {
  case EQUAL:
    return columnName + ":" + value;
  case NOT_EQUAL:
    return "-(" + columnName + ":" + value + ")";
  case LESS_THAN:
    return columnName + ":[MIN TO " + value + "}";
  case LESS_THAN_EQUAL:
    return columnName + ":[MIN TO " + value + "]";
  case GREATER_THAN:
    return columnName + ":{" + value + " TO MAX]";
  case GREATER_THAN_EQUAL:
    return columnName + ":[" + value + " TO MAX]";
  default:
    throw new IllegalArgumentException("Unexpected relation: " + relation);
  }
}
 
Example 16
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testVertexCentricIndexWithNull() {
    EdgeLabel bought = makeLabel("bought");
    PropertyKey time = makeKey("time", Long.class);
    mgmt.buildEdgeIndex(bought, "byTimeDesc", BOTH, decr, time);
    mgmt.buildEdgeIndex(bought, "byTimeIncr", BOTH, incr, time);
    finishSchema();

    TitanVertex v1 = tx.addVertex(), v2 = tx.addVertex();
    v1.addEdge("bought", v2).property("time", 1);
    v1.addEdge("bought", v2).property("time", 2);
    v1.addEdge("bought", v2).property("time", 3);
    v1.addEdge("bought", v2);
    v1.addEdge("bought", v2);

    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());


    newTx();
    v1 = tx.getVertex(v1.longId());
    //Queries copied from above

    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
}
 
Example 17
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 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 18
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 5 votes vote down vote up
/**
 * Tests indexing dates
 */
@Test
public void testDateIndexing() {
    PropertyKey name = makeKey("date", Date.class);
    mgmt.buildIndex("dateIndex", Vertex.class).
            addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();

    TitanVertex v1 = graph.addVertex();
    v1.property("date", new Date(1));

    TitanVertex v2 = graph.addVertex();
    v2.property("date", new Date(2000));


    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));

    clopen();//Flush the index
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));


}
 
Example 19
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 5 votes vote down vote up
/**
 * Tests indexing boolean
 */
@Test
public void testUUIDIndexing() {
    PropertyKey name = makeKey("uid", UUID.class);
    mgmt.buildIndex("uuidIndex", Vertex.class).
            addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();

    UUID uid1 = UUID.randomUUID();
    UUID uid2 = UUID.randomUUID();

    TitanVertex v1 = graph.addVertex();
    v1.property("uid", uid1);

    TitanVertex v2 = graph.addVertex();
    v2.property("uid", uid2);

    assertCount(2, graph.query().vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
    assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));

    assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));

    clopen();//Flush the index
    assertCount(2, graph.query().vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
    assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));

    assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));

}
 
Example 20
Project: titan1withtp3.1   File: TitanOperationCountingTest.java   Source Code and License 5 votes vote down vote up
@Test
public void checkPropertyLockingAndIndex() {
    PropertyKey uid = makeKey("uid",String.class);
    TitanGraphIndex index = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex();
    mgmt.setConsistency(index, ConsistencyModifier.LOCK);
    mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.makePropertyKey("age").dataType(Integer.class).make();
    finishSchema();

    metricsPrefix = "checkPropertyLockingAndIndex";

    TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start();
    TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john");
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME);
    verifyLockingOverwrite(INDEXSTORE_NAME, 1);
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l));

    resetMetrics();

    tx = graph.buildTransaction().groupName(metricsPrefix).start();
    v = Iterables.getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices());
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME);
}
 
Example 21
Project: incubator-atlas   File: Solr5Index.java   Source Code and License 5 votes vote down vote up
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
    Class<?> dataType = information.getDataType();
    Mapping mapping = getMapping(information);
    if (mapping!= DEFAULT && !AttributeUtil.isString(dataType)) return false;

    if (Number.class.isAssignableFrom(dataType)) {
        return titanPredicate instanceof Cmp;
    } else if (dataType == Geoshape.class) {
        return titanPredicate == Geo.WITHIN;
    } else if (AttributeUtil.isString(dataType)) {
        switch(mapping) {
            case DEFAULT:
            case TEXT:
                return titanPredicate == Text.CONTAINS || titanPredicate == Text.CONTAINS_PREFIX || titanPredicate == Text.CONTAINS_REGEX;
            case STRING:
                return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL || titanPredicate==Text.REGEX || titanPredicate==Text.PREFIX;
            //                case TEXTSTRING:
            //                    return (titanPredicate instanceof Text) || titanPredicate == Cmp.EQUAL || titanPredicate==Cmp.NOT_EQUAL;
        }
    } else if (dataType == Date.class) {
        if (titanPredicate instanceof Cmp) return true;
    } else if (dataType == Boolean.class) {
        return titanPredicate == EQUAL || titanPredicate == NOT_EQUAL;
    } else if (dataType == UUID.class) {
        return titanPredicate == EQUAL || titanPredicate== NOT_EQUAL;
    }
    return false;
}
 
Example 22
Project: titan1.0.1.kafka   File: TitanGraphTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testVertexCentricIndexWithNull() {
    EdgeLabel bought = makeLabel("bought");
    PropertyKey time = makeKey("time", Long.class);
    mgmt.buildEdgeIndex(bought, "byTimeDesc", BOTH, decr, time);
    mgmt.buildEdgeIndex(bought, "byTimeIncr", BOTH, incr, time);
    finishSchema();

    TitanVertex v1 = tx.addVertex(), v2 = tx.addVertex();
    v1.addEdge("bought", v2).property("time", 1);
    v1.addEdge("bought", v2).property("time", 2);
    v1.addEdge("bought", v2).property("time", 3);
    v1.addEdge("bought", v2);
    v1.addEdge("bought", v2);

    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());


    newTx();
    v1 = tx.getVertex(v1.longId());
    //Queries copied from above

    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
}
 
Example 23
Project: titan1.0.1.kafka   File: TitanIndexTest.java   Source Code and License 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 24
Project: titan1.0.1.kafka   File: TitanIndexTest.java   Source Code and License 5 votes vote down vote up
/**
 * Tests indexing dates
 */
@Test
public void testDateIndexing() {
    PropertyKey name = makeKey("date", Date.class);
    mgmt.buildIndex("dateIndex", Vertex.class).
            addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();

    TitanVertex v1 = graph.addVertex();
    v1.property("date", new Date(1));

    TitanVertex v2 = graph.addVertex();
    v2.property("date", new Date(2000));


    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));

    clopen();//Flush the index
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));


}
 
Example 25
Project: titan1.0.1.kafka   File: TitanIndexTest.java   Source Code and License 5 votes vote down vote up
/**
 * Tests indexing boolean
 */
@Test
public void testUUIDIndexing() {
    PropertyKey name = makeKey("uid", UUID.class);
    mgmt.buildIndex("uuidIndex", Vertex.class).
            addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();

    UUID uid1 = UUID.randomUUID();
    UUID uid2 = UUID.randomUUID();

    TitanVertex v1 = graph.addVertex();
    v1.property("uid", uid1);

    TitanVertex v2 = graph.addVertex();
    v2.property("uid", uid2);

    assertCount(2, graph.query().vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
    assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));

    assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));

    clopen();//Flush the index
    assertCount(2, graph.query().vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1)));
    assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2)));

    assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1)));
    assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2)));

}
 
Example 26
Project: titan1.0.1.kafka   File: TitanOperationCountingTest.java   Source Code and License 5 votes vote down vote up
@Test
public void checkPropertyLockingAndIndex() {
    PropertyKey uid = makeKey("uid",String.class);
    TitanGraphIndex index = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex();
    mgmt.setConsistency(index, ConsistencyModifier.LOCK);
    mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.makePropertyKey("age").dataType(Integer.class).make();
    finishSchema();

    metricsPrefix = "checkPropertyLockingAndIndex";

    TitanTransaction tx = graph.buildTransaction().groupName(metricsPrefix).start();
    TitanVertex v = tx.addVertex("uid", "v1", "age", 25, "name", "john");
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME);
    verifyLockingOverwrite(INDEXSTORE_NAME, 1);
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME, ImmutableMap.of(M_MUTATE, 1l));

    resetMetrics();

    tx = graph.buildTransaction().groupName(metricsPrefix).start();
    v = Iterables.getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices());
    assertEquals(25,v.property("age").value());
    tx.commit();
    verifyStoreMetrics(EDGESTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(INDEXSTORE_NAME, ImmutableMap.of(M_GET_SLICE,1l));
    verifyStoreMetrics(METRICS_STOREMANAGER_NAME);
}
 
Example 27
Project: titan0.5.4-hbase1.1.1-custom   File: BaseVertexCentricQueryBuilder.java   Source Code and License 5 votes vote down vote up
private Q addConstraint(String type, TitanPredicate rel, Object value) {
    Preconditions.checkArgument(type!=null && StringUtils.isNotBlank(type) && rel!=null);
    //Treat special cases
    if (type.equals(ImplicitKey.ADJACENT_ID.getName())) {
        Preconditions.checkArgument(rel == Cmp.EQUAL,"Only equality constraints are supported for %s",type);
        Preconditions.checkArgument(value instanceof Number,"Expected valid vertex id: %s",value);
        return adjacent(getVertex(((Number)value).longValue()));
    } else if (type.equals(ImplicitKey.ID.getName())) {
        Preconditions.checkArgument(value instanceof RelationIdentifier,"Expected valid relation id: %s",value);
        return addConstraint(ImplicitKey.TITANID.getName(),rel,((RelationIdentifier)value).getRelationId());
    }
    if (constraints==NO_CONSTRAINTS) constraints = new ArrayList<PredicateCondition<String, TitanRelation>>(5);
    constraints.add(new PredicateCondition<String, TitanRelation>(type, rel, value));
    return getThis();
}
 
Example 28
Project: angulillos-titan   File: TitanConversions.java   Source Code and License 5 votes vote down vote up
public static final Cmp asTitanCmp(QueryPredicate.Compare predicate) {

      switch(predicate) {
        case EQUAL:              return Cmp.EQUAL;
        case NOT_EQUAL:          return Cmp.NOT_EQUAL;
        case GREATER_THAN:       return Cmp.GREATER_THAN;
        case GREATER_THAN_EQUAL: return Cmp.GREATER_THAN_EQUAL;
        case LESS_THAN:          return Cmp.LESS_THAN;
        case LESS_THAN_EQUAL:    return Cmp.LESS_THAN_EQUAL;
        // NOTE: this shouldn't happen, because we pattern match on all cases of a sealed enum
        default:                 return Cmp.EQUAL;
      }
    }
 
Example 29
Project: ldbc_snb_implementations   File: TitanFTMDb.java   Source Code and License 5 votes vote down vote up
/**
 * Gets the specified vertices or null if no such vertex is found
 *
 * @param property name
 * @param value    value in property field
 * @param limit    int value limiting the result. use Integer.MAX_VALUE for unlimited
 * @return the specified vertices or null if no such vertex is found
 */
@SuppressWarnings("unchecked")
public Iterable<Vertex> getVertices(String property, String value, int limit) {
    if (limit == Integer.MAX_VALUE)
        return g.query().has(value, Cmp.EQUAL, value).vertices();
    else
        return g.query().has(property, Cmp.EQUAL, value).limit(limit).vertices();

}
 
Example 30
Project: incubator-blur   File: BlurIndex.java   Source Code and License 5 votes vote down vote up
@Override
public boolean supports(Class<?> dataType, Relation relation) {
  if (Number.class.isAssignableFrom(dataType)) {
    if (relation instanceof Cmp) {
      return true;
    }
  } else if (dataType == Geoshape.class) {
    return relation == Geo.INTERSECT;
  } else if (dataType == String.class) {
    return relation == Text.CONTAINS;
  }
  return false;
}
 
Example 31
Project: titan1withtp3.1   File: TitanGraphTest.java   Source Code and License 4 votes vote down vote up
/**
 * Iterating over all vertices and edges in a graph
 */
@Test
public void testGlobalIteration() {
    int numV = 50;
    int deleteV = 5;

    TitanVertex previous = tx.addVertex("count", 0);
    for (int i = 1; i < numV; i++) {
        TitanVertex next = tx.addVertex("count", i);
        previous.addEdge("next", next);
        previous = next;
    }
    int numE = numV - 1;
    assertCount(numV, tx.query().vertices());
    assertCount(numV, tx.query().vertices());
    assertCount(numE, tx.query().edges());
    assertCount(numE, tx.query().edges());

    clopen();

    assertCount(numV, tx.query().vertices());
    assertCount(numV, tx.query().vertices());
    assertCount(numE, tx.query().edges());
    assertCount(numE, tx.query().edges());

    //tx.V().range(0,deleteV).remove();
    for (TitanVertex v : tx.query().limit(deleteV).vertices()) {
        v.remove();
    }

    for (int i = 0; i < 10; i++) { //Repeated vertex counts
        assertCount(numV - deleteV, tx.query().vertices());
        assertCount(numV - deleteV, tx.query().has("count", Cmp.GREATER_THAN_EQUAL, 0).vertices());
    }

    clopen();
    for (int i = 0; i < 10; i++) { //Repeated vertex counts
        assertCount(numV - deleteV, tx.query().vertices());
        assertCount(numV - deleteV, tx.query().has("count", Cmp.GREATER_THAN_EQUAL, 0).vertices());
    }
}
 
Example 32
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testCompositeAndMixedIndexing() {
    PropertyKey name = makeKey("name", String.class);
    PropertyKey weight = makeKey("weight", Double.class);
    PropertyKey text = makeKey("text", String.class);
    PropertyKey flag = makeKey("flag", Boolean.class);

    TitanGraphIndex composite = mgmt.buildIndex("composite", Vertex.class).addKey(name).addKey(weight).buildCompositeIndex();
    TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(weight)
            .addKey(text, getTextMapping()).buildMixedIndex(INDEX);
    mixed.name();
    composite.name();
    finishSchema();

    final int numV = 100;
    String[] strs = {"houseboat", "humanoid", "differential", "extraordinary"};
    String[] strs2 = new String[strs.length];
    for (int i = 0; i < strs.length; i++) strs2[i] = strs[i] + " " + strs[i];
    final int modulo = 5;
    final int divisor = modulo * strs.length;

    for (int i = 0; i < numV; i++) {
        TitanVertex v = tx.addVertex();
        v.property("name", strs[i % strs.length]);
        v.property("text", strs[i % strs.length]);
        v.property("weight", (i % modulo) + 0.5);
        v.property("flag", true);
    }

    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true});
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("flag"), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, composite.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name(), composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name(), composite.name());

    clopen();

    //Same queries as above
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true});
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("flag"), ElementCategory.VERTEX,
            numV / strs.length, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, composite.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{true, true}, mixed.name(), composite.name());
    evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX,
            numV / divisor, new boolean[]{false, true}, mixed.name(), composite.name());

}
 
Example 33
Project: titan1withtp3.1   File: TitanIndexTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testDualMapping() {
    if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) return;

    PropertyKey name = makeKey("name", String.class);
    TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX);
    mixed.name();
    finishSchema();


    tx.addVertex("name", "Long John Don");
    tx.addVertex("name", "Long Little Lewis");
    tx.addVertex("name", "Middle Sister Mabel");

    clopen();
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "Long John Don"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX,
            2, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long Don"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS_PREFIX, "Lon"), ElementCategory.VERTEX,
            2, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS_REGEX, "Lit*le"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.REGEX, "Long.*"), ElementCategory.VERTEX,
            2, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");

    for (Vertex u : tx.getVertices()) {
        String n = u.<String>value("name");
        if (n.endsWith("Don")) {
            u.remove();
        } else if (n.endsWith("Lewis")) {
            u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob");
        } else if (n.endsWith("Mabel")) {
            u.property("name").remove();
        }
    }

    clopen();

    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX,
            0, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "Big"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Big"), ElementCategory.VERTEX,
            1, new boolean[]{true, true}, "mixed");
    evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX,
            0, new boolean[]{true, true}, "mixed");

}
 
Example 34
Project: titan1withtp3.1   File: TextTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testContains() {
    String text = "This world is full of 1funny surprises! A Full Yes";
    //Contains
    assertTrue(CONTAINS.test(text, "world"));
    assertTrue(CONTAINS.test(text, "wOrLD"));
    assertFalse(CONTAINS.test(text, "worl"));

    assertTrue(CONTAINS.test(text, "this"));
    assertTrue(CONTAINS.test(text, "yes"));
    assertFalse(CONTAINS.test(text, "funny"));

    assertFalse(CONTAINS.test(text, "a"));
    assertFalse(CONTAINS.test(text, "A"));

    assertTrue(CONTAINS.test(text, "surprises"));
    assertTrue(CONTAINS.test(text, "FULL"));

    assertTrue(CONTAINS.test(text, "full surprises"));
    assertTrue(CONTAINS.test(text, "full,surprises,world"));
    assertFalse(CONTAINS.test(text, "full bunny"));
    assertTrue(CONTAINS.test(text, "a world"));



    //Prefix
    assertTrue(CONTAINS_PREFIX.test(text, "worl"));
    assertTrue(CONTAINS_PREFIX.test(text, "wORl"));
    assertTrue(CONTAINS_PREFIX.test(text, "ye"));
    assertTrue(CONTAINS_PREFIX.test(text, "Y"));

    assertFalse(CONTAINS_PREFIX.test(text, "fo"));
    assertFalse(CONTAINS_PREFIX.test(text, "of 1f"));
    assertFalse(CONTAINS_PREFIX.test(text, "ses"));


    //Regex
    assertTrue(CONTAINS_REGEX.test(text, "fu[l]+"));
    assertTrue(CONTAINS_REGEX.test(text, "wor[ld]{1,2}"));
    assertTrue(CONTAINS_REGEX.test(text, "\\dfu\\w*"));

    assertFalse(CONTAINS_REGEX.test(text, "fo"));
    assertFalse(CONTAINS_REGEX.test(text, "wor[l]+"));
    assertFalse(CONTAINS_REGEX.test(text, "wor[ld]{3,5}"));


    String name = "fully funny";
    //Cmp
    assertTrue(Cmp.EQUAL.test(name.toString(), name));
    assertFalse(Cmp.NOT_EQUAL.test(name, name));
    assertFalse(Cmp.EQUAL.test("fullly funny", name));
    assertTrue(Cmp.NOT_EQUAL.test("fullly funny", name));

    //Prefix
    assertTrue(PREFIX.test(name, "fully"));
    assertTrue(PREFIX.test(name, "ful"));
    assertTrue(PREFIX.test(name, "fully fu"));
    assertFalse(PREFIX.test(name, "fun"));

    //REGEX
    assertTrue(REGEX.test(name, "(fu[ln]*y) (fu[ln]*y)"));
    assertFalse(REGEX.test(name, "(fu[l]*y) (fu[l]*y)"));
    assertTrue(REGEX.test(name, "(fu[l]*y) .*"));

}
 
Example 35
Project: titan1withtp3.1   File: BaseVertexCentricQueryBuilder.java   Source Code and License 4 votes vote down vote up
@Override
public Q has(String type, Object value) {
    return addConstraint(type, Cmp.EQUAL, value);
}
 
Example 36
Project: titan1withtp3.1   File: BaseVertexCentricQueryBuilder.java   Source Code and License 4 votes vote down vote up
@Override
public Q hasNot(String key, Object value) {
    return has(key, Cmp.NOT_EQUAL, value);
}
 
Example 37
Project: titan1withtp3.1   File: BaseVertexCentricQueryBuilder.java   Source Code and License 4 votes vote down vote up
@Override
public Q has(String key) {
    return has(key, Cmp.NOT_EQUAL, (Object) null);
}
 
Example 38
Project: titan1withtp3.1   File: BaseVertexCentricQueryBuilder.java   Source Code and License 4 votes vote down vote up
@Override
public Q hasNot(String key) {
    return has(key, Cmp.EQUAL, (Object) null);
}
 
Example 39
Project: titan1withtp3.1   File: BaseVertexCentricQueryBuilder.java   Source Code and License 4 votes vote down vote up
@Override
public <T extends Comparable<?>> Q interval(String key, T start, T end) {
    addConstraint(key, Cmp.GREATER_THAN_EQUAL, start);
    return addConstraint(key, Cmp.LESS_THAN, end);
}
 
Example 40
Project: titan1withtp3.1   File: QueryUtil.java   Source Code and License 4 votes vote down vote up
public static Iterable<TitanVertex> getVertices(StandardTitanTx tx,
                                                PropertyKey key, Object equalityCondition) {
    return tx.query().has(key,Cmp.EQUAL,equalityCondition).vertices();
}