apache / age

Graph database optimized for fast analysis and real-time data processing. It is provided as an extension to PostgreSQL.
https://age.apache.org
Apache License 2.0
3.11k stars 410 forks source link

Call subquery #1690

Open rafsun42 opened 7 months ago

rafsun42 commented 7 months ago

Should we add call subquery to AGE? It will allow Neo4j's GraphQL library to be compatible with AGE.

Data Setup

SELECT * FROM cypher('xyz', $$
CREATE (:Actor{name:'Tom Hanks'})-[:ACTED_IN]->(:Movie{title:'Forrest Gump'}) 
$$) as (a agtype);

Two uses of call subquery

1)

SELECT * FROM ag_catalog.cypher('xyz', $$
    MATCH (this:Movie)
    CALL {
        WITH this
        MATCH (this)<-[this0:ACTED_IN]-(this1:Actor)
        WITH ag_catalog.agtype_build_map('name', this1.name) AS this1
        RETURN collect(this1) AS var2
    }
    RETURN ag_catalog.agtype_build_map('title', this.title, 'actors', var2) AS this
$$) as ("?" agtype);

2)

SELECT * FROM ag_catalog.cypher('xyz', $$
    UNWIND $create_param0 AS create_var0
    CALL {
        WITH create_var0
        CREATE (create_this1:Movie)
        SET
            create_this1.title = create_var0.title
        WITH create_this1, create_var0
        CALL {
            WITH create_this1, create_var0
            UNWIND create_var0.actors.create AS create_var2
            WITH create_var2.node AS create_var3, create_var2.edge AS create_var4, create_this1
            CREATE (create_this5:Actor)
            SET
                create_this5.name = create_var3.name
            MERGE (create_this1)<-[create_this6:ACTED_IN]-(create_this5)

            RETURN collect(NULL) AS create_var7
        }

        RETURN create_this1
    }
    CALL {
        WITH create_this1
        MATCH (create_this1)<-[create_this8:ACTED_IN]-(create_this9:Actor)
        WITH ag_catalog.agtype_build_map('name', create_this9.name) AS create_this9 
        RETURN collect(create_this9) AS create_var10
    }
    RETURN collect(ag_catalog.agtype_build_map('title', create_this1.title, 'actors', create_var10)) AS data
$$,
'[ { title: 'Forrest Gump', actors: { create: [{ node: { name: "Tom Hanks" } }] } } ]' -- parameter
) as ("?" agtype);

Expected output For both queries:

[
    {
      "title": "Forrest Gump",
      "actors": [
        {
          "name": "Tom Hanks"
        }
      ]
    }
]
github-actions[bot] commented 6 months ago

This issue is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.