Skip to content

Commit

Permalink
Merge branch '4.1' of github.com:neo4j-contrib/neo4j-apoc-procedures …
Browse files Browse the repository at this point in the history
…into 4.1
  • Loading branch information
Max Andersson committed Oct 1, 2021
2 parents 2996031 + fbc7334 commit 5775c43
Show file tree
Hide file tree
Showing 604 changed files with 12,611 additions and 8,007 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build --continue
run: ./gradlew build
2 changes: 1 addition & 1 deletion 40_notes.adoc
Expand Up @@ -8,7 +8,7 @@ All freetext/fulltext stuff has been removed in favour of 3.5+ productized fullt
apoc.index.relatedNodes (index feature ootb)
apoc.index.orderedRange (index feature ootb)

apoc.algo.* (use separate graph algo apackage instead)
apoc.algo.* (use separate graph algo package instead)

apoc.static.get (proc deleted, function exists)
apoc.static.getAll (proc deleted, function exists)
Expand Down
13 changes: 8 additions & 5 deletions build.gradle
Expand Up @@ -28,8 +28,7 @@ repositories {
/*maven { // this contains the neo4j 4.0.0-beta jars
url "https://neo4j.bintray.com/community/"
}*/
jcenter()
//mavenCentral()
mavenCentral()
maven {
url "https://repo.gradle.org/gradle/libs-releases"
}
Expand All @@ -44,8 +43,7 @@ subprojects {
/*maven { // this contains the neo4j 4.0.0-beta jars
url "https://neo4j.bintray.com/community/"
}*/
jcenter()
//mavenCentral()
mavenCentral()
maven {
url "https://repo.gradle.org/gradle/libs-releases"
}
Expand Down Expand Up @@ -86,7 +84,12 @@ subprojects {
setFailOnNoMatchingTests(false)
}

ignoreFailures(true)
// in TC we don't have the CI env so we can manage it in this way
if (System.env.TEAMCITY_VERSION != null) {
ignoreFailures(true)
}
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
}

configurations {
Expand Down
16 changes: 8 additions & 8 deletions core/build.gradle
Expand Up @@ -36,13 +36,12 @@ generateGrammarSource {
}

dependencies {

testCompile project(':test-utils')
apt project(':processor')

// apt 'net.biville.florent:neo4j-sproc-compiler:1.2' // temporarily disabled until byte[] is supported by sproc compiler
apt group: 'org.neo4j', name: 'neo4j', version: neo4jVersionEffective
apt group: 'org.neo4j', name: 'neo4j', version: neo4jVersionEffective
compile group: 'commons-codec', name: 'commons-codec', version: '1.14'
compileOnly group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
testCompile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
compile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.4.0'
compile group: 'net.minidev', name: 'json-smart', version: '2.4.2'
compile group: 'org.hdrhistogram', name: 'HdrHistogram', version: '2.1.9'
Expand Down Expand Up @@ -112,8 +111,8 @@ dependencies {

testCompile group: 'org.apache.hive', name: 'hive-jdbc', version: '1.2.2', withoutServers

compileOnly group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: '2.7.5', withoutServers
compileOnly group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.5', withoutServers
compileOnly group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: '3.3.1', withoutServers
compileOnly group: 'org.apache.hadoop', name: 'hadoop-common', version: '3.3.1', withoutServers

compile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
// explicit update comomns.io version
Expand All @@ -135,8 +134,9 @@ dependencies {
exclude group: 'com.google.guava', module: 'guava'
}

// there is a compatibility problem between the Guava Library used by HDFS, Google Cloud Storage and Reflections; the only version that fits for all is the following
compile group: 'com.google.guava', name: 'guava', version: '20.0'
compile group: 'com.google.guava', name: 'guava', version: '27.0-jre'

compile group: 'xerces', name: 'xercesImpl', version: '2.12.1'

configurations.all {
exclude group: 'org.slf4j', module: 'slf4j-nop'
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/apoc/CoreApocGlobalComponents.java
Expand Up @@ -21,7 +21,8 @@ public Map<String,Lifecycle> getServices(GraphDatabaseAPI db, ApocExtensionFacto
dependencies.apocConfig(),
dependencies.log().getUserLog(TriggerHandler.class),
dependencies.globalProceduresRegistry(),
dependencies.pools())
dependencies.pools(),
dependencies.scheduler())
);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/apoc/SystemLabels.java
Expand Up @@ -8,5 +8,5 @@ public enum SystemLabels implements Label {
Procedure,
Function,
ApocUuid,
ApocTrigger
ApocTriggerMeta, ApocTrigger
}
149 changes: 0 additions & 149 deletions core/src/main/java/apoc/algo/PathFinding.java

This file was deleted.

8 changes: 8 additions & 0 deletions core/src/main/java/apoc/atomic/util/AtomicUtils.java
Expand Up @@ -10,8 +10,12 @@ public class AtomicUtils {
public static Number sum(Number oldValue, Number number){
if(oldValue instanceof Long)
return oldValue.longValue() + number.longValue();
if(oldValue instanceof Integer)
return oldValue.intValue() + number.intValue();
if(oldValue instanceof Double)
return oldValue.doubleValue() + number.doubleValue();
if(oldValue instanceof Float)
return oldValue.floatValue() + number.floatValue();
if(oldValue instanceof Short)
return oldValue.shortValue() + number.shortValue();
if(oldValue instanceof Byte)
Expand All @@ -22,8 +26,12 @@ public static Number sum(Number oldValue, Number number){
public static Number sub(Number oldValue, Number number){
if(oldValue instanceof Long)
return oldValue.longValue() - number.longValue();
if(oldValue instanceof Integer)
return oldValue.intValue() - number.intValue();
if(oldValue instanceof Double)
return oldValue.doubleValue() - number.doubleValue();
if(oldValue instanceof Float)
return oldValue.floatValue() - number.floatValue();
if(oldValue instanceof Short)
return oldValue.shortValue() - number.shortValue();
if(oldValue instanceof Byte)
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/apoc/coll/Coll.java
Expand Up @@ -3,6 +3,7 @@
import apoc.result.ListResult;
import com.google.common.util.concurrent.AtomicDouble;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;
import org.apache.commons.math3.util.Combinations;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
Expand Down Expand Up @@ -51,6 +52,16 @@ public class Coll {

@Context public Transaction tx;

@UserFunction
@Description("apoc.coll.stdev(list, isBiasCorrected) - returns the sample or population standard deviation with isBiasCorrected true or false respectively. For example apoc.coll.stdev([10, 12, 23]) return 7")
public Number stdev(@Name("list") List<Number> list, @Name(value = "isBiasCorrected", defaultValue = "true") boolean isBiasCorrected) {
if (list == null || list.isEmpty()) return null;
final double stdev = new StandardDeviation(isBiasCorrected)
.evaluate(list.stream().mapToDouble(Number::doubleValue).toArray());
if ((long) stdev == stdev) return (long) stdev;
return stdev;
}

@UserFunction
@Description("apoc.coll.runningTotal(list1) - returns an accumulative array. For example apoc.coll.runningTotal([1,2,3.5]) return [1,3,6.5]")
public List<Number> runningTotal(@Name("list") List<Number> list) {
Expand Down
30 changes: 15 additions & 15 deletions core/src/main/java/apoc/convert/Json.java
Expand Up @@ -82,9 +82,9 @@ private Map<String, Object> mapWithOptionalProps(Map<String,Object> mapEntity, M
public org.neo4j.graphdb.GraphDatabaseService db;

@UserFunction("apoc.json.path")
@Description("apoc.json.path('{json}','json-path')")
public Object path(@Name("json") String json, @Name(value = "path",defaultValue = "$") String path) {
return JsonUtil.parse(json,path,Object.class);
@Description("apoc.json.path('{json}' [,'json-path' , 'path-options'])")
public Object path(@Name("json") String json, @Name(value = "path",defaultValue = "$") String path, @Name(value = "pathOptions", defaultValue = "null") List<String> pathOptions) {
return JsonUtil.parse(json, path, Object.class, pathOptions);
}
@UserFunction("apoc.convert.toJson")
@Description("apoc.convert.toJson([1,2,3]) or toJson({a:42,b:\"foo\",c:[1,2,3]}) or toJson(NODE/REL/PATH)")
Expand All @@ -107,29 +107,29 @@ public void setJsonProperty(@Name("node") Node node, @Name("key") String key, @N
}

@UserFunction// ("apoc.json.getJsonProperty")
@Description("apoc.convert.getJsonProperty(node,key[,'json-path']) - converts serialized JSON in property back to original object")
public Object getJsonProperty(@Name("node") Node node, @Name("key") String key,@Name(value = "path",defaultValue = "") String path) {
@Description("apoc.convert.getJsonProperty(node,key[,'json-path', 'path-options']) - converts serialized JSON in property back to original object")
public Object getJsonProperty(@Name("node") Node node, @Name("key") String key,@Name(value = "path",defaultValue = "") String path, @Name(value = "pathOptions", defaultValue = "null") List<String> pathOptions) {
String value = (String) node.getProperty(key, null);
return JsonUtil.parse(value, path, Object.class);
return JsonUtil.parse(value, path, Object.class, pathOptions);
}

@UserFunction// ("apoc.json.getJsonPropertyMap")
@Description("apoc.convert.getJsonPropertyMap(node,key[,'json-path']) - converts serialized JSON in property back to map")
public Map<String,Object> getJsonPropertyMap(@Name("node") Node node, @Name("key") String key,@Name(value = "path",defaultValue = "") String path) {
@Description("apoc.convert.getJsonPropertyMap(node,key[,'json-path', 'path-options']) - converts serialized JSON in property back to map")
public Map<String,Object> getJsonPropertyMap(@Name("node") Node node, @Name("key") String key,@Name(value = "path",defaultValue = "") String path, @Name(value = "pathOptions", defaultValue = "null") List<String> pathOptions) {
String value = (String) node.getProperty(key, null);
return JsonUtil.parse(value, path, Map.class);
return JsonUtil.parse(value, path, Map.class, pathOptions);
}

@UserFunction
@Description("apoc.convert.fromJsonMap('{\"a\":42,\"b\":\"foo\",\"c\":[1,2,3]}'[,'json-path'])")
public Map<String,Object> fromJsonMap(@Name("map") String value,@Name(value = "path",defaultValue = "") String path) {
return JsonUtil.parse(value, path, Map.class);
@Description("apoc.convert.fromJsonMap('{\"a\":42,\"b\":\"foo\",\"c\":[1,2,3]}'[,'json-path', 'path-options'])")
public Map<String,Object> fromJsonMap(@Name("map") String value,@Name(value = "path",defaultValue = "") String path, @Name(value = "pathOptions", defaultValue = "null") List<String> pathOptions) {
return JsonUtil.parse(value, path, Map.class, pathOptions);
}

@UserFunction
@Description("apoc.convert.fromJsonList('[1,2,3]'[,'json-path'])")
public List<Object> fromJsonList(@Name("list") String value, @Name(value = "path",defaultValue = "") String path) {
return JsonUtil.parse(value, path, List.class);
@Description("apoc.convert.fromJsonList('[1,2,3]'[,'json-path', 'path-options'])")
public List<Object> fromJsonList(@Name("list") String value, @Name(value = "path",defaultValue = "") String path, @Name(value = "pathOptions", defaultValue = "null") List<String> pathOptions) {
return JsonUtil.parse(value, path, List.class, pathOptions);
}

@Procedure("apoc.convert.toTree")
Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/apoc/create/Create.java
Expand Up @@ -220,6 +220,30 @@ public Stream<VirtualPathResult> virtualPath(@Name("labelsN") List<String> label
return Stream.of(new VirtualPathResult(from, rel, to));
}

@Procedure
@Description("apoc.create.clonePathToVirtual")
public Stream<PathResult> clonePathToVirtual(@Name("path") Path path) {
return Stream.of(createVirtualPath(path));
}

@Procedure
@Description("apoc.create.clonePathsToVirtual")
public Stream<PathResult> clonePathsToVirtual(@Name("paths") List<Path> paths) {
return paths.stream().map(this::createVirtualPath);
}

private PathResult createVirtualPath(Path path) {
final Iterable<Relationship> relationships = path.relationships();
final Node first = path.startNode();
VirtualPath virtualPath = new VirtualPath(new VirtualNode(first, Iterables.asList(first.getPropertyKeys())));
for (Relationship rel : relationships) {
VirtualNode start = VirtualNode.from(rel.getStartNode());
VirtualNode end = VirtualNode.from(rel.getEndNode());
virtualPath.addRel(VirtualRelationship.from(start, end, rel));
}
return new PathResult(virtualPath);
}

private <T extends Entity> T setProperties(T pc, Map<String, Object> p) {
if (p == null) return pc;
for (Map.Entry<String, Object> entry : p.entrySet()) {
Expand Down

0 comments on commit 5775c43

Please sign in to comment.