2

Since the current version of Neo4jClient does not support UNWIND, I am having troubles rewriting the following Cypher query :

MATCH (:A{UId:someByteArray})--(b1:B)-[:C]-(b2:B)
    MATCH p = (b1)-[:C*]->(b2)
    WITH b1.someString as s1, b2.someString as s2, p, 
        EXTRACT(c IN RELATIONSHIPS(p) | c.someValue) AS valuesAlias
    UNWIND(valuesAlias) AS va
    WITH s1, s2, length(NODES(p)) as pLength, MIN(va) AS minVA
WITH s1, s2, MAX(minVA) as maxMinVA, MIN(pLength) AS minPL
RETURN s1, s2, maxMinVA

The query above is a variation on Solve the Widest Path Problem in Cypher

TermoTux
  • 588
  • 4
  • 17

2 Answers2

1

For the record, UNWIND is now supported in Neo4jClient.

Stuporman
  • 773
  • 6
  • 26
0

Basically one needs to replace UNWIND/MIN with REDUCE/CASE statements as illustrated by the following query:

MATCH (:A{UId:someByteArray})--(b1:B)-[:C]-(b2:B)
    MATCH p = (b1)-[:C*]->(b2)
    WITH b1.someString as s1, b2.someString as s2, p, 
        EXTRACT(c IN RELATIONSHIPS(p) | c.someValue) AS valuesAlias
    WITH s1, s2, p, length(NODES(p)) as pLength, 
        REDUCE(curVA=9999999999, va in valuesAlias |
            CASE
                WHEN va < curVA THEN va
                ELSE curVA
            END
        ) AS minVA
WITH s1, s2, MAX(minVA) as maxMinVA, MIN(pLength) AS minPL
RETURN s1, s2, maxMinVA

Results produced are exactly the same, including the ordering, though I guess this is not guaranteed in general.

TermoTux
  • 588
  • 4
  • 17