Search in sources :

Example 1 with EntityType

use of org.neo4j.common.EntityType in project neo4j by neo4j.

the class BuiltInProceduresTest method setup.

@BeforeEach
void setup() throws Exception {
    procs.registerComponent(KernelTransaction.class, ctx -> ctx.internalTransaction().kernelTransaction(), false);
    procs.registerComponent(DependencyResolver.class, Context::dependencyResolver, false);
    procs.registerComponent(GraphDatabaseAPI.class, Context::graphDatabaseAPI, false);
    procs.registerComponent(Transaction.class, Context::internalTransaction, true);
    procs.registerComponent(SecurityContext.class, Context::securityContext, true);
    procs.registerComponent(ProcedureCallContext.class, Context::procedureCallContext, true);
    procs.registerComponent(SystemGraphComponents.class, ctx -> systemGraphComponents, false);
    procs.registerComponent(Log.class, ctx -> log, false);
    procs.registerType(Node.class, NTNode);
    procs.registerType(Relationship.class, NTRelationship);
    procs.registerType(Path.class, NTPath);
    new SpecialBuiltInProcedures("1.3.37", Edition.COMMUNITY.toString()).accept(procs);
    procs.registerProcedure(BuiltInProcedures.class);
    procs.registerProcedure(BuiltInDbmsProcedures.class);
    when(transaction.kernelTransaction()).thenReturn(tx);
    when(tx.tokenRead()).thenReturn(tokens);
    when(tx.dataRead()).thenReturn(read);
    when(tx.schemaRead()).thenReturn(schemaRead);
    when(tx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
    when(callContext.isCalledFromCypher()).thenReturn(false);
    when(schemaRead.snapshot()).thenReturn(schemaReadCore);
    when(tokens.propertyKeyGetAllTokens()).thenAnswer(asTokens(propKeys));
    when(tokens.labelsGetAllTokens()).thenAnswer(asTokens(labels));
    when(tokens.relationshipTypesGetAllTokens()).thenAnswer(asTokens(relTypes));
    when(schemaReadCore.indexesGetAll()).thenAnswer(i -> Iterators.concat(indexes.iterator(), uniqueIndexes.iterator()));
    when(schemaReadCore.index(any(SchemaDescriptor.class))).thenAnswer((Answer<IndexDescriptor>) invocationOnMock -> {
        SchemaDescriptor schema = invocationOnMock.getArgument(0);
        return getIndexReference(schema);
    });
    when(schemaReadCore.constraintsGetAll()).thenAnswer(i -> constraints.iterator());
    when(tokens.propertyKeyName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
    when(tokens.nodeLabelName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
    when(tokens.relationshipTypeName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
    when(tokens.propertyKeyGetName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
    when(tokens.labelGetName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
    when(tokens.relationshipTypeGetName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
    when(tokens.entityTokensGetNames(any(), any())).then(invocation -> {
        EntityType type = invocation.getArgument(0);
        int[] ids = invocation.getArgument(1);
        Map<Integer, String> mapping = type == EntityType.NODE ? labels : relTypes;
        return Arrays.stream(ids).mapToObj(mapping::get).toArray(String[]::new);
    });
    when(schemaReadCore.constraintsGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
    when(schemaReadCore.indexesGetForLabel(anyInt())).thenReturn(emptyIterator());
    when(schemaReadCore.indexesGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
    when(schemaReadCore.constraintsGetForLabel(anyInt())).thenReturn(emptyIterator());
    when(read.countsForNode(anyInt())).thenReturn(1L);
    when(read.countsForRelationship(anyInt(), anyInt(), anyInt())).thenReturn(1L);
    when(schemaReadCore.indexGetState(any(IndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
}
Also used : SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) Context(org.neo4j.kernel.api.procedure.Context) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) SystemGraphComponent(org.neo4j.dbms.database.SystemGraphComponent) MapUtil(org.neo4j.internal.helpers.collection.MapUtil) Log(org.neo4j.logging.Log) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EMPTY(org.neo4j.kernel.api.index.IndexProvider.EMPTY) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Value(org.neo4j.values.storable.Value) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Statement(org.neo4j.kernel.api.Statement) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Collections.singletonList(java.util.Collections.singletonList) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) EMPTY_RESOURCE_TRACKER(org.neo4j.kernel.api.ResourceTracker.EMPTY_RESOURCE_TRACKER) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) Map(java.util.Map) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) Transaction(org.neo4j.graphdb.Transaction) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) SettingValueParsers(org.neo4j.configuration.SettingValueParsers) TextValue(org.neo4j.values.storable.TextValue) Collections.emptyIterator(java.util.Collections.emptyIterator) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) Path(org.neo4j.graphdb.Path) List(java.util.List) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) EntityType(org.neo4j.common.EntityType) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Mockito.mock(org.mockito.Mockito.mock) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AnyValue(org.neo4j.values.AnyValue) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NodeExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor) SettingImpl(org.neo4j.configuration.SettingImpl) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) NTNode(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTNode) Node(org.neo4j.graphdb.Node) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) ArrayList(java.util.ArrayList) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) Values(org.neo4j.values.storable.Values) DefaultValueMapper(org.neo4j.kernel.impl.util.DefaultValueMapper) Answer(org.mockito.stubbing.Answer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) SystemGraphComponents(org.neo4j.dbms.database.SystemGraphComponents) TestSystemGraphComponent(org.neo4j.dbms.database.TestSystemGraphComponent) DependencyResolver(org.neo4j.common.DependencyResolver) IndexConfig(org.neo4j.internal.schema.IndexConfig) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) IntSupplier(java.util.function.IntSupplier) ValueUtils(org.neo4j.kernel.impl.util.ValueUtils) Iterator(java.util.Iterator) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) Edition(org.neo4j.common.Edition) Setting(org.neo4j.graphdb.config.Setting) BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Mockito.when(org.mockito.Mockito.when) Context(org.neo4j.kernel.api.procedure.Context) NTPath(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTPath) GlobalProceduresRegistry(org.neo4j.procedure.impl.GlobalProceduresRegistry) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) Relationship(org.neo4j.graphdb.Relationship) NTRelationship(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTRelationship) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NamedToken(org.neo4j.token.api.NamedToken) ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) EntityType(org.neo4j.common.EntityType) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with EntityType

use of org.neo4j.common.EntityType in project neo4j by neo4j.

the class IndexingService method populateIndexesOfAllTypes.

private void populateIndexesOfAllTypes(MutableLongObjectMap<IndexDescriptor> rebuildingDescriptors, IndexMap indexMap) {
    Map<EntityType, MutableLongObjectMap<IndexDescriptor>> rebuildingDescriptorsByType = new EnumMap<>(EntityType.class);
    for (IndexDescriptor descriptor : rebuildingDescriptors) {
        rebuildingDescriptorsByType.computeIfAbsent(descriptor.schema().entityType(), type -> new LongObjectHashMap<>()).put(descriptor.getId(), descriptor);
    }
    for (Map.Entry<EntityType, MutableLongObjectMap<IndexDescriptor>> descriptorToPopulate : rebuildingDescriptorsByType.entrySet()) {
        IndexPopulationJob populationJob = newIndexPopulationJob(descriptorToPopulate.getKey(), false, SYSTEM);
        populate(descriptorToPopulate.getValue(), indexMap, populationJob);
    }
}
Also used : EntityType(org.neo4j.common.EntityType) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) Arrays(java.util.Arrays) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Log(org.neo4j.logging.Log) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) LongObjectProcedure(org.eclipse.collections.api.block.procedure.primitive.LongObjectProcedure) UnaryOperator(java.util.function.UnaryOperator) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) Preconditions(org.neo4j.util.Preconditions) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Map(java.util.Map) LongIterable(org.eclipse.collections.api.LongIterable) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Path(java.nio.file.Path) EnumMap(java.util.EnumMap) SYSTEM(org.neo4j.common.Subject.SYSTEM) Collection(java.util.Collection) Set(java.util.Set) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) EntityType(org.neo4j.common.EntityType) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) FAILED(org.neo4j.internal.kernel.api.InternalIndexState.FAILED) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) NODE(org.neo4j.common.EntityType.NODE) Iterators.asResourceIterator(org.neo4j.internal.helpers.collection.Iterators.asResourceIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexSamplingController(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingController) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) Iterators.iterator(org.neo4j.internal.helpers.collection.Iterators.iterator) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) ArrayList(java.util.ArrayList) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) ThrowingConsumer(org.neo4j.function.ThrowingConsumer) POPULATING(org.neo4j.internal.kernel.api.InternalIndexState.POPULATING) IndexPopulationFailure.failure(org.neo4j.kernel.impl.api.index.IndexPopulationFailure.failure) ONLINE(org.neo4j.internal.kernel.api.InternalIndexState.ONLINE) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) NodePropertyAccessor(org.neo4j.storageengine.api.NodePropertyAccessor) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) Subject(org.neo4j.common.Subject) Iterators(org.neo4j.internal.helpers.collection.Iterators) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) Iterables.asList(org.neo4j.internal.helpers.collection.Iterables.asList) IOException(java.io.IOException) IndexActivationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) TimeUnit(java.util.concurrent.TimeUnit) KernelException(org.neo4j.exceptions.KernelException) StringJoiner(java.util.StringJoiner) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) SchemaState(org.neo4j.internal.schema.SchemaState) LongSet(org.eclipse.collections.api.set.primitive.LongSet) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) EnumMap(java.util.EnumMap) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap)

Example 3 with EntityType

use of org.neo4j.common.EntityType in project neo4j by neo4j.

the class IndexingService method init.

/**
 * Called while the database starts up, before recovery.
 */
@Override
public void init() throws IOException {
    validateDefaultProviderExisting();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(INIT_TAG))) {
        indexMapRef.modify(indexMap -> {
            Map<InternalIndexState, List<IndexLogRecord>> indexStates = new EnumMap<>(InternalIndexState.class);
            for (IndexDescriptor descriptor : indexDescriptors) {
                // No index (except NLI) is allowed to have the name generated for NLI.
                if (descriptor.getName().equals(IndexDescriptor.NLI_GENERATED_NAME) && !(descriptor.schema().isAnyTokenSchemaDescriptor() && descriptor.schema().entityType() == NODE)) {
                    throw new IllegalStateException("Index '" + descriptor.userDescription(tokenNameLookup) + "' is using a reserved name: '" + IndexDescriptor.NLI_GENERATED_NAME + "'. This index must be removed on an earlier version " + "to be able to use binaries for version 4.3 or newer.");
                }
                IndexProxy indexProxy;
                IndexProviderDescriptor providerDescriptor = descriptor.getIndexProvider();
                IndexProvider provider = providerMap.lookup(providerDescriptor);
                InternalIndexState initialState = provider.getInitialState(descriptor, cursorContext);
                indexStates.computeIfAbsent(initialState, internalIndexState -> new ArrayList<>()).add(new IndexLogRecord(descriptor));
                internalLog.debug(indexStateInfo("init", initialState, descriptor));
                switch(initialState) {
                    case ONLINE:
                        monitor.initialState(databaseName, descriptor, ONLINE);
                        indexProxy = indexProxyCreator.createOnlineIndexProxy(descriptor);
                        break;
                    case POPULATING:
                        // The database was shut down during population, or a crash has occurred, or some other sad thing.
                        monitor.initialState(databaseName, descriptor, POPULATING);
                        indexProxy = indexProxyCreator.createRecoveringIndexProxy(descriptor);
                        break;
                    case FAILED:
                        monitor.initialState(databaseName, descriptor, FAILED);
                        IndexPopulationFailure failure = failure(provider.getPopulationFailure(descriptor, cursorContext));
                        indexProxy = indexProxyCreator.createFailedIndexProxy(descriptor, failure);
                        break;
                    default:
                        throw new IllegalArgumentException("" + initialState);
                }
                indexMap.putIndexProxy(indexProxy);
            }
            logIndexStateSummary("init", indexStates);
            return indexMap;
        });
    }
    indexStatisticsStore.init();
}
Also used : LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) Arrays(java.util.Arrays) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Log(org.neo4j.logging.Log) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) LongObjectProcedure(org.eclipse.collections.api.block.procedure.primitive.LongObjectProcedure) UnaryOperator(java.util.function.UnaryOperator) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) Preconditions(org.neo4j.util.Preconditions) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Map(java.util.Map) LongIterable(org.eclipse.collections.api.LongIterable) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Path(java.nio.file.Path) EnumMap(java.util.EnumMap) SYSTEM(org.neo4j.common.Subject.SYSTEM) Collection(java.util.Collection) Set(java.util.Set) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) EntityType(org.neo4j.common.EntityType) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) FAILED(org.neo4j.internal.kernel.api.InternalIndexState.FAILED) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) NODE(org.neo4j.common.EntityType.NODE) Iterators.asResourceIterator(org.neo4j.internal.helpers.collection.Iterators.asResourceIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexSamplingController(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingController) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) Iterators.iterator(org.neo4j.internal.helpers.collection.Iterators.iterator) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) ArrayList(java.util.ArrayList) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) ThrowingConsumer(org.neo4j.function.ThrowingConsumer) POPULATING(org.neo4j.internal.kernel.api.InternalIndexState.POPULATING) IndexPopulationFailure.failure(org.neo4j.kernel.impl.api.index.IndexPopulationFailure.failure) ONLINE(org.neo4j.internal.kernel.api.InternalIndexState.ONLINE) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) NodePropertyAccessor(org.neo4j.storageengine.api.NodePropertyAccessor) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) Subject(org.neo4j.common.Subject) Iterators(org.neo4j.internal.helpers.collection.Iterators) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) Iterables.asList(org.neo4j.internal.helpers.collection.Iterables.asList) IOException(java.io.IOException) IndexActivationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) TimeUnit(java.util.concurrent.TimeUnit) KernelException(org.neo4j.exceptions.KernelException) StringJoiner(java.util.StringJoiner) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) SchemaState(org.neo4j.internal.schema.SchemaState) LongSet(org.eclipse.collections.api.set.primitive.LongSet) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) ArrayList(java.util.ArrayList) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) List(java.util.List) ArrayList(java.util.ArrayList) Iterables.asList(org.neo4j.internal.helpers.collection.Iterables.asList) EnumMap(java.util.EnumMap)

Example 4 with EntityType

use of org.neo4j.common.EntityType in project neo4j by neo4j.

the class FulltextProcedures method queryFulltextForRelationships.

@SystemProcedure
@Description("Query the given full-text index. Returns the matching relationships, and their Lucene query score, ordered by score. " + "Valid keys for the options map are: 'skip' to skip the top N results; 'limit' to limit the number of results returned.")
@Procedure(name = "db.index.fulltext.queryRelationships", mode = READ)
public Stream<RelationshipOutput> queryFulltextForRelationships(@Name("indexName") String name, @Name("queryString") String query, @Name(value = "options", defaultValue = "{}") Map<String, Object> options) throws Exception {
    if (callContext.isSystemDatabase()) {
        return Stream.empty();
    }
    IndexDescriptor indexReference = getValidIndex(name);
    awaitOnline(indexReference);
    EntityType entityType = indexReference.schema().entityType();
    if (entityType != RELATIONSHIP) {
        throw new IllegalArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for relationships.");
    }
    RelationshipValueIndexCursor cursor = tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
    IndexReadSession indexReadSession = tx.dataRead().indexReadSession(indexReference);
    IndexQueryConstraints constraints = queryConstraints(options);
    tx.dataRead().relationshipIndexSeek(indexReadSession, cursor, constraints, PropertyIndexQuery.fulltextSearch(query));
    Spliterator<RelationshipOutput> spliterator = new SpliteratorAdaptor<>() {

        @Override
        public boolean tryAdvance(Consumer<? super RelationshipOutput> action) {
            while (cursor.next()) {
                long relationshipReference = cursor.relationshipReference();
                float score = cursor.score();
                RelationshipOutput relationshipOutput = RelationshipOutput.forExistingEntityOrNull(transaction, relationshipReference, score);
                if (relationshipOutput != null) {
                    action.accept(relationshipOutput);
                    return true;
                }
            }
            cursor.close();
            return false;
        }
    };
    return StreamSupport.stream(spliterator, false).onClose(cursor::close);
}
Also used : RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EntityType(org.neo4j.common.EntityType) Consumer(java.util.function.Consumer) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 5 with EntityType

use of org.neo4j.common.EntityType in project neo4j by neo4j.

the class TokenIndexProvider method indexFiles.

private IndexFiles indexFiles(IndexDescriptor descriptor) {
    EntityType entityType = descriptor.schema().entityType();
    boolean labelIndex = entityType == EntityType.NODE;
    Path filePath = labelIndex ? databaseLayout.labelScanStore() : databaseLayout.relationshipTypeScanStore();
    return new IndexFiles.SingleFile(databaseIndexContext.fileSystem, filePath);
}
Also used : EntityType(org.neo4j.common.EntityType) Path(java.nio.file.Path)

Aggregations

EntityType (org.neo4j.common.EntityType)15 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)9 Arrays (java.util.Arrays)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 Config (org.neo4j.configuration.Config)5 Iterators (org.neo4j.internal.helpers.collection.Iterators)5 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)5 Collectors (java.util.stream.Collectors)4 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 String.format (java.lang.String.format)3 Iterator (java.util.Iterator)3 TimeUnit (java.util.concurrent.TimeUnit)3 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)3 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)3 Log (org.neo4j.logging.Log)3