use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.
the class IndexManagerTest method testGetClassInvolvedIndexesWithNullValues.
@Test
public void testGetClassInvolvedIndexesWithNullValues() {
String className = "GetClassInvolvedIndexesWithNullValues";
final OIndexManager indexManager = database.getMetadata().getIndexManager();
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.createClass(className);
oClass.createProperty("one", OType.STRING);
oClass.createProperty("two", OType.STRING);
oClass.createProperty("three", OType.STRING);
indexManager.createIndex(className + "_indexOne_notunique", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OPropertyIndexDefinition(className, "one", OType.STRING), oClass.getClusterIds(), null, null);
indexManager.createIndex(className + "_indexOneTwo_notunique", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OCompositeIndexDefinition(className, Arrays.asList(new OPropertyIndexDefinition(className, "one", OType.STRING), new OPropertyIndexDefinition(className, "two", OType.STRING)), -1), oClass.getClusterIds(), null, null);
indexManager.createIndex(className + "_indexOneTwoThree_notunique", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OCompositeIndexDefinition(className, Arrays.asList(new OPropertyIndexDefinition(className, "one", OType.STRING), new OPropertyIndexDefinition(className, "two", OType.STRING), new OPropertyIndexDefinition(className, "three", OType.STRING)), -1), oClass.getClusterIds(), null, null);
Set<OIndex<?>> result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("one"));
assertEquals(result.size(), 3);
result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("one", "two"));
assertEquals(result.size(), 2);
result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("one", "two", "three"));
assertEquals(result.size(), 1);
result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("two"));
assertEquals(result.size(), 0);
result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("two", "one", "three"));
assertEquals(result.size(), 1);
}
use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.
the class SQLDropPropertyIndexTest method testForcePropertyDisabled.
@Test
public void testForcePropertyDisabled() throws Exception {
database.command(new OCommandSQL("CREATE INDEX DropPropertyIndexCompositeIndex ON DropPropertyIndexTestClass (prop1, prop2) UNIQUE")).execute();
database.getMetadata().getIndexManager().reload();
OIndex<?> index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
Assert.assertNotNull(index);
try {
database.command(new OCommandSQL("DROP PROPERTY DropPropertyIndexTestClass.prop1")).execute();
Assert.fail();
} catch (OCommandExecutionException e) {
Assert.assertTrue(e.getMessage().contains("Property used in indexes (" + "DropPropertyIndexCompositeIndex" + "). Please drop these indexes before removing property or use FORCE parameter."));
}
database.getMetadata().getIndexManager().reload();
index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop1", "prop2"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { EXPECTED_PROP1_TYPE, EXPECTED_PROP2_TYPE });
Assert.assertEquals(index.getType(), "UNIQUE");
}
use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.
the class OQueryOperatorMinor method executeIndexQuery.
@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
final OIndexDefinition indexDefinition = index.getDefinition();
final OIndexInternal<?> internalIndex = index.getInternal();
if (!internalIndex.canBeUsedInEqualityOperators() || !internalIndex.hasRangeQuerySupport())
return null;
final OIndexCursor cursor;
if (indexDefinition.getParamCount() == 1) {
final Object key;
if (indexDefinition instanceof OIndexDefinitionMultiValue)
key = ((OIndexDefinitionMultiValue) indexDefinition).createSingleValue(keyParams.get(0));
else
key = indexDefinition.createValue(keyParams);
if (key == null)
return null;
cursor = index.iterateEntriesMinor(key, false, ascSortOrder);
} else {
// if we have situation like "field1 = 1 AND field2 < 2"
// then we fetch collection which left included boundary is the smallest composite key in the
// index that contains key with value field1=1 and which right not included boundary
// is the biggest composite key in the index that contains key with values field1=1 and field2=2.
final OCompositeIndexDefinition compositeIndexDefinition = (OCompositeIndexDefinition) indexDefinition;
final Object keyOne = compositeIndexDefinition.createSingleValue(keyParams.subList(0, keyParams.size() - 1));
if (keyOne == null)
return null;
final Object keyTwo = compositeIndexDefinition.createSingleValue(keyParams);
if (keyTwo == null)
return null;
cursor = index.iterateEntriesBetween(keyOne, true, keyTwo, false, ascSortOrder);
}
updateProfiler(iContext, index, keyParams, indexDefinition);
return cursor;
}
use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.
the class ClassIndexTest method testCreateCompositeEmbeddedListIndex.
@Test
public void testCreateCompositeEmbeddedListIndex() {
final OIndex result = oClass.createIndex("ClassIndexTestCompositeEmbeddedList", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fThirteen", "fEmbeddedList" });
assertEquals(result.getName(), "ClassIndexTestCompositeEmbeddedList");
assertEquals(oClass.getClassIndex("ClassIndexTestCompositeEmbeddedList").getName(), result.getName());
assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeEmbeddedList").getName(), result.getName());
final OIndexDefinition indexDefinition = result.getDefinition();
assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
assertEquals(indexDefinition.getFields().toArray(), new String[] { "fThirteen", "fEmbeddedList" });
assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.INTEGER });
assertEquals(indexDefinition.getParamCount(), 2);
}
use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.
the class ClassIndexTest method testCreateCompositeEmbeddedMapByValueIndex.
@Test
public void testCreateCompositeEmbeddedMapByValueIndex() {
final OIndex result = oClass.createIndex("ClassIndexTestCompositeEmbeddedMapByValue", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fTen", "fEmbeddedMap by value" });
assertEquals(result.getName(), "ClassIndexTestCompositeEmbeddedMapByValue");
assertEquals(oClass.getClassIndex("ClassIndexTestCompositeEmbeddedMapByValue").getName(), result.getName());
assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeEmbeddedMapByValue").getName(), result.getName());
final OIndexDefinition indexDefinition = result.getDefinition();
assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
assertEquals(indexDefinition.getFields().toArray(), new String[] { "fTen", "fEmbeddedMap" });
assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.INTEGER });
assertEquals(indexDefinition.getParamCount(), 2);
}
Aggregations