Search in sources :

Example 11 with EntityType

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

the class GraphCountsSection method constraints.

private static List<Map<String, Object>> constraints(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) {
    List<Map<String, Object>> constraints = new ArrayList<>();
    Iterator<ConstraintDescriptor> iterator = schemaRead.constraintsGetAll();
    while (iterator.hasNext()) {
        ConstraintDescriptor constraint = iterator.next();
        EntityType entityType = constraint.schema().entityType();
        Map<String, Object> data = new HashMap<>();
        data.put("properties", map(constraint.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
        data.put("type", constraintType(constraint));
        int entityTokenId = constraint.schema().getEntityTokenIds()[0];
        switch(entityType) {
            case NODE:
                data.put("label", anonymizer.label(tokens.labelGetName(entityTokenId), entityTokenId));
                constraints.add(data);
                break;
            case RELATIONSHIP:
                data.put("relationshipType", anonymizer.relationshipType(tokens.relationshipTypeGetName(entityTokenId), entityTokenId));
                constraints.add(data);
                break;
            default:
        }
    }
    return constraints;
}
Also used : EntityType(org.neo4j.common.EntityType) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) IndexType(org.neo4j.internal.schema.IndexType) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) Kernel(org.neo4j.kernel.api.Kernel) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Stream(java.util.stream.Stream) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) EntityType(org.neo4j.common.EntityType) Map(java.util.Map) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NamedToken(org.neo4j.token.api.NamedToken) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) IntFunction(java.util.function.IntFunction) HashMap(java.util.HashMap) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with EntityType

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

the class SchemaRuleSerialization35 method readMultiTokenSchema.

private static SchemaDescriptor readMultiTokenSchema(ByteBuffer source) throws MalformedSchemaRuleException {
    byte schemaDescriptorType = source.get();
    EntityType type;
    switch(schemaDescriptorType) {
        case SIMPLE_LABEL:
            type = EntityType.NODE;
            break;
        case SIMPLE_REL_TYPE:
            type = EntityType.RELATIONSHIP;
            break;
        default:
            throw new MalformedSchemaRuleException(format("Got unknown schema descriptor type '%d'.", schemaDescriptorType));
    }
    int[] entityTokenIds = readTokenIdList(source);
    int[] propertyIds = readTokenIdList(source);
    return SchemaDescriptor.fulltext(type, entityTokenIds, propertyIds);
}
Also used : EntityType(org.neo4j.common.EntityType) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)

Example 13 with EntityType

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

the class TokenScanWriteMonitor method dump.

public static void dump(FileSystemAbstraction fs, DatabaseLayout databaseLayout, Dumper dumper, TxFilter txFilter, EntityType entityType) throws IOException {
    Path writeLogFile = writeLogBaseFile(databaseLayout, entityType);
    String writeLogFileBaseName = writeLogFile.getFileName().toString();
    Path[] files = fs.listFiles(databaseLayout.databaseDirectory(), name -> name.getFileName().toString().startsWith(writeLogFileBaseName));
    Arrays.sort(files, comparing(file -> file.getFileName().toString().equals(writeLogFileBaseName) ? 0 : millisOf(file)));
    long session = 0;
    for (Path file : files) {
        dumper.file(file);
        session = dumpFile(fs, file, dumper, txFilter, session);
    }
}
Also used : Path(java.nio.file.Path) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) SystemNanoClock(org.neo4j.time.SystemNanoClock) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) BufferedOutputStream(java.io.BufferedOutputStream) DEFAULT_READ_AHEAD_SIZE(org.neo4j.io.fs.ReadAheadChannel.DEFAULT_READ_AHEAD_SIZE) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) Comparator.comparing(java.util.Comparator.comparing) ReadAheadChannel(org.neo4j.io.fs.ReadAheadChannel) Path(java.nio.file.Path) FlushableChannel(org.neo4j.io.fs.FlushableChannel) PrintStream(java.io.PrintStream) ByteUnit(org.neo4j.io.ByteUnit) PhysicalFlushableChannel(org.neo4j.io.fs.PhysicalFlushableChannel) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Files(java.nio.file.Files) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) IOException(java.io.IOException) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException) String.format(java.lang.String.format) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) Args(org.neo4j.internal.helpers.Args) Lock(java.util.concurrent.locks.Lock) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) EntityType(org.neo4j.common.EntityType) ReadableChannel(org.neo4j.io.fs.ReadableChannel) Clocks(org.neo4j.time.Clocks) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction)

Example 14 with EntityType

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

the class FulltextProcedures method queryFulltextForNodes.

@SystemProcedure
@Description("Query the given full-text index. Returns the matching nodes, 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.queryNodes", mode = READ)
public Stream<NodeOutput> queryFulltextForNodes(@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 != NODE) {
        throw new IllegalArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for nodes.");
    }
    NodeValueIndexCursor cursor = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker());
    IndexReadSession indexSession = tx.dataRead().indexReadSession(indexReference);
    IndexQueryConstraints constraints = queryConstraints(options);
    tx.dataRead().nodeIndexSeek(indexSession, cursor, constraints, PropertyIndexQuery.fulltextSearch(query));
    Spliterator<NodeOutput> spliterator = new SpliteratorAdaptor<>() {

        @Override
        public boolean tryAdvance(Consumer<? super NodeOutput> action) {
            while (cursor.next()) {
                long nodeReference = cursor.nodeReference();
                float score = cursor.score();
                NodeOutput nodeOutput = NodeOutput.forExistingEntityOrNull(transaction, nodeReference, score);
                if (nodeOutput != null) {
                    action.accept(nodeOutput);
                    return true;
                }
            }
            cursor.close();
            return false;
        }
    };
    Stream<NodeOutput> stream = StreamSupport.stream(spliterator, false);
    return stream.onClose(cursor::close);
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) 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 15 with EntityType

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

the class GraphCountsSection method indexes.

private static List<Map<String, Object>> indexes(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) throws IndexNotFoundKernelException {
    List<Map<String, Object>> indexes = new ArrayList<>();
    Iterator<IndexDescriptor> iterator = schemaRead.indexesGetAll();
    while (iterator.hasNext()) {
        IndexDescriptor index = iterator.next();
        IndexType indexType = index.getIndexType();
        if (indexType == IndexType.FULLTEXT) {
            /* For full text indexes, we currently do not return its options, which makes returning information on
                 * this index not useful and if the index type is ignored, this would even be misleading.
                 */
            continue;
        }
        EntityType entityType = index.schema().entityType();
        Map<String, Object> data = new HashMap<>();
        switch(entityType) {
            case NODE:
                data.put("labels", map(index.schema().getEntityTokenIds(), id -> anonymizer.label(tokens.labelGetName(id), id)));
                break;
            case RELATIONSHIP:
                data.put("relationshipTypes", map(index.schema().getEntityTokenIds(), id -> anonymizer.relationshipType(tokens.relationshipTypeGetName(id), id)));
                break;
            default:
        }
        data.put("properties", map(index.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
        var indexSample = schemaRead.indexSample(index);
        data.put("totalSize", indexSample.indexSize());
        data.put("updatesSinceEstimation", indexSample.updates());
        data.put("estimatedUniqueSize", indexSample.uniqueValues());
        data.put("indexType", indexType.name());
        indexes.add(data);
    }
    return indexes;
}
Also used : Arrays(java.util.Arrays) Iterator(java.util.Iterator) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) IndexType(org.neo4j.internal.schema.IndexType) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) Kernel(org.neo4j.kernel.api.Kernel) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Stream(java.util.stream.Stream) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) EntityType(org.neo4j.common.EntityType) Map(java.util.Map) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NamedToken(org.neo4j.token.api.NamedToken) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) IntFunction(java.util.function.IntFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) EntityType(org.neo4j.common.EntityType) IndexType(org.neo4j.internal.schema.IndexType) HashMap(java.util.HashMap) Map(java.util.Map)

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