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

The following examples show how to use com.thinkaurelius.titan.core.attribute.Cmp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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
Source File: BlurIndex.java    From incubator-retired-blur with Apache License 2.0 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 #3
Source File: GraphCentricQueryBuilder.java    From incubator-atlas with Apache License 2.0 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 #4
Source File: IndexHelper.java    From titan1withtp3.1 with Apache License 2.0 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 #5
Source File: GraphCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 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 #6
Source File: BaseVertexCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 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 #7
Source File: TitanPredicate.java    From titan1withtp3.1 with Apache License 2.0 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 #8
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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 #9
Source File: BlurIndex.java    From incubator-retired-blur with Apache License 2.0 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 #10
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 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 #11
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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 #12
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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 #13
Source File: TitanOperationCountingTest.java    From titan1withtp3.1 with Apache License 2.0 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 #14
Source File: GraphCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends Comparable<?>> GraphCentricQueryBuilder interval(String s, T t1, T t2) {
    has(s, Cmp.GREATER_THAN_EQUAL, t1);
    return has(s, Cmp.LESS_THAN, t2);
}
 
Example #15
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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 #16
Source File: GraphCentricQueryBuilder.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends Comparable<?>> GraphCentricQueryBuilder interval(String s, T t1, T t2) {
    has(s, Cmp.GREATER_THAN_EQUAL, t1);
    return has(s, Cmp.LESS_THAN, t2);
}
 
Example #17
Source File: GraphCentricQueryBuilder.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder hasNot(String key, Object value) {
    return has(key, Cmp.NOT_EQUAL, value);
}
 
Example #18
Source File: GraphCentricQueryBuilder.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder has(String key, Object value) {
    return has(key, Cmp.EQUAL, value);
}
 
Example #19
Source File: GraphCentricQueryBuilder.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder hasNot(String key) {
    return has(key, Cmp.EQUAL, (Object) null);
}
 
Example #20
Source File: GraphCentricQueryBuilder.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder has(String key) {
    return has(key, Cmp.NOT_EQUAL, (Object) null);
}
 
Example #21
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 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 #22
Source File: SolrIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testSupport() {
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT))));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING))));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING))));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT))));

    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Long.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT))));
    assertTrue(index.supports(of(Integer.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Short.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Byte.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Float.class, Cardinality.SINGLE)));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Object.class, Cardinality.SINGLE)));
    assertFalse(index.supports(of(Exception.class, Cardinality.SINGLE)));

    assertTrue(index.supports(of(String.class, Cardinality.SINGLE), Text.CONTAINS));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.CONTAINS_PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_REGEX));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXTSTRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Text.CONTAINS));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.DEFAULT)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.PREFIX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.STRING)), Text.REGEX));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.EQUAL));
    assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.STRING)), Cmp.NOT_EQUAL));
    assertFalse(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXTSTRING)), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.DEFAULT)), Cmp.LESS_THAN));
    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE, new Parameter("mapping",Mapping.TEXT)), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.WITHIN));

    assertFalse(index.supports(of(Double.class, Cardinality.SINGLE), Geo.INTERSECT));
    assertFalse(index.supports(of(Long.class, Cardinality.SINGLE), Text.CONTAINS));
    assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.DISJOINT));

    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.LESS_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.GREATER_THAN_EQUAL));
    assertTrue(index.supports(of(Date.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(Boolean.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));

    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.EQUAL));
    assertTrue(index.supports(of(UUID.class, Cardinality.SINGLE), Cmp.NOT_EQUAL));
}
 
Example #23
Source File: TitanEventualGraphTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the correct interpretation of the commit time and that timestamps can be read
 */
@Test
public void testTimestampSetting() {
    clopen(option(GraphDatabaseConfiguration.STORE_META_TIMESTAMPS,"edgestore"),true,
            option(GraphDatabaseConfiguration.STORE_META_TTL,"edgestore"),true);


    // Transaction 1: Init graph with two vertices, having set "name" and "age" properties
    TitanTransaction tx1 = graph.buildTransaction().commitTime(Instant.ofEpochSecond(100)).start();
    String name = "name";
    String age = "age";
    String address = "address";

    TitanVertex v1 = tx1.addVertex(name, "a");
    TitanVertex v2 = tx1.addVertex(age, "14", name, "b", age, "42");
    tx1.commit();

    // Fetch vertex ids
    long id1 = getId(v1);
    long id2 = getId(v2);

    // Transaction 2: Remove "name" property from v1, set "address" property; create
    // an edge v2 -> v1
    TitanTransaction tx2 = graph.buildTransaction().commitTime(Instant.ofEpochSecond(1000)).start();
    v1 = getV(tx2,id1);
    v2 = getV(tx2,id2);
    for (Iterator<VertexProperty<Object>> propiter = v1.properties(name); propiter.hasNext(); ) {
        VertexProperty prop = propiter.next();
        if (features.hasTimestamps()) {
            Instant t = prop.value("~timestamp");
            assertEquals(100,t.getEpochSecond());
            assertEquals(Instant.ofEpochSecond(0, 1000).getNano(),t.getNano());
        }
        if (features.hasCellTTL()) {
            Duration d = prop.value("~ttl");
            assertEquals(0l, d.getSeconds());
            assertTrue(d.isZero());
        }
    }
    assertEquals(1, v1.query().propertyCount());
    assertEquals(1, v1.query().has("~timestamp", Cmp.GREATER_THAN, Instant.ofEpochSecond(10)).propertyCount());
    assertEquals(1, v1.query().has("~timestamp", Instant.ofEpochSecond(100, 1000)).propertyCount());
    v1.property(name).remove();
    v1.property(VertexProperty.Cardinality.single, address,  "xyz");
    Edge edge = v2.addEdge("parent",v1);
    tx2.commit();
    Object edgeId = edge.id();

    TitanVertex afterTx2 = getV(graph,id1);

    // Verify that "name" property is gone
    assertFalse(afterTx2.keys().contains(name));
    // Verify that "address" property is set
    assertEquals("xyz", afterTx2.value(address));
    // Verify that the edge is properly registered with the endpoint vertex
    assertCount(1, afterTx2.query().direction(IN).labels("parent").edges());
    // Verify that edge is registered under the id
    assertNotNull(getE(graph,edgeId));
    graph.tx().commit();

    // Transaction 3: Remove "address" property from v1 with earlier timestamp than
    // when the value was set
    TitanTransaction tx3 = graph.buildTransaction().commitTime(Instant.ofEpochSecond(200)).start();
    v1 = getV(tx3,id1);
    v1.property(address).remove();
    tx3.commit();

    TitanVertex afterTx3 = getV(graph,id1);
    graph.tx().commit();
    // Verify that "address" is still set
    assertEquals("xyz", afterTx3.value(address));

    // Transaction 4: Modify "age" property on v2, remove edge between v2 and v1
    TitanTransaction tx4 = graph.buildTransaction().commitTime(Instant.ofEpochSecond(2000)).start();
    v2 = getV(tx4,id2);
    v2.property(VertexProperty.Cardinality.single, age,  "15");
    getE(tx4,edgeId).remove();
    tx4.commit();

    TitanVertex afterTx4 = getV(graph,id2);
    // Verify that "age" property is modified
    assertEquals("15", afterTx4.value(age));
    // Verify that edge is no longer registered with the endpoint vertex
    assertCount(0, afterTx4.query().direction(OUT).labels("parent").edges());
    // Verify that edge entry disappeared from id registry
    assertNull(getE(graph,edgeId));

    // Transaction 5: Modify "age" property on v2 with earlier timestamp
    TitanTransaction tx5 = graph.buildTransaction().commitTime(Instant.ofEpochSecond(1500)).start();
    v2 = getV(tx5,id2);
    v2.property(VertexProperty.Cardinality.single, age,  "16");
    tx5.commit();
    TitanVertex afterTx5 = getV(graph,id2);

    // Verify that the property value is unchanged
    assertEquals("15", afterTx5.value(age));
}
 
Example #24
Source File: StandardIndexInformation.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supports(KeyInformation information, TitanPredicate titanPredicate) {
    return titanPredicate == Cmp.EQUAL || titanPredicate == Contain.IN;
}
 
Example #25
Source File: TextTest.java    From titan1withtp3.1 with Apache License 2.0 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 #26
Source File: GraphCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder hasNot(String key, Object value) {
    return has(key, Cmp.NOT_EQUAL, value);
}
 
Example #27
Source File: GraphCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder has(String key, Object value) {
    return has(key, Cmp.EQUAL, value);
}
 
Example #28
Source File: GraphCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder hasNot(String key) {
    return has(key, Cmp.EQUAL, (Object) null);
}
 
Example #29
Source File: GraphCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public GraphCentricQueryBuilder has(String key) {
    return has(key, Cmp.NOT_EQUAL, (Object) null);
}
 
Example #30
Source File: QueryUtil.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static Iterable<TitanEdge> getEdges(StandardTitanTx tx,
                                           String key, Object equalityCondition) {
    return tx.query().has(key,Cmp.EQUAL,equalityCondition).edges();
}