Search in sources :

Example 36 with Description

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

the class Store method store.

@Procedure
@Description("apoc.monitor.store() returns informations about the sizes of the different parts of the neo4j graph store")
public Stream<StoreInfoResult> store() {
    ObjectName objectName = getObjectName(db, JMX_OBJECT_NAME);
    StoreInfoResult storeInfo = new StoreInfoResult(getAttribute(objectName, LOG_SIZE), getAttribute(objectName, STRING_SIZE), getAttribute(objectName, ARRAY_SIZE), getAttribute(objectName, REL_SIZE), getAttribute(objectName, PROP_SIZE), getAttribute(objectName, TOTAL_SIZE), getAttribute(objectName, NODE_SIZE));
    return Stream.of(storeInfo);
}
Also used : StoreInfoResult(apoc.result.StoreInfoResult) ObjectName(javax.management.ObjectName) JmxUtils.getObjectName(org.neo4j.jmx.JmxUtils.getObjectName) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 37 with Description

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

the class PathExplorer method subgraphAll.

@Procedure("apoc.path.subgraphAll")
@Description("apoc.path.subgraphAll(startNode <id>|Node|list, {maxLevel,relationshipFilter,labelFilter,bfs:true, filterStartNode:false, limit:-1, endNodes:[], terminatorNodes:[], sequence, beginSequenceAtStart:true}) yield nodes, relationships - expand the subgraph reachable from start node following relationships to max-level adhering to the label filters, and also return all relationships within the subgraph")
public Stream<GraphResult> subgraphAll(@Name("start") Object start, @Name("config") Map<String, Object> config) throws Exception {
    Map<String, Object> configMap = new HashMap<>(config);
    // not needed, will return empty collections anyway if no results
    configMap.remove("optional");
    configMap.put("uniqueness", "NODE_GLOBAL");
    if (config.containsKey("minLevel")) {
        throw new IllegalArgumentException("minLevel not supported in subgraphAll");
    }
    List<Node> subgraphNodes = expandConfigPrivate(start, configMap).map(Path::endNode).collect(Collectors.toList());
    List<Relationship> subgraphRels = Cover.coverNodes(subgraphNodes).collect(Collectors.toList());
    return Stream.of(new GraphResult(subgraphNodes, subgraphRels));
}
Also used : GraphResult(apoc.result.GraphResult) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 38 with Description

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

the class Graphs method fromPaths.

@Description("apoc.graph.fromPaths([paths],'name',{properties}) - creates a virtual graph object for later processing")
@Procedure
public Stream<VirtualGraph> fromPaths(@Name("paths") List<Path> paths, @Name("name") String name, @Name("properties") Map<String, Object> properties) {
    List<Node> nodes = new ArrayList<>(1000);
    List<Relationship> rels = new ArrayList<>(1000);
    for (Path path : paths) {
        Iterables.addAll(nodes, path.nodes());
        Iterables.addAll(rels, path.relationships());
    }
    return Stream.of(new VirtualGraph(name, nodes, rels, properties));
}
Also used : Path(org.neo4j.graphdb.Path) VirtualGraph(apoc.result.VirtualGraph) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 39 with Description

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

the class Graphs method from.

@Description("apoc.graph.from(data,'name',{properties}) | creates a virtual graph object for later processing it tries its best to extract the graph information from the data you pass in")
@Procedure
public Stream<VirtualGraph> from(@Name("data") Object data, @Name("name") String name, @Name("properties") Map<String, Object> properties) {
    Set<Node> nodes = new HashSet<>(1000);
    Set<Relationship> rels = new HashSet<>(10000);
    extract(data, nodes, rels);
    return Stream.of(new VirtualGraph(name, nodes, rels, properties));
}
Also used : VirtualGraph(apoc.result.VirtualGraph) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 40 with Description

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

the class Strings method toCypher.

@UserFunction
@Description("apoc.text.toCypher(value, {skipKeys,keepKeys,skipValues,keepValues,skipNull,node,relationship,start,end}) | tries it's best to convert the value to a cypher-property-string")
public String toCypher(@Name("value") Object value, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) {
    if (config.containsKey("keepValues") && !((Collection) config.get("keepValues")).stream().noneMatch((v) -> (v.getClass().isInstance(value) || isPrimitive(value) && isPrimitive(v)) && !value.equals(v)))
        return null;
    else if (config.containsKey("skipValues") && ((Collection) config.get("skipValues")).contains(value))
        return null;
    if (value == null)
        return "null";
    if (value instanceof Number || value instanceof Boolean)
        return value.toString();
    if (value instanceof String)
        return '\'' + value.toString() + '\'';
    if (value instanceof Iterable)
        return '[' + StreamSupport.stream(((Iterable<?>) value).spliterator(), false).map(v -> toCypher(v, config)).filter(Objects::nonNull).collect(Collectors.joining(",")) + ']';
    if (value.getClass().isArray())
        return '[' + Arrays.stream((Object[]) value).map(v -> toCypher(v, config)).filter(Objects::nonNull).collect(Collectors.joining(",")) + ']';
    if (value instanceof Node) {
        Node node = (Node) value;
        String labels = StreamSupport.stream(node.getLabels().spliterator(), false).map(l -> quote(l.name())).collect(Collectors.joining(":"));
        if (!labels.isEmpty())
            labels = ':' + labels;
        String var = cypherName(config, "node", () -> "", Util::quote);
        return '(' + var + labels + ' ' + toCypher(node.getAllProperties(), config) + ')';
    }
    if (value instanceof Relationship) {
        Relationship rel = (Relationship) value;
        String type = ':' + quote(rel.getType().name());
        String start = cypherName(config, "start", () -> toCypher(rel.getStartNode(), config), (s) -> '(' + quote(s) + ')');
        String relationship = cypherName(config, "relationship", () -> "", Util::quote);
        String end = cypherName(config, "end", () -> toCypher(rel.getEndNode(), config), (s) -> '(' + quote(s) + ')');
        return start + "-[" + relationship + type + ' ' + toCypher(rel.getAllProperties(), config) + "]->" + end;
    }
    if (value instanceof Map) {
        Map<String, Object> values = (Map<String, Object>) value;
        if (config.containsKey("keepKeys")) {
            values.keySet().retainAll((List<String>) (config.get("keepKeys")));
        }
        if (config.containsKey("skipKeys")) {
            values.keySet().removeAll((List<String>) (config.get("skipKeys")));
        }
        return '{' + values.entrySet().stream().map((e) -> Pair.of(e.getKey(), toCypher(e.getValue(), config))).filter((p) -> p.other() != null).sorted(Comparator.comparing(Pair::first)).map((p) -> quote(p.first()) + ":" + p.other()).collect(Collectors.joining(",")) + '}';
    }
    return null;
}
Also used : java.util(java.util) URLDecoder(java.net.URLDecoder) Pair(org.neo4j.helpers.collection.Pair) Function(java.util.function.Function) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) Node(org.neo4j.graphdb.Node) Matcher(java.util.regex.Matcher) Util.quote(apoc.util.Util.quote) Arrays.asList(java.util.Arrays.asList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) StreamSupport(java.util.stream.StreamSupport) Math.toIntExact(java.lang.Math.toIntExact) Util(apoc.util.Util) Procedure(org.neo4j.procedure.Procedure) Description(org.neo4j.procedure.Description) StringResult(apoc.result.StringResult) Collectors(java.util.stream.Collectors) UserFunction(org.neo4j.procedure.UserFunction) Normalizer(java.text.Normalizer) URLEncoder(java.net.URLEncoder) Relationship(org.neo4j.graphdb.Relationship) Stream(java.util.stream.Stream) Name(org.neo4j.procedure.Name) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Node(org.neo4j.graphdb.Node) Util(apoc.util.Util) Relationship(org.neo4j.graphdb.Relationship) Description(org.neo4j.procedure.Description) UserFunction(org.neo4j.procedure.UserFunction)

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