GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — review: path.combine refuses what is not a path instead of returning … · ArcadeData/arcadedb@a34d973

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • engine/src
    • main/java/com/arcadedb/function/path
      • PathCombine.java
    • test/java/com/arcadedb/query/opencypher
      • Issue10017PathCombineTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎engine/src/main/java/com/arcadedb/function/path/PathCombine.java‎

Copy file name to clipboardExpand all lines: engine/src/main/java/com/arcadedb/function/path/PathCombine.java
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,33 @@ public Object execute(final Object[] args, final CommandContext context) {
8282
return asPathValue(arg);
8383
}
8484

85+
/**
86+
* The path {@code value} is: a real path when its elements are graph elements, the value itself when it is a path
87+
* of other elements (a node/relationship map, an alternating list). Anything else is not a path and is refused, so a
88+
* value that is not one never comes back out as a "combined path".
89+
*/
8590
private static Object asPathValue(final Object value) {
8691
final TraversalPath path = asTraversalPath(value);
87-
return path != null ? path : value;
92+
if (path != null)
93+
return path;
94+
if (value instanceof Map<?, ?> map && map.get("nodes") instanceof List<?>)
95+
return value;
96+
if (value instanceof List<?> list && list.size() % 2 == 1)
97+
return value;
98+
throw new CommandExecutionException("path.combine() expects paths, got " + describe(value));
8899
}
89100

90101
private static Object combine(final Object first, final Object second) {
91102
if (first == null)
92103
return second == null ? null : asPathValue(second);
93104
if (second == null)
94105
return asPathValue(first);
95-
final TraversalPath firstPath = asTraversalPath(first);
96-
final TraversalPath secondPath = asTraversalPath(second);
106+
final TraversalPath firstPath = asTraversalPath(asPathValue(first));
107+
final TraversalPath secondPath = asTraversalPath(asPathValue(second));
97108
if (firstPath != null && secondPath != null) {
98109
final Object end = firstPath.getEndVertex().getIdentity();
99110
final Object start = secondPath.getStartVertex().getIdentity();
100-
if (!end.equals(start))
111+
if (!Objects.equals(end, start))
101112
throw notConnected(end, start);
102113
return new TraversalPath(firstPath, secondPath);
103114
}
Collapse file

‎engine/src/test/java/com/arcadedb/query/opencypher/Issue10017PathCombineTest.java‎

Copy file name to clipboardExpand all lines: engine/src/test/java/com/arcadedb/query/opencypher/Issue10017PathCombineTest.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ void pathsThatDoNotConnectAreRefused() {
9595
.hasMessageContaining("do not connect");
9696
}
9797

98+
@Test
99+
void whatIsNotAPathIsRefused() {
100+
assertThatThrownBy(() -> single("MATCH p = (:N {id: 1})-[:R]->(:N {id: 2}) RETURN path.combine(p, 42) AS p"))
101+
.isInstanceOf(CommandExecutionException.class).hasMessageContaining("expects paths");
102+
assertThatThrownBy(() -> single("MATCH p = (:N {id: 1})-[:R]->(:N {id: 2}) RETURN path.combine([p, 'x']) AS p"))
103+
.isInstanceOf(CommandExecutionException.class).hasMessageContaining("expects paths");
104+
}
105+
98106
@Test
99107
void theListFormJoinsEveryPathInOrder() {
100108
assertThat(single("""

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.