Skip to content

Commit

Permalink
Update apoc help so that it does not rely on extended at all (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j authored Nov 27, 2024
1 parent ed7e897 commit 18e352d
Show file tree
Hide file tree
Showing 4 changed files with 890 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/traceability-comments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- synchronize

jobs:
validate-pr:
traceability:
runs-on: ubuntu-latest
steps:
- uses: neo4j/github-action-traceability@v2
Expand Down
41 changes: 16 additions & 25 deletions core/src/main/java/apoc/help/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@

import static apoc.util.Util.map;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.api.QueryLanguage;
Expand All @@ -42,23 +36,6 @@ public class Help {
@Context
public Transaction tx;

private static final Set<String> extended = new HashSet<>();

public Help() {
try (InputStream stream = getClass().getClassLoader().getResourceAsStream("extended.txt")) {
if (stream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String name;
while ((name = reader.readLine()) != null) {
extended.add(name);
}
}
} catch (IOException e) {
// Failed to load extended file
throw new RuntimeException("Failed to load extended file with error: " + e.getMessage());
}
}

@NotThreadSafe
@Procedure("apoc.help")
@QueryLanguageScope(scope = {QueryLanguage.CYPHER_5})
Expand Down Expand Up @@ -103,7 +80,21 @@ private Stream<HelpResult> help(String name, Boolean version5) {
Stream<Map<String, Object>> functionsResults = tx.execute(functionsQuery, params).stream();

return Stream.of(proceduresResults, functionsResults)
.flatMap(results ->
results.map(row -> new HelpResult(row, !extended.contains((String) row.get("name")))));
.flatMap(results -> results.map(row -> new HelpResult(
row,
existsInCore(
(String) row.get("name"),
version5,
row.get("type").equals("function")))));
}

private boolean existsInCore(String name, boolean version5, boolean function) {
if (version5) {
if (function) return HelpUtil.coreFunctionsV5.contains(name);
else return HelpUtil.coreProceduresV5.contains(name);
} else {
if (function) return HelpUtil.coreFunctionsV25.contains(name);
else return HelpUtil.coreProceduresV25.contains(name);
}
}
}
Loading

0 comments on commit 18e352d

Please sign in to comment.