Skip to content

Undirected edges in edge body raises an error. #5

Description

@glennga

The following query, which queries a graph whose edge body contains an undirected edge from another graph, raises an error.

WITH
    GRAPH Complex14Graph AS
        VERTEX (:Person)
            PRIMARY KEY (id)
            AS SNB.Native.Persons,
        EDGE (:Person)-[:KNOWS]->(:Person)
            SOURCE KEY      (startId)
            DESTINATION KEY (endId)
            AS (
                FROM
                    GRAPH SNB.Native.SNBGraph
                        (personA:Person)-[:KNOWS]->(personB:Person),
                        (personA)<-[:HAS_CREATOR]-(m1:Message),
                        (m1)-[:REPLY_OF]-(m2:Message),
                        (m2)-[:HAS_CREATOR]->(personB)
                GROUP BY
                    personA.id,
                    personB.id
                    GROUP AS g
                LET
                    w1 = ( FROM g WHERE g.m1.isPost OR g.m2.isPost SELECT VALUE COUNT(*) )[0],
                    w2 = ( FROM g WHERE NOT g.m1.isPost OR NOT g.m2.isPost SELECT VALUE COUNT(*) )[0] * 0.5,
                SELECT
                    personA.id AS startId,
                    personB.id AS endId,
                    w1 + w2    AS weight
            )
FROM
    GRAPH Complex14Graph
        (person1:Person)-[k:KNOWS+]->(person2:Person)
WHERE
    person1.id = $person1Id AND
    person2.id = $person2Id
GROUP BY
    person1.id,
    person2.id
    GROUP AS g
LET
    cheapestPath = (
        FROM
            g
        SELECT
            ( FROM VERTICES(g.k) kv SELECT VALUE kv.id )          AS ids,
            ( FROM EDGES(g.k) ke SELECT VALUE SUM(ke.weight) )[0] AS cost
        ORDER BY
            ABS(cost) ASC
        LIMIT
            1
    )[0]
SELECT
    cheapestPath.ids  AS personIdsInPath,
    cheapestPath.cost AS pathWeight
ORDER BY
    pathWeight DESC;

The workaround here is to define the edge body in pure SQL++, and to either perform a disjunctive JOIN (to capture both directions, given below) or a UNION ALL (to avoid a disjunction, leading to an HHJ):

WITH
    GRAPH Complex14Graph AS
        VERTEX (:Person)
            PRIMARY KEY (id)
            AS SNB.Native.Persons,
        EDGE (:Person)-[:KNOWS]->(:Person)
            SOURCE KEY      (startId)
            DESTINATION KEY (endId)
            AS (
                FROM
                    SNB.Native.Messages m1,
                    SNB.Native.Messages m2,
                    SNB.Native.Knows k
                WHERE
                    k.startId = m1.creatorId AND
                    k.endId = m2.creatorId AND
                    ( m1.replyOfMessageId = m2.id OR
                      m2.replyOfMessageId = m1.id )
                GROUP BY
                    m1.creatorId AS startId,
                    m2.creatorId AS endId
                    GROUP AS g
                LET
                    w1 = ( FROM g WHERE g.m1.isPost OR g.m2.isPost SELECT VALUE COUNT(*) )[0],
                    w2 = ( FROM g WHERE NOT g.m1.isPost OR NOT g.m2.isPost SELECT VALUE COUNT(*) )[0] * 0.5
                SELECT
                    startId AS startId,
                    endId   AS endId,
                    w1 + w2 AS weight
            )
FROM
    GRAPH Complex14Graph
        (person1:Person)-[k:KNOWS+]->(person2:Person)
WHERE
    person1.id = $person1Id AND
    person2.id = $person2Id
GROUP BY
    person1.id,
    person2.id
    GROUP AS g
LET
    cheapestPath = (
        FROM
            g
        SELECT
            ( FROM VERTICES(g.k) kv SELECT VALUE kv.id )          AS ids,
            ( FROM EDGES(g.k) ke SELECT VALUE SUM(ke.weight) )[0] AS cost
        ORDER BY
            ABS(cost) ASC
        LIMIT
            1
    )[0]
SELECT
    cheapestPath.ids  AS personIdsInPath,
    cheapestPath.cost AS pathWeight
ORDER BY
    pathWeight DESC;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions