Search in sources :

Example 16 with OCompositeIndexDefinition

use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.

the class OQueryOperatorMinorEquals 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();
    OIndexCursor cursor;
    if (!internalIndex.canBeUsedInEqualityOperators() || !internalIndex.hasRangeQuerySupport())
        return null;
    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, true, 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 value 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, true, 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 17 with OCompositeIndexDefinition

use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.

the class ClassIndexTest method testGetClassIndexes.

@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest", "testCreateOnePropertyEmbeddedMapIndex", "testCreateOnePropertyByKeyEmbeddedMapIndex", "testCreateOnePropertyByValueEmbeddedMapIndex", "testCreateOnePropertyLinkedMapIndex", "testCreateOnePropertyLinkMapByKeyIndex", "testCreateOnePropertyLinkMapByValueIndex", "testCreateCompositeEmbeddedMapIndex", "testCreateCompositeEmbeddedMapByKeyIndex", "testCreateCompositeEmbeddedMapByValueIndex", "testCreateCompositeLinkMapByValueIndex", "testCreateCompositeEmbeddedSetIndex", "testCreateCompositeEmbeddedListIndex", "testCreateCompositeLinkListIndex", "testCreateCompositeRidBagIndex" })
public void testGetClassIndexes() {
    final Set<OIndex<?>> indexes = oClass.getClassIndexes();
    final Set<OIndexDefinition> expectedIndexDefinitions = new HashSet<OIndexDefinition>();
    final OCompositeIndexDefinition compositeIndexOne = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexOne.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fOne", OType.INTEGER));
    compositeIndexOne.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTwo", OType.STRING));
    expectedIndexDefinitions.add(compositeIndexOne);
    final OCompositeIndexDefinition compositeIndexTwo = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fOne", OType.INTEGER));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTwo", OType.STRING));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fThree", OType.BOOLEAN));
    expectedIndexDefinitions.add(compositeIndexTwo);
    final OCompositeIndexDefinition compositeIndexThree = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexThree.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fEight", OType.INTEGER));
    compositeIndexThree.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY));
    expectedIndexDefinitions.add(compositeIndexThree);
    final OCompositeIndexDefinition compositeIndexFour = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexFour.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTen", OType.INTEGER));
    compositeIndexFour.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.INTEGER, OPropertyMapIndexDefinition.INDEX_BY.VALUE));
    expectedIndexDefinitions.add(compositeIndexFour);
    final OCompositeIndexDefinition compositeIndexFive = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexFive.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fEleven", OType.INTEGER));
    compositeIndexFive.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fLinkMap", OType.LINK, OPropertyMapIndexDefinition.INDEX_BY.VALUE));
    expectedIndexDefinitions.add(compositeIndexFive);
    final OCompositeIndexDefinition compositeIndexSix = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexSix.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTwelve", OType.INTEGER));
    compositeIndexSix.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fEmbeddedSet", OType.INTEGER));
    expectedIndexDefinitions.add(compositeIndexSix);
    final OCompositeIndexDefinition compositeIndexSeven = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexSeven.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fThirteen", OType.INTEGER));
    compositeIndexSeven.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fEmbeddedList", OType.INTEGER));
    expectedIndexDefinitions.add(compositeIndexSeven);
    final OCompositeIndexDefinition compositeIndexEight = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexEight.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFourteen", OType.INTEGER));
    compositeIndexEight.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fEmbeddedList", OType.LINK));
    expectedIndexDefinitions.add(compositeIndexEight);
    final OCompositeIndexDefinition compositeIndexNine = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexNine.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFifteen", OType.INTEGER));
    compositeIndexNine.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY));
    expectedIndexDefinitions.add(compositeIndexNine);
    final OCompositeIndexDefinition compositeIndexTen = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexTen.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFourteen", OType.INTEGER));
    compositeIndexTen.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fLinkList", OType.LINK));
    expectedIndexDefinitions.add(compositeIndexTen);
    final OCompositeIndexDefinition compositeIndexEleven = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexEleven.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFourteen", OType.INTEGER));
    compositeIndexEleven.addIndex(new OPropertyRidBagIndexDefinition("ClassIndexTestClass", "fRidBag"));
    expectedIndexDefinitions.add(compositeIndexEleven);
    final OPropertyIndexDefinition propertyIndex = new OPropertyIndexDefinition("ClassIndexTestClass", "fOne", OType.INTEGER);
    expectedIndexDefinitions.add(propertyIndex);
    final OPropertyMapIndexDefinition propertyMapIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY);
    expectedIndexDefinitions.add(propertyMapIndexDefinition);
    final OPropertyMapIndexDefinition propertyMapByValueIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.INTEGER, OPropertyMapIndexDefinition.INDEX_BY.VALUE);
    expectedIndexDefinitions.add(propertyMapByValueIndexDefinition);
    final OPropertyMapIndexDefinition propertyLinkMapByKeyIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fLinkMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY);
    expectedIndexDefinitions.add(propertyLinkMapByKeyIndexDefinition);
    final OPropertyMapIndexDefinition propertyLinkMapByValueIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fLinkMap", OType.LINK, OPropertyMapIndexDefinition.INDEX_BY.VALUE);
    expectedIndexDefinitions.add(propertyLinkMapByValueIndexDefinition);
    assertEquals(indexes.size(), 17);
    for (final OIndex index : indexes) {
        assertTrue(expectedIndexDefinitions.contains(index.getDefinition()));
    }
}
Also used : OPropertyRidBagIndexDefinition(com.orientechnologies.orient.core.index.OPropertyRidBagIndexDefinition) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OPropertyMapIndexDefinition(com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OPropertyListIndexDefinition(com.orientechnologies.orient.core.index.OPropertyListIndexDefinition) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 18 with OCompositeIndexDefinition

use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.

the class ClassIndexTest method testCreateCompositeLinkListIndex.

public void testCreateCompositeLinkListIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeLinkList", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fFourteen", "fLinkList" });
    assertEquals(result.getName(), "ClassIndexTestCompositeLinkList");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeLinkList").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeLinkList").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    assertEquals(indexDefinition.getFields().toArray(), new String[] { "fFourteen", "fLinkList" });
    assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.LINK });
    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)

Example 19 with OCompositeIndexDefinition

use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.

the class ClassIndexTest method testCreateCompositeEmbeddedSetIndex.

@Test
public void testCreateCompositeEmbeddedSetIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeEmbeddedSet", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fTwelve", "fEmbeddedSet" });
    assertEquals(result.getName(), "ClassIndexTestCompositeEmbeddedSet");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeEmbeddedSet").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeEmbeddedSet").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    assertEquals(indexDefinition.getFields().toArray(), new String[] { "fTwelve", "fEmbeddedSet" });
    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 20 with OCompositeIndexDefinition

use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition in project orientdb by orientechnologies.

the class ClassIndexTest method testCreateCompositeRidBagIndex.

public void testCreateCompositeRidBagIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeRidBag", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fFourteen", "fRidBag" });
    assertEquals(result.getName(), "ClassIndexTestCompositeRidBag");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeRidBag").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeRidBag").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    assertEquals(indexDefinition.getFields().toArray(), new String[] { "fFourteen", "fRidBag" });
    assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.LINK });
    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)

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