Repository navigation
Description
Problem
GraphEngine.parseDirection coerces any unrecognised direction string to BOTH:
public static Vertex.DIRECTION parseDirection(final String dir) {
if (dir == null)
return Vertex.DIRECTION.BOTH;
return switch (dir.toUpperCase()) {
case "OUT" -> Vertex.DIRECTION.OUT;
case "IN" -> Vertex.DIRECTION.IN;
default -> Vertex.DIRECTION.BOTH; // <-- 'INCOMING', 'outgoing', 'nope', ''
};
}So CALL algo.bfs(startNode, 3, 'INCOMING') traverses both directions and returns a plausible-looking result. The caller asked one question and got the answer to a different one, with nothing to indicate the substitution. A typo in a direction is silently a semantic change, not an error.
This affects roughly 23 algo.*/path procedures that route their direction argument through the shared helper, including algo.bfs, algo.dfs, algo.degree, algo.closeness, algo.harmonic, algo.eccentricity, algo.eigenvector, algo.jaccard, algo.commonNeighbors, algo.adamicAdar, algo.resourceAllocation, algo.preferentialAttachment, algo.totalNeighbors, algo.knn, algo.randomWalk, algo.node2vec, algo.fastrp, algo.hashgnn, algo.graphsage, algo.maxkcut, algo.labelPropagation, algo.dijkstra, algo.dijkstraSingleSource. AlgoLabelPropagation also carries its own local copy of the same pattern.
Why now
This is longstanding and was low-impact for as long as the direction values were near-interchangeable in practice. #6956 changed that for PageRank: direction: 'IN' had been returning OUT's scores on one of the two execution paths, and once fixed the three values demonstrably produce different answers. The same PR added rejection locally in AlgoPageRank rather than tightening the shared helper, precisely because the shared change reaches ~23 other procedures and deserved its own issue. That is this issue.
The wider lesson from #6956 is the relevant one: a direction that silently degrades to something plausible is exactly how a direction bug survives unnoticed for a long time.
Proposed fix
Reject unrecognised values by name instead of coercing:
throw new IllegalArgumentException("unknown direction '" + dir + "', expected one of OUT, IN or BOTH");matching the IllegalArgumentException style AbstractAlgoProcedure already uses for its other config knobs, and the "reject, do not silently clamp — there is no correct value to fall back to" precedent set for the numeric bounds in #6065.
Things to settle before implementing
- Keep
nullmeaningBOTH. Every current caller relies on an absent argument defaulting through this helper, so null must stay a legal "use the default". Only a present but unrecognised value should be rejected. Note the default here isBOTH, whereasAlgoPageRank's own default isOUT— do not unify those two without checking each procedure, they are separately meaningful. parseDirectionis public API onGraphEngine. Check for callers outside the procedure package before changing its contract.AlgoLabelPropagation's local copy needs the same treatment, or should be routed through the shared helper.- It is a behaviour change. Anything today passing a malformed direction and quietly getting
BOTHstarts getting an error. That is the point, but it belongs in the release notes. - Test coverage.
AlgoPageRankTest.pageRankRejectsAnUnrecognisedDirection(added in fix(pagerank): honor IN direction in OLTP and CSR paths #6956) is a usable template — it pins both the rejected shapes ('INCOMING','OUTGOING', trailing whitespace, empty string, a non-string) and that all three valid values in either case still work.
Related
- fix(pagerank): honor IN direction in OLTP and CSR paths #6956 — the PageRank direction fix that surfaced this, and which contains the local precedent
- Document the algo.pagerank direction property (OUT/IN/BOTH), and correct its default arcadedb-docs#446 — documents the
directionproperty, and notes that the shared docs currently describeBOTHas "the default for most algorithms" while PageRank defaults toOUT
Activity
review: bounds-check the overlay-aware Dijkstra fallback, close the #…
Merge pull request #7001 from ArcadeData/fix/6976-6791-direction-and-…
lvca commentedon Sep 2, 2026
Fixed in #7001.
algo.*procedures and path functions used to accept any direction string and silently fall back toBOTHwhen they didn't recognise it. So a typo likedirection: 'INCOMING'instead of'IN'gave you a plausible-looking answer to a question you never asked, with no error to hint at it.They now reject anything that isn't
OUT,INorBOTH(case doesn't matter):Omitting the direction still works as before and uses each procedure's own default.
Two other places carried the same bug and are fixed too: the
bellmanFord()SQL function, andnode.degree()/node.relationship.exists()/node.relationship.types().Heads up: this is a behaviour change. If a query of yours passes a malformed direction today, it has been quietly running with
BOTHand will now fail instead. That is the point of the fix, but it's worth checking your saved queries.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
docs: an unrecognised algo direction is now rejected instead of falli…
fix(ArcadeData#6976,ArcadeData#6791): reject unknown algo direction s…
test: consolidate the Issue*Test classes of the other openCypher sub-…
test: consolidate the Issue*Test classes of the other openCypher sub-…