Search in sources :

Example 31 with Description

use of org.neo4j.procedure.Description in project neo4j by neo4j.

the class BuiltInProcedures method listIndexes.

@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ)
public Stream<IndexResult> listIndexes() throws ProcedureException {
    try (Statement statement = tx.acquireStatement()) {
        ReadOperations operations = statement.readOperations();
        TokenNameLookup tokens = new StatementTokenNameLookup(operations);
        List<NewIndexDescriptor> indexes = asList(operations.indexesGetAll());
        Set<NewIndexDescriptor> uniqueIndexes = asSet(operations.uniqueIndexesGetAll());
        indexes.addAll(uniqueIndexes);
        indexes.sort(Comparator.comparing(a -> a.userDescription(tokens)));
        ArrayList<IndexResult> result = new ArrayList<>();
        for (NewIndexDescriptor index : indexes) {
            try {
                String type;
                if (uniqueIndexes.contains(index)) {
                    type = IndexType.NODE_UNIQUE_PROPERTY.typeName();
                } else {
                    type = IndexType.NODE_LABEL_PROPERTY.typeName();
                }
                result.add(new IndexResult("INDEX ON " + index.schema().userDescription(tokens), operations.indexGetState(index).toString(), type));
            } catch (IndexNotFoundKernelException e) {
                throw new ProcedureException(Status.Schema.IndexNotFound, e, "No index on ", index.userDescription(tokens));
            }
        }
        return result.stream();
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Label(org.neo4j.graphdb.Label) Context(org.neo4j.procedure.Context) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ArrayList(java.util.ArrayList) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) Procedure(org.neo4j.procedure.Procedure) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) ReadOperations(org.neo4j.kernel.api.ReadOperations) Set(java.util.Set) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) Comparator(java.util.Comparator) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ReadOperations(org.neo4j.kernel.api.ReadOperations) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 32 with Description

use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.

the class SchemaIndex method orderedByText.

@Procedure
@Description("apoc.index.orderedByText(label,key,operator,value,sort-relevance,limit) yield node - schema string search which keeps index order and adds limit, operator is 'STARTS WITH' or 'CONTAINS'")
public Stream<NodeResult> orderedByText(@Name("label") String label, @Name("key") String key, @Name("operator") String operator, @Name("value") String value, @Name("relevance") boolean relevance, @Name("limit") long limit) throws SchemaRuleNotFoundException, IndexNotFoundKernelException, DuplicateSchemaRuleException {
    SortedIndexReader sortedIndexReader = getSortedIndexReader(label, key, limit, getSort(value, value, relevance));
    PrimitiveLongIterator it = queryForString(sortedIndexReader, operator, value);
    return Util.toLongStream(it).mapToObj(id -> new NodeResult(db.getNodeById(id)));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) SortedIndexReader(org.neo4j.kernel.api.impl.schema.reader.SortedIndexReader) NodeResult(apoc.result.NodeResult) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 33 with Description

use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.

the class LoadCsv method csv.

@Procedure
@Description("apoc.load.csv('url',{config}) YIELD lineNo, list, map - load CSV fom URL as stream of values,\n config contains any of: {skip:1,limit:5,header:false,sep:'TAB',ignore:['tmp'],arraySep:';',mapping:{years:{type:'int',arraySep:'-',array:false,name:'age',ignore:false}}")
public Stream<CSVResult> csv(@Name("url") String url, @Name("config") Map<String, Object> config) {
    boolean failOnError = booleanValue(config, "failOnError", true);
    try {
        CountingReader reader = FileUtils.readerFor(url);
        char separator = separator(config, "sep", DEFAULT_SEP);
        char arraySep = separator(config, "arraySep", DEFAULT_ARRAY_SEP);
        long skip = longValue(config, "skip", 0L);
        boolean hasHeader = booleanValue(config, "header", true);
        long limit = longValue(config, "limit", Long.MAX_VALUE);
        EnumSet<Results> results = EnumSet.noneOf(Results.class);
        for (String result : value(config, "results", asList("map", "list"))) {
            results.add(Results.valueOf(result));
        }
        List<String> ignore = value(config, "ignore", emptyList());
        List<String> nullValues = value(config, "nullValues", emptyList());
        Map<String, Map<String, Object>> mapping = value(config, "mapping", Collections.emptyMap());
        Map<String, Mapping> mappings = createMapping(mapping, arraySep, ignore);
        CSVReader csv = new CSVReader(reader, separator);
        String[] header = getHeader(hasHeader, csv, ignore, mappings);
        boolean checkIgnore = !ignore.isEmpty() || mappings.values().stream().anyMatch(m -> m.ignore);
        return StreamSupport.stream(new CSVSpliterator(csv, header, url, skip, limit, checkIgnore, mappings, nullValues, results), false);
    } catch (IOException e) {
        if (!failOnError)
            return Stream.of(new CSVResult(new String[0], new String[0], 0, true, Collections.emptyMap(), emptyList(), EnumSet.noneOf(Results.class)));
        else
            throw new RuntimeException("Can't read CSV from URL " + cleanUrl(url), e);
    }
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) FileUtils(apoc.util.FileUtils) java.util(java.util) Meta(apoc.meta.Meta) Context(org.neo4j.procedure.Context) Collections.emptyList(java.util.Collections.emptyList) IOException(java.io.IOException) Description(org.neo4j.procedure.Description) CountingReader(apoc.export.util.CountingReader) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) CSVReader(au.com.bytecode.opencsv.CSVReader) Util.cleanUrl(apoc.util.Util.cleanUrl) Arrays.asList(java.util.Arrays.asList) Name(org.neo4j.procedure.Name) StreamSupport(java.util.stream.StreamSupport) Pattern(java.util.regex.Pattern) Util(apoc.util.Util) Procedure(org.neo4j.procedure.Procedure) CountingReader(apoc.export.util.CountingReader) CSVReader(au.com.bytecode.opencsv.CSVReader) IOException(java.io.IOException) Collections.emptyMap(java.util.Collections.emptyMap) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 34 with Description

use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.

the class Locks method lockInfo.

@Procedure("apoc.monitor.locks")
@Deprecated
@Description("deprecated, the information is not provided by neo4j anymore.\napoc.monitor.locks(minWaitTime) yield advertedDeadLocks, lockCount, contendedLockCount, minimumWaitTimeMs, contendedLocks, info")
public Stream<LockInfoResult> lockInfo(@Name("minWaitTime") Long minWaitTime) {
    if (minWaitTime == null || minWaitTime < 0)
        minWaitTime = 0L;
    ObjectName objectName = getObjectName(database, JMX_OBJECT_NAME);
    CompositeData[] locks = getAttribute(objectName, JMX_LOCKS_KEY);
    List<Map<String, Object>> lockInfos = getContentedLocks(objectName, minWaitTime);
    Long avertedDeadLocks = getAttribute(objectName, JMX_NR_ADVERTED_DEADLOCKS_KEY);
    LockInfoResult info = new LockInfoResult(minWaitTime, locks.length, avertedDeadLocks, lockInfos.size(), lockInfos);
    return Stream.of(info);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) HashMap(java.util.HashMap) Map(java.util.Map) ObjectName(javax.management.ObjectName) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 35 with Description

use of org.neo4j.procedure.Description in project neo4j-apoc-procedures by neo4j-contrib.

the class Kernel method kernel.

@Procedure
@Description("apoc.monitor.kernel() returns informations about the neo4j kernel")
public Stream<KernelInfoResult> kernel() {
    ObjectName objectName = getObjectName(database, JMX_OBJECT_NAME);
    KernelInfoResult info = new KernelInfoResult(getAttribute(objectName, READ_ONLY), getAttribute(objectName, KERNEL_VERSION), getAttribute(objectName, STORE_ID), getAttribute(objectName, START_TIME), getAttribute(objectName, DB_NAME), getAttribute(objectName, STORE_LOG_VERSION), getAttribute(objectName, STORE_CREATION_DATE));
    return Stream.of(info);
}
Also used : KernelInfoResult(apoc.result.KernelInfoResult) ObjectName(javax.management.ObjectName) JmxUtils.getObjectName(org.neo4j.jmx.JmxUtils.getObjectName) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Aggregations

Description (org.neo4j.procedure.Description)65 Procedure (org.neo4j.procedure.Procedure)58 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)25 ArrayList (java.util.ArrayList)19 Node (org.neo4j.graphdb.Node)15 HashMap (java.util.HashMap)14 Stream (java.util.stream.Stream)14 Map (java.util.Map)13 Context (org.neo4j.procedure.Context)13 Name (org.neo4j.procedure.Name)13 Collectors (java.util.stream.Collectors)12 Relationship (org.neo4j.graphdb.Relationship)12 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)12 ZoneId (java.time.ZoneId)11 Comparator (java.util.Comparator)11 List (java.util.List)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)11 Status (org.neo4j.kernel.api.exceptions.Status)11 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)11 Admin (org.neo4j.procedure.Admin)11