Search in sources :

Example 1 with OCompositeIndexDefinition

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);
}
Also used : OIndexManager(com.orientechnologies.orient.core.index.OIndexManager) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 2 with OCompositeIndexDefinition

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");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 3 with OCompositeIndexDefinition

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;
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndexCursor(com.orientechnologies.orient.core.index.OIndexCursor) OIndexDefinitionMultiValue(com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue)

Example 4 with OCompositeIndexDefinition

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);
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 5 with OCompositeIndexDefinition

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);
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)29 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)26 OIndex (com.orientechnologies.orient.core.index.OIndex)16 Test (org.testng.annotations.Test)16 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)11 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)7 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)7 OIndexDefinitionMultiValue (com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 HashSet (java.util.HashSet)4 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)3 OPropertyMapIndexDefinition (com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 OIndexCursorCollectionValue (com.orientechnologies.orient.core.index.OIndexCursorCollectionValue)2 OIndexCursorSingleValue (com.orientechnologies.orient.core.index.OIndexCursorSingleValue)2 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)2 OPropertyListIndexDefinition (com.orientechnologies.orient.core.index.OPropertyListIndexDefinition)2 OPropertyRidBagIndexDefinition (com.orientechnologies.orient.core.index.OPropertyRidBagIndexDefinition)2 OProgressListener (com.orientechnologies.common.listener.OProgressListener)1