Search in sources :

Example 41 with OIndex

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

the class ClassIndexManagerTest method testNoClassIndexesUpdate.

public void testNoClassIndexesUpdate() {
    final ODocument doc = new ODocument("classIndexManagerTestClassTwo");
    doc.field("prop1", "a");
    doc.save();
    doc.field("prop1", "b");
    doc.save();
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.getClass("classIndexManagerTestClass");
    final Collection<OIndex<?>> indexes = oClass.getIndexes();
    for (final OIndex<?> index : indexes) {
        Assert.assertEquals(index.getSize(), 0);
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 42 with OIndex

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

the class OChainedIndexProxyFindBestIndexTest method testTheOnlyChoice.

@Test
public void testTheOnlyChoice() throws Exception {
    final OIndexUnique expectedResult = mockUniqueIndex();
    final List<OIndex<?>> indexes = Arrays.<OIndex<?>>asList(expectedResult);
    final OIndex<?> result = OChainedIndexProxy.findBestIndex(indexes);
    Assert.assertSame(result, expectedResult);
}
Also used : OIndexUnique(com.orientechnologies.orient.core.index.OIndexUnique) OIndex(com.orientechnologies.orient.core.index.OIndex) Test(org.testng.annotations.Test)

Example 43 with OIndex

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

the class OChainedIndexProxyFindBestIndexTest method testDoNotUseIndexesWithNoNullValueSupport.

@Test
public void testDoNotUseIndexesWithNoNullValueSupport() throws Exception {
    final OIndexUnique expectedResult = mockUniqueIndex();
    final List<OIndex<?>> indexes = Arrays.<OIndex<?>>asList(mockUniqueCompositeHashIndex(), mockUniqueCompositeIndex(), expectedResult);
    final OIndex<?> result = OChainedIndexProxy.findBestIndex(indexes);
    Assert.assertSame(result, expectedResult);
}
Also used : OIndexUnique(com.orientechnologies.orient.core.index.OIndexUnique) OIndex(com.orientechnologies.orient.core.index.OIndex) Test(org.testng.annotations.Test)

Example 44 with OIndex

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

the class OOrientDBLoader method createSchema.

private void createSchema(OETLPipeline pipeline, ODatabaseDocument documentDatabase) {
    if (classes != null) {
        for (ODocument cls : classes) {
            schemaClass = getOrCreateClass(pipeline, (String) cls.field("name"), (String) cls.field("extends"));
            Integer clusters = cls.field("clusters");
            if (clusters != null)
                OClassImpl.addClusters(schemaClass, clusters);
            log(DEBUG, "%s: found %d %s in class '%s'", getName(), schemaClass.count(), getUnit(), className);
        }
    }
    if (className != null) {
        schemaClass = getOrCreateClass(pipeline, className, null);
        log(DEBUG, "%s: found %d %s in class '%s'", getName(), schemaClass.count(), getUnit(), className);
    }
    if (indexes != null) {
        for (ODocument idx : indexes) {
            OIndex index;
            final ODocument metadata = (ODocument) resolve(idx.field("metadata"));
            log(DEBUG, "%s: found metadata field '%s'", getName(), metadata);
            String idxName = (String) resolve(idx.field("name"));
            if (idxName != null) {
                index = documentDatabase.getMetadata().getIndexManager().getIndex(idxName);
                if (index != null)
                    // ALREADY EXISTS
                    continue;
            }
            final String idxClass = (String) resolve(idx.field("class"));
            if (idxClass == null)
                throw new OConfigurationException("Index 'class' missed in OrientDB Loader");
            final OClass cls = getOrCreateClass(pipeline, idxClass, null);
            final String idxType = idx.field("type");
            if (idxType == null)
                throw new OConfigurationException("Index 'type' missed in OrientDB Loader for index '" + idxName + "'");
            final List<String> idxFields = idx.field("fields");
            if (idxFields == null)
                throw new OConfigurationException("Index 'fields' missed in OrientDB Loader");
            String[] fields = new String[idxFields.size()];
            for (int f = 0; f < fields.length; ++f) {
                final String fieldName = idxFields.get(f);
                final String[] fieldNameParts = fieldName.split(":");
                if (!cls.existsProperty(fieldNameParts[0])) {
                    if (fieldNameParts.length < 2)
                        throw new OConfigurationException("Index field type missed in OrientDB Loader for field '" + fieldName + "'");
                    final String fieldType = fieldNameParts[1].toUpperCase(Locale.ENGLISH);
                    final OType type = OType.valueOf(fieldType);
                    cls.createProperty(fieldNameParts[0], type);
                    log(DEBUG, "- OrientDBLoader: created property '%s.%s' of type: %s", idxClass, fieldNameParts[0], fieldNameParts[1]);
                }
                fields[f] = fieldNameParts[0];
            }
            if (idxName == null) {
                // CREATE INDEX NAME
                idxName = idxClass + ".";
                for (int i = 0; i < fields.length; ++i) {
                    if (i > 0)
                        idxName += '_';
                    idxName += fields[i];
                }
            }
            index = documentDatabase.getMetadata().getIndexManager().getIndex(idxName);
            if (index != null)
                // ALREADY EXISTS
                continue;
            index = cls.createIndex(idxName, idxType, null, metadata, fields);
            log(DEBUG, "- OrientDocumentLoader: created index '%s' type '%s' against Class '%s', fields %s", idxName, idxType, idxClass, idxFields);
        }
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 45 with OIndex

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

the class OSQLFunctionOut method fetchFromIndex.

private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
    String edgeClassName = null;
    if (iEdgeTypes == null) {
        edgeClassName = "E";
    } else if (iEdgeTypes.length == 1) {
        edgeClassName = iEdgeTypes[0];
    } else {
        return null;
    }
    OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
    if (edgeClass == null) {
        return null;
    }
    Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("out", "in");
    if (indexes == null || indexes.size() == 0) {
        return null;
    }
    OIndex index = indexes.iterator().next();
    OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
    for (OIdentifiable to : iTo) {
        OCompositeKey key = new OCompositeKey(iFrom, to);
        Object indexResult = index.get(key);
        if (indexResult instanceof OIdentifiable) {
            indexResult = Collections.singleton(indexResult);
        }
        Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
        for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
            identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
        }
        result.add(identities);
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OIndex (com.orientechnologies.orient.core.index.OIndex)98 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)54 Test (org.testng.annotations.Test)50 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)26 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)20 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)18 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)16 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)16 Test (org.junit.Test)14 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)12 Collection (java.util.Collection)11 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)9 OPropertyMapIndexDefinition (com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition)8 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)8 HashSet (java.util.HashSet)6 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)5 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)5 OIndexUnique (com.orientechnologies.orient.core.index.OIndexUnique)5 Map (java.util.Map)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4