From 32789498e82bbbf0c81f1253753831c46ab076b7 Mon Sep 17 00:00:00 2001 From: Giuseppe Villani Date: Thu, 13 Jan 2022 13:10:44 +0100 Subject: [PATCH] Fixes #577: return apoc.nodes.count(['User']) (#2277) --- core/src/main/java/apoc/meta/Meta.java | 47 +++++++++++++ core/src/test/java/apoc/meta/MetaTest.java | 46 ++++++++++++- .../apoc.meta.nodes-lite.csv | 2 + .../apoc.meta.nodes.count-lite.csv | 2 + .../apoc.meta.nodes.count.adoc | 5 ++ .../apoc.meta.nodes.csv | 6 ++ .../generated-documentation/documentation.csv | 1 + .../apoc.meta/apoc.meta.nodes.count.adoc | 34 ++++++++++ .../ROOT/pages/overview/apoc.meta/index.adoc | 5 ++ .../documentation.adoc | 5 ++ .../partials/generated-documentation/nav.adoc | 1 + .../partials/usage/apoc.meta.nodes.count.adoc | 66 +++++++++++++++++++ .../usage/config/apoc.meta.nodes.count.adoc | 9 +++ 13 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 docs/asciidoc/modules/ROOT/examples/generated-documentation/apoc.meta.nodes-lite.csv create mode 100644 docs/asciidoc/modules/ROOT/examples/generated-documentation/apoc.meta.nodes.count-lite.csv create mode 100644 docs/asciidoc/modules/ROOT/examples/generated-documentation/apoc.meta.nodes.count.adoc create mode 100644 docs/asciidoc/modules/ROOT/examples/generated-documentation/apoc.meta.nodes.csv create mode 100644 docs/asciidoc/modules/ROOT/pages/overview/apoc.meta/apoc.meta.nodes.count.adoc create mode 100644 docs/asciidoc/modules/ROOT/partials/usage/apoc.meta.nodes.count.adoc create mode 100644 docs/asciidoc/modules/ROOT/partials/usage/config/apoc.meta.nodes.count.adoc diff --git a/core/src/main/java/apoc/meta/Meta.java b/core/src/main/java/apoc/meta/Meta.java index f94ccd8206..98399cf515 100644 --- a/core/src/main/java/apoc/meta/Meta.java +++ b/core/src/main/java/apoc/meta/Meta.java @@ -58,6 +58,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ThreadLocalRandom; @@ -372,6 +373,52 @@ public Stream stats() { return Stream.of(collectStats()); } + @UserFunction(name = "apoc.meta.nodes.count") + @Description("apoc.meta.nodes.count([labels], $config) - Returns the sum of the nodes with a label present in the list.") + public long count(@Name(value = "nodes", defaultValue = "[]") List nodes, @Name(value = "config", defaultValue = "{}") Map config) { + MetaConfig conf = new MetaConfig(config); + final DatabaseSubGraph subGraph = new DatabaseSubGraph(transaction); + Stream