use of org.janusgraph.core.schema.Parameter in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testIndexUpdatesWithoutReindex.
@Test
public void testIndexUpdatesWithoutReindex() throws InterruptedException, ExecutionException {
Object[] settings = new Object[] { option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250) };
clopen(settings);
final String defText = "Mountain rocks are great friends";
final int defTime = 5;
final double defHeight = 101.1;
final String[] defPhones = new String[] { "1234", "5678" };
// Creates types and index only two keys key
mgmt.makePropertyKey("time").dataType(Integer.class).make();
PropertyKey text = mgmt.makePropertyKey("text").dataType(String.class).make();
mgmt.makePropertyKey("height").dataType(Double.class).make();
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
mgmt.makePropertyKey("phone").dataType(String.class).cardinality(Cardinality.LIST).make();
}
mgmt.buildIndex("theIndex", Vertex.class).addKey(text, getTextMapping(), getFieldMap(text)).buildMixedIndex(INDEX);
finishSchema();
// Add initial data
addVertex(defTime, defText, defHeight, defPhones);
// Indexes should not yet be in use
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 1, new boolean[] { false, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
}
newTx();
// Add another key to index ------------------------------------------------------
finishSchema();
PropertyKey time = mgmt.getPropertyKey("time");
mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), time, getFieldMap(time));
finishSchema();
newTx();
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
tx.commit();
// Should not yet be able to enable since not yet registered
assertNull(mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX));
// This call is redundant and just here to make sure it doesn't mess anything up
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REGISTER_INDEX).get();
mgmt.commit();
ManagementSystem.awaitGraphIndexStatus(graph, "theIndex").timeout(10L, ChronoUnit.SECONDS).call();
finishSchema();
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX).get();
finishSchema();
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
// One more key should be indexed but only sees partial data
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 3, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 3, new boolean[] { false, true });
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { false, true }, "theIndex");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { false, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 3, new boolean[] { false, true });
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 3, new boolean[] { false, true });
}
newTx();
// Add another key to index ------------------------------------------------------
finishSchema();
PropertyKey height = mgmt.getPropertyKey("height");
mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), height);
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
PropertyKey phone = mgmt.getPropertyKey("phone");
mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), phone, new Parameter("mapping", Mapping.STRING));
}
finishSchema();
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
tx.commit();
mgmt.commit();
ManagementUtil.awaitGraphIndexUpdate(graph, "theIndex", 10, ChronoUnit.SECONDS);
finishSchema();
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
finishSchema();
JanusGraphIndex index = mgmt.getGraphIndex("theIndex");
for (PropertyKey key : index.getFieldKeys()) {
assertEquals(SchemaStatus.ENABLED, index.getIndexStatus(key));
}
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
// One more key should be indexed but only sees partial data
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 4, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
}
newTx();
finishSchema();
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REINDEX).get();
mgmt.commit();
finishSchema();
// All the data should now be in the index
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
}
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.DISABLE_INDEX).get();
tx.commit();
mgmt.commit();
ManagementUtil.awaitGraphIndexUpdate(graph, "theIndex", 10, ChronoUnit.SECONDS);
finishSchema();
index = mgmt.getGraphIndex("theIndex");
for (PropertyKey key : index.getFieldKeys()) {
assertEquals(SchemaStatus.DISABLED, index.getIndexStatus(key));
}
newTx();
// This now requires a full graph scan
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { false, true });
}
use of org.janusgraph.core.schema.Parameter in project janusgraph by JanusGraph.
the class SolrIndexTest method testSupport.
@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)));
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));
assertTrue(index.supports(of(String.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.TEXT)), Text.CONTAINS_FUZZY));
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)), Text.FUZZY));
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)));
assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.WITHIN));
assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.INTERSECT));
assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.CONTAINS));
assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE), Geo.DISJOINT));
assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.PREFIX_TREE)), Geo.CONTAINS));
assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.PREFIX_TREE)), Geo.WITHIN));
assertTrue(index.supports(of(Geoshape.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.PREFIX_TREE)), Geo.INTERSECT));
assertFalse(index.supports(of(Geoshape.class, Cardinality.SINGLE, new Parameter("mapping", Mapping.PREFIX_TREE)), Geo.DISJOINT));
assertFalse(index.supports(of(Double.class, Cardinality.SINGLE), Geo.INTERSECT));
assertFalse(index.supports(of(Long.class, Cardinality.SINGLE), Text.CONTAINS));
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));
}
use of org.janusgraph.core.schema.Parameter in project janusgraph by JanusGraph.
the class LuceneCustomAnalyzer method getWrappedAnalyzer.
@Override
protected final Analyzer getWrappedAnalyzer(String fieldName) {
final KeyInformation keyInformation = informations.get(store, fieldName);
if (keyInformation == null || !String.class.isAssignableFrom(keyInformation.getDataType())) {
return analyzerFor(STANDARD_ANALYZER);
}
final Parameter[] parameters = keyInformation.getParameters();
// if mapping isn't present in parameters, we use Mapping.DEFAULT
final Mapping mapping = ParameterType.MAPPING.findParameter(parameters, Mapping.DEFAULT);
// everything else falls through a StandardAnalyzer as was the case before
return analyzerFor(analyzerNameFor(parameters, mapping, KEYWORD_ANALYZER, STANDARD_ANALYZER));
}
use of org.janusgraph.core.schema.Parameter in project janusgraph by JanusGraph.
the class ManagementSystem method addIndexKey.
@Override
public void addIndexKey(final JanusGraphIndex index, final PropertyKey key, Parameter... parameters) {
Preconditions.checkArgument(index != null && key != null && index instanceof JanusGraphIndexWrapper && !(key instanceof BaseKey), "Need to provide valid index and key");
if (parameters == null)
parameters = new Parameter[0];
IndexType indexType = ((JanusGraphIndexWrapper) index).getBaseIndex();
Preconditions.checkArgument(indexType instanceof MixedIndexType, "Can only add keys to an external index, not %s", index.name());
Preconditions.checkArgument(indexType instanceof IndexTypeWrapper && key instanceof JanusGraphSchemaVertex && ((IndexTypeWrapper) indexType).getSchemaBase() instanceof JanusGraphSchemaVertex);
JanusGraphSchemaVertex indexVertex = (JanusGraphSchemaVertex) ((IndexTypeWrapper) indexType).getSchemaBase();
for (IndexField field : indexType.getFieldKeys()) Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name());
// Assemble parameters
boolean addMappingParameter = !ParameterType.MAPPED_NAME.hasParameter(parameters);
Parameter[] extendedParas = new Parameter[parameters.length + 1 + (addMappingParameter ? 1 : 0)];
System.arraycopy(parameters, 0, extendedParas, 0, parameters.length);
int arrPosition = parameters.length;
if (addMappingParameter)
extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter(graph.getIndexSerializer().getDefaultFieldName(key, parameters, indexType.getBackingIndexName()));
extendedParas[arrPosition] = ParameterType.STATUS.getParameter(key.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
addSchemaEdge(indexVertex, key, TypeDefinitionCategory.INDEX_FIELD, extendedParas);
updateSchemaVertex(indexVertex);
indexType.resetCache();
// Check to see if the index supports this
if (!graph.getIndexSerializer().supports((MixedIndexType) indexType, ParameterIndexField.of(key, parameters))) {
throw new JanusGraphException("Could not register new index field '" + key.name() + "' with index backend as the data type, cardinality or parameter combination is not supported.");
}
try {
IndexSerializer.register((MixedIndexType) indexType, key, transaction.getTxHandle());
} catch (BackendException e) {
throw new JanusGraphException("Could not register new index field with index backend", e);
}
if (!indexVertex.isNew())
updatedTypes.add(indexVertex);
if (!key.isNew())
updateIndex(index, SchemaAction.REGISTER_INDEX);
}
use of org.janusgraph.core.schema.Parameter in project janusgraph by JanusGraph.
the class ManagementSystem method setStatusEdges.
private void setStatusEdges(JanusGraphSchemaVertex vertex, SchemaStatus status, Set<PropertyKeyVertex> keys) {
Preconditions.checkArgument(vertex.asIndexType().isMixedIndex());
for (JanusGraphEdge edge : vertex.getEdges(TypeDefinitionCategory.INDEX_FIELD, Direction.OUT)) {
// Only address edges with matching keys
if (!keys.contains(edge.vertex(Direction.IN)))
continue;
TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc);
assert desc.getCategory() == TypeDefinitionCategory.INDEX_FIELD;
Parameter[] parameters = (Parameter[]) desc.getModifier();
assert parameters[parameters.length - 1].key().equals(ParameterType.STATUS.getName());
if (parameters[parameters.length - 1].value().equals(status))
continue;
Parameter[] paraCopy = Arrays.copyOf(parameters, parameters.length);
paraCopy[parameters.length - 1] = ParameterType.STATUS.getParameter(status);
edge.remove();
addSchemaEdge(vertex, edge.vertex(Direction.IN), TypeDefinitionCategory.INDEX_FIELD, paraCopy);
}
for (PropertyKeyVertex prop : keys) prop.resetCache();
}
Aggregations