Skip to content

Commit 536833c

Browse files
authored
Merge pull request #281 from lqst/test_speedup
Let's make unit tests run faster (4.4)
2 parents ff78c91 + 720623a commit 536833c

31 files changed

+983
-1446
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# neosemantics (n10s)
22
![n10s Logo](https://guides.neo4j.com/rdf/n10s.png) neosemantics is a plugin that enables the **use of RDF in Neo4j**. [RDF is a W3C standard model](https://www.w3.org/RDF/) for data interchange. Some key features of n10s are:
33

4+
45
* **Store RDF data in Neo4j** in a
56
lossless manner (imported RDF can subsequently be exported without losing a single triple in the process).
67
* On-demand **export property graph data** from Neo4j *as RDF*.

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.neo4j</groupId>
77
<artifactId>neosemantics</artifactId>
8-
<version>4.4.0.2</version>
8+
<version>5.1.0.0</version>
99
<packaging>jar</packaging>
1010
<name>neosemantics (n10s)</name>
1111
<description>n10s is a plugin that enables the use of RDF in Neo4j</description>
@@ -34,8 +34,8 @@
3434
</developers>
3535

3636
<properties>
37-
<neo4j.version>4.4.11</neo4j.version>
38-
<sesame.version>3.7.7</sesame.version>
37+
<neo4j.version>5.1.0</neo4j.version>
38+
<sesame.version>4.2.0</sesame.version>
3939
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4040
</properties>
4141

src/main/java/n10s/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private static String buildCypher(String uri, String graphUri, Map<String, Objec
126126
cypher.append("AND n.graphUri = $graphUri ");
127127
params.put("graphUri", graphUri);
128128
} else {
129-
cypher.append("AND NOT EXISTS(n.graphUri) ");
129+
cypher.append("AND n.graphUri is null ");
130130
}
131131
cypher.append("RETURN n");
132132
return cypher.toString();

src/main/java/n10s/endpoint/RDFEndpoint.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.neo4j.graphdb.GraphDatabaseService;
3838
import org.neo4j.graphdb.NotFoundException;
3939
import org.neo4j.graphdb.Transaction;
40-
import org.neo4j.logging.Log;
4140

4241
/**
4342
* Created by jbarrasa on 08/09/2016.
@@ -70,10 +69,6 @@ public class RDFEndpoint {
7069
RDFFormat.TURTLE, RDFFormat.NTRIPLES, RDFFormat.TRIG, RDFFormat.NQUADS, RDFFormat.TURTLESTAR,
7170
RDFFormat.TRIGSTAR};
7271

73-
@Context
74-
public Log log;
75-
76-
7772
@GET
7873
@Path("/ping")
7974
public Response ping() throws IOException {
@@ -321,27 +316,21 @@ private void handleSerialisationError(OutputStream outputStream, Exception e,
321316
private RDFFormat getFormat(String mimetype, String formatParam) {
322317
// format request param overrides the one defined in the accept header param
323318
if (formatParam != null) {
324-
log.debug("serialization from param in request: " + formatParam);
325319
for (RDFFormat parser : availableParsers) {
326320
if (parser.getName().contains(formatParam)) {
327-
log.debug("parser to be used: " + parser.getDefaultMIMEType());
328321
return parser;
329322
}
330323
}
331324
} else {
332325
if (mimetype != null) {
333-
log.debug("serialization from media type in request: " + mimetype);
334326
for (RDFFormat parser : availableParsers) {
335327
if (parser.getMIMETypes().contains(mimetype)) {
336-
log.debug("parser to be used: " + parser.getDefaultMIMEType());
337328
return parser;
338329
}
339330
}
340331
}
341332
}
342333

343-
log.debug("Unrecognized or undefined serialization. Defaulting to Turtle serialization");
344-
345334
return RDFFormat.TURTLE;
346335

347336
}

src/main/java/n10s/mapping/MappingUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Stream<MappingDesc> add(@Name("elementUri") String rdfVocElement,
6565
+ "DETACH DELETE oldmd";
6666

6767
String cleanOrphansIfAny = "MATCH (oldns:`_MapNs`)\n"
68-
+ " WHERE size((oldns)<-[:_IN]-())=0\n"
68+
+ " WHERE not (oldns)<-[:_IN]-() \n"
6969
+ " DELETE oldns";
7070

7171
String createNewMapping = "MERGE (newmns:`_MapNs` { _ns: $namespace, _prefix: $prefix }) \n"
@@ -105,7 +105,7 @@ public Stream<StringOutput> dropAll(@Name("namespace") String schemaUri) {
105105
public Stream<StringOutput> drop(@Name("graphElementName") String gElem)
106106
throws MappingDefinitionException {
107107
String cypher = "MATCH (mapns)<-[:_IN]-(elem:_MapDef { _key : $local }) DETACH DELETE elem "
108-
+ "RETURN count(elem) AS deletecount, size((mapns)<-[:_IN]-()) AS remaining, mapns ";
108+
+ "RETURN count(elem) AS deletecount, size([(mapns)<-[r:_IN]-() | r ]) AS remaining, mapns ";
109109
Map<String, Object> params = new HashMap<>();
110110
params.put("local", gElem);
111111
Result queryResult = tx.execute(cypher, params);

src/main/java/n10s/quadrdf/RDFQuadToLPGStatementProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ String buildCypher(String uri, String graphUri, Map<String, Object> params) {
106106
cypher.append("AND n.graphUri = $graphUri ");
107107
params.put("graphUri", graphUri);
108108
} else {
109-
cypher.append("AND NOT EXISTS(n.graphUri) ");
109+
cypher.append("AND n.graphUri is null ");
110110
}
111111
cypher.append("RETURN n");
112112
return cypher.toString();

src/main/java/n10s/rdf/export/LPGRDFToRDFProcesssor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ public Stream<Statement> streamNodeByUri(String uri, String graphId, boolean exc
161161
params.put("uri", uri);
162162
if (graphId == null || graphId.equals("")) {
163163
queryWithContext = "MATCH (x:Resource {uri:$uri}) " +
164-
"WHERE NOT EXISTS(x.graphUri)\n" +
164+
"WHERE x.graphUri is null \n" +
165165
"OPTIONAL MATCH (x)-[r]-(val:Resource) " +
166-
"WHERE exists(val.uri)\n" +
167-
"AND NOT EXISTS(val.graphUri)\n" +
166+
"WHERE val.uri is not null \n" +
167+
"AND val.graphUri is null \n" +
168168
"RETURN x, r, val.uri AS value";
169169

170170
queryNoContext = "MATCH (x:Resource {uri:$uri}) " +
171-
"WHERE NOT EXISTS(x.graphUri)\n" +
171+
"WHERE x.graphUri is null \n" +
172172
"RETURN x, null AS r, null AS value";
173173
} else {
174174
queryWithContext = "MATCH (x:Resource {uri:$uri, graphUri:$graphUri}) " +
175175
"OPTIONAL MATCH (x)-[r]-(val:Resource {graphUri:$graphUri}) " +
176-
"WHERE exists(val.uri)\n" +
176+
"WHERE val.uri is not null \n" +
177177
"RETURN x, r, val.uri AS value";
178178

179179
queryNoContext = "MATCH (x:Resource {uri:$uri, graphUri:$graphUri}) " +
@@ -441,7 +441,7 @@ public Stream<Statement> streamTriplesFromTriplePattern(TriplePattern tp)
441441
result = tx.execute("MATCH (r:Resource) WHERE size(labels(r))>1 RETURN r");
442442
} else {
443443
result = tx.execute(String
444-
.format("MATCH (r:Resource) WHERE exists(r.`%s`) RETURN r\n"
444+
.format("MATCH (r:Resource) WHERE r.`%s` is not null RETURN r\n"
445445
+ "UNION \n"
446446
+ "MATCH (:Resource)-[r:`%s`]->() RETURN r",
447447
predicate, predicate));

src/main/java/n10s/rdf/export/LPGToRDFProcesssor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public Stream<Statement> streamTriplesFromTriplePattern(TriplePattern tp)
400400
//CHECK IF predicate is <NONE>, in which case there's no point in running the query
401401
if (!predicate.equals(NOT_MATCHING_NS)) {
402402
result = tx.execute(String
403-
.format("MATCH (s) WHERE exists(s.`%s`) RETURN s, s.`%s` as o\n"
403+
.format("MATCH (s) WHERE s.`%s` is not null RETURN s, s.`%s` as o\n"
404404
+ "UNION \n"
405405
+ "MATCH (s)-[:`%s`]->(o) RETURN s, o",
406406
predicate, predicate, predicate));

src/main/java/n10s/result/VirtualNode.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
import java.util.concurrent.atomic.AtomicLong;
1212
import java.util.stream.Collectors;
1313
import n10s.Util;
14-
import org.neo4j.graphdb.Direction;
15-
import org.neo4j.graphdb.Label;
16-
import org.neo4j.graphdb.Node;
17-
import org.neo4j.graphdb.Relationship;
18-
import org.neo4j.graphdb.RelationshipType;
14+
import org.neo4j.graphdb.*;
1915
import org.neo4j.internal.helpers.collection.FilteringIterable;
2016
import org.neo4j.internal.helpers.collection.Iterables;
2117

@@ -61,6 +57,12 @@ public long getId() {
6157
return id;
6258
}
6359

60+
@Override
61+
public String getElementId()
62+
{
63+
return String.valueOf( id );
64+
}
65+
6466
@Override
6567
public void delete() {
6668
for (Relationship rel : rels) {
@@ -69,8 +71,8 @@ public void delete() {
6971
}
7072

7173
@Override
72-
public Iterable<Relationship> getRelationships() {
73-
return rels;
74+
public ResourceIterable<Relationship> getRelationships() {
75+
return Iterables.asResourceIterable(rels);
7476
}
7577

7678
@Override
@@ -79,8 +81,8 @@ public boolean hasRelationship() {
7981
}
8082

8183
@Override
82-
public Iterable<Relationship> getRelationships(RelationshipType... relationshipTypes) {
83-
return new FilteringIterable<>(rels, (r) -> isType(r, relationshipTypes));
84+
public ResourceIterable<Relationship> getRelationships(RelationshipType... relationshipTypes) {
85+
return Iterables.asResourceIterable(new FilteringIterable<>(rels, (r) -> isType(r, relationshipTypes)));
8486
}
8587

8688
private boolean isType(Relationship r, RelationshipType... relationshipTypes) {
@@ -93,10 +95,10 @@ private boolean isType(Relationship r, RelationshipType... relationshipTypes) {
9395
}
9496

9597
@Override
96-
public Iterable<Relationship> getRelationships(Direction direction,
98+
public ResourceIterable<Relationship> getRelationships(Direction direction,
9799
RelationshipType... relationshipTypes) {
98-
return new FilteringIterable<>(rels,
99-
(r) -> isType(r, relationshipTypes) && isDirection(r, direction));
100+
return Iterables.asResourceIterable(new FilteringIterable<>(rels,
101+
(r) -> isType(r, relationshipTypes) && isDirection(r, direction)));
100102
}
101103

102104
private boolean isDirection(Relationship r, Direction direction) {
@@ -115,8 +117,8 @@ public boolean hasRelationship(Direction direction, RelationshipType... relation
115117
}
116118

117119
@Override
118-
public Iterable<Relationship> getRelationships(Direction direction) {
119-
return new FilteringIterable<>(rels, (r) -> isDirection(r, direction));
120+
public ResourceIterable<Relationship> getRelationships(Direction direction) {
121+
return Iterables.asResourceIterable(new FilteringIterable<>(rels, (r) -> isDirection(r, direction)));
120122
}
121123

122124
@Override

src/main/java/n10s/result/VirtualRelationship.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public long getId() {
5454
return id;
5555
}
5656

57+
@Override
58+
public String getElementId()
59+
{
60+
return String.valueOf( id );
61+
}
62+
5763
@Override
5864
public void delete() {
5965
if (getStartNode() instanceof VirtualNode) {

0 commit comments

Comments
 (0)