use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method testBooleanIndexing.
/**
* 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)));
//Flush the index
clopen();
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)));
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method testInstantIndexing.
/**
* Tests indexing instants
*/
@Test
public void testInstantIndexing() {
PropertyKey name = makeKey("instant", Instant.class);
mgmt.buildIndex("instantIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
Instant firstTimestamp = Instant.ofEpochMilli(1);
Instant secondTimestamp = Instant.ofEpochMilli(2000);
TitanVertex v1 = graph.addVertex();
v1.property("instant", firstTimestamp);
TitanVertex v2 = graph.addVertex();
v2.property("instant", secondTimestamp);
testInstant(firstTimestamp, secondTimestamp, v1, v2);
firstTimestamp = Instant.ofEpochSecond(0, 1);
v1 = (TitanVertex) graph.vertices(v1.id()).next();
v1.property("instant", firstTimestamp);
if (indexFeatures.supportsNanoseconds()) {
testInstant(firstTimestamp, secondTimestamp, v1, v2);
} else {
//Flush the index
clopen();
try {
assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
Assert.fail("Should have failed to update the index");
} catch (Exception e) {
}
}
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class TitanIndexTest method testDateIndexing.
/**
* 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))));
//Flush the index
clopen();
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))));
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class BaseVertexCentricQueryBuilder method orderBy.
@Override
public Q orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) {
Preconditions.checkArgument(schemaInspector.containsPropertyKey(keyName), "Provided key does not exist: %s", keyName);
PropertyKey key = schemaInspector.getPropertyKey(keyName);
Preconditions.checkArgument(key != null && order != null, "Need to specify and key and an order");
Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.dataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.name(), key.dataType());
Preconditions.checkArgument(key.cardinality() == Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.name());
Preconditions.checkArgument(!(key instanceof SystemRelationType), "Cannot use system types in ordering: %s", key);
Preconditions.checkArgument(!orders.containsKey(key));
Preconditions.checkArgument(orders.isEmpty(), "Only a single sort order is supported on vertex queries");
orders.add(key, Order.convert(order));
return getThis();
}
use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.
the class IndexTypeWrapper method getField.
@Override
public IndexField getField(PropertyKey key) {
Map<PropertyKey, IndexField> result = fieldMap;
if (result == null) {
ImmutableMap.Builder<PropertyKey, IndexField> b = ImmutableMap.builder();
for (IndexField f : getFieldKeys()) b.put(f.getFieldKey(), f);
result = b.build();
fieldMap = result;
}
assert result != null;
return result.get(key);
}
Aggregations