jihot2000 commented on issue #220:
URL: https://github.com/apache/incubator-age/issues/220#issuecomment-1135396842

   I split the sql file into two files.
   
   First, the ```use_loop.sql```
   
   ```
   CREATE SCHEMA test_vle;
   
   SET search_path = test_vle, ag_catalog, "$user";
   
   SELECT create_graph('mygraph');
   SELECT create_vlabel('mygraph', 'head');
   SELECT create_vlabel('mygraph', 'tail');
   SELECT create_vlabel('mygraph', 'node');
   SELECT create_elabel('mygraph', 'next');
   
   CREATE OR REPLACE FUNCTION create_list(list_name text)
   RETURNS void
   LANGUAGE 'plpgsql'
   AS $$
   DECLARE
       ag_param agtype;
   BEGIN
       ag_param = FORMAT('{"list_name": "%s"}', $1)::agtype;
       PERFORM * FROM cypher('mygraph', $CYPHER$
           MERGE (:head {name: $list_name})-[:next]->(:tail {name: $list_name})
       $CYPHER$, ag_param) AS (a agtype);
   END $$;
   
   CREATE OR REPLACE FUNCTION prepend_node(list_name text, node_content text)
   RETURNS void
   LANGUAGE 'plpgsql'
   AS $$
   DECLARE
       ag_param agtype;
   BEGIN
       ag_param = FORMAT('{"list_name": "%s", "node_content": "%s"}', $1, 
$2)::agtype;
       PERFORM * FROM cypher('mygraph', $CYPHER$
           MATCH (h:head {name: $list_name})-[e:next]->(v)
           DELETE e
           CREATE (h)-[:next]->(:node {content: $node_content})-[:next]->(v)
       $CYPHER$, ag_param) AS (a agtype);
   END $$;
   
   CREATE OR REPLACE FUNCTION show_list_use_loop(list_name text)
   RETURNS TABLE(node agtype)
   LANGUAGE 'plpgsql'
   AS $$
   DECLARE
       node_id bigint;
       ag_param agtype;
   BEGIN
       ag_param = FORMAT('{"list_name": "%s"}', $1)::agtype;
       SELECT g.id INTO node_id FROM cypher('mygraph', $CYPHER$
           MATCH (h:head {name: $list_name})
           RETURN id(h)
       $CYPHER$, ag_param) AS g(id bigint);
   
       IF node_id IS NULL THEN
           RETURN;
       END IF;
   
       LOOP
           ag_param = FORMAT('{"node_id": %s}', node_id)::agtype;
           SELECT g.id, g.node INTO node_id, node FROM cypher('mygraph', 
$CYPHER$
               MATCH (p)-[e:next]->(v:node)
               WHERE id(p) = $node_id
               RETURN id(v), v
           $CYPHER$, ag_param) AS g(id bigint, node agtype);
           EXIT WHEN node_id IS NULL;
           RETURN NEXT;
       END LOOP;
   END $$;
   
   -- create a list
   SELECT create_list('list01');
   
   -- prepend a node 'a'
   SELECT prepend_node('list01', 'a');
   SELECT * FROM show_list_use_loop('list01');
   
   -- prepend a node 'b'
   SELECT prepend_node('list01', 'b');
   SELECT * FROM show_list_use_loop('list01');
   
   SELECT drop_graph('mygraph', true);
   ```
   
   Its output is right:
   
   ```
   CREATE SCHEMA
   SET
   psql:06.sql:5: NOTICE:  graph "mygraph" has been created
    create_graph 
   --------------
    
   (1 row)
   
   psql:06.sql:6: NOTICE:  VLabel "head" has been created
    create_vlabel 
   ---------------
    
   (1 row)
   
   psql:06.sql:7: NOTICE:  VLabel "tail" has been created
    create_vlabel 
   ---------------
    
   (1 row)
   
   psql:06.sql:8: NOTICE:  VLabel "node" has been created
    create_vlabel 
   ---------------
    
   (1 row)
   
   psql:06.sql:9: NOTICE:  ELabel "next" has been created
    create_elabel 
   ---------------
    
   (1 row)
   
   CREATE FUNCTION
   CREATE FUNCTION
   CREATE FUNCTION
    create_list 
   -------------
    
   (1 row)
   
    prepend_node 
   --------------
    
   (1 row)
   
                                          node                                  
      
   
-----------------------------------------------------------------------------------
    {"id": 1407374883553281, "label": "node", "properties": {"content": 
"a"}}::vertex
   (1 row)
   
    prepend_node 
   --------------
    
   (1 row)
   
                                          node                                  
      
   
-----------------------------------------------------------------------------------
    {"id": 1407374883553282, "label": "node", "properties": {"content": 
"b"}}::vertex
    {"id": 1407374883553281, "label": "node", "properties": {"content": 
"a"}}::vertex
   (2 rows)
   
   psql:06.sql:80: NOTICE:  drop cascades to 6 other objects
   DETAIL:  drop cascades to table mygraph._ag_label_vertex
   drop cascades to table mygraph._ag_label_edge
   drop cascades to table mygraph.head
   drop cascades to table mygraph.tail
   drop cascades to table mygraph.node
   drop cascades to table mygraph.next
   psql:06.sql:80: NOTICE:  graph "mygraph" has been dropped
    drop_graph 
   ------------
    
   (1 row)
   
   psql:06.sql:82: NOTICE:  drop cascades to 3 other objects
   DETAIL:  drop cascades to function create_list(text)
   drop cascades to function prepend_node(text,text)
   drop cascades to function show_list_use_loop(text)
   DROP SCHEMA
   ```
   
   Second, the 'use_vle.sql':
   
   ```
   CREATE SCHEMA test_vle;
   
   SET search_path = test_vle, ag_catalog, "$user";
   
   SELECT create_graph('mygraph');
   SELECT create_vlabel('mygraph', 'head');
   SELECT create_vlabel('mygraph', 'tail');
   SELECT create_vlabel('mygraph', 'node');
   SELECT create_elabel('mygraph', 'next');
   
   CREATE OR REPLACE FUNCTION create_list(list_name text)
   RETURNS void
   LANGUAGE 'plpgsql'
   AS $$
   DECLARE
       ag_param agtype;
   BEGIN
       ag_param = FORMAT('{"list_name": "%s"}', $1)::agtype;
       PERFORM * FROM cypher('mygraph', $CYPHER$
           MERGE (:head {name: $list_name})-[:next]->(:tail {name: $list_name})
       $CYPHER$, ag_param) AS (a agtype);
   END $$;
   
   CREATE OR REPLACE FUNCTION prepend_node(list_name text, node_content text)
   RETURNS void
   LANGUAGE 'plpgsql'
   AS $$
   DECLARE
       ag_param agtype;
   BEGIN
       ag_param = FORMAT('{"list_name": "%s", "node_content": "%s"}', $1, 
$2)::agtype;
       PERFORM * FROM cypher('mygraph', $CYPHER$
           MATCH (h:head {name: $list_name})-[e:next]->(v)
           DELETE e
           CREATE (h)-[:next]->(:node {content: $node_content})-[:next]->(v)
       $CYPHER$, ag_param) AS (a agtype);
   END $$;
   
   CREATE OR REPLACE FUNCTION show_list_use_vle(list_name text)
   RETURNS TABLE(node agtype)
   LANGUAGE 'plpgsql'
   AS $$
   DECLARE
       ag_param agtype;
   BEGIN
       ag_param = FORMAT('{"list_name": "%s"}', $1)::agtype;
       RETURN QUERY
       SELECT * FROM cypher('mygraph', $CYPHER$
           MATCH (h:head {name: $list_name})-[e:next*]->(v:node)
           RETURN v
       $CYPHER$, ag_param) AS (node agtype);
   END $$;
   
   -- create a list
   SELECT create_list('list01');
   
   -- prepend a node 'a'
   SELECT prepend_node('list01', 'a');
   SELECT * FROM show_list_use_vle('list01');
   
   -- prepend a node 'b'
   SELECT prepend_node('list01', 'b');
   SELECT * FROM show_list_use_vle('list01'); 
   
   SELECT drop_graph('mygraph', true);
   
   DROP SCHEMA test_vle CASCADE;
   ```
   
   Its output is wrong:
   
   ```
   CREATE SCHEMA
   SET
   psql:07.sql:5: NOTICE:  graph "mygraph" has been created
    create_graph 
   --------------
    
   (1 row)
   
   psql:07.sql:6: NOTICE:  VLabel "head" has been created
    create_vlabel 
   ---------------
    
   (1 row)
   
   psql:07.sql:7: NOTICE:  VLabel "tail" has been created
    create_vlabel 
   ---------------
    
   (1 row)
   
   psql:07.sql:8: NOTICE:  VLabel "node" has been created
    create_vlabel 
   ---------------
    
   (1 row)
   
   psql:07.sql:9: NOTICE:  ELabel "next" has been created
    create_elabel 
   ---------------
    
   (1 row)
   
   CREATE FUNCTION
   CREATE FUNCTION
   CREATE FUNCTION
    create_list 
   -------------
    
   (1 row)
   
    prepend_node 
   --------------
    
   (1 row)
   
                                          node                                  
      
   
-----------------------------------------------------------------------------------
    {"id": 1407374883553281, "label": "node", "properties": {"content": 
"a"}}::vertex
   (1 row)
   
    prepend_node 
   --------------
    
   (1 row)
   
                                          node                                  
      
   
-----------------------------------------------------------------------------------
    {"id": 1407374883553281, "label": "node", "properties": {"content": 
"a"}}::vertex
   (1 row)
   
   psql:07.sql:65: NOTICE:  drop cascades to 6 other objects
   DETAIL:  drop cascades to table mygraph._ag_label_vertex
   drop cascades to table mygraph._ag_label_edge
   drop cascades to table mygraph.head
   drop cascades to table mygraph.tail
   drop cascades to table mygraph.node
   drop cascades to table mygraph.next
   psql:07.sql:65: NOTICE:  graph "mygraph" has been dropped
    drop_graph 
   ------------
    
   (1 row)
   
   psql:07.sql:67: NOTICE:  drop cascades to 3 other objects
   DETAIL:  drop cascades to function create_list(text)
   drop cascades to function prepend_node(text,text)
   drop cascades to function show_list_use_vle(text)
   DROP SCHEMA
   ```
   
   The question is the output after prepend node 'b' of ```use_loop.sql``` is 
right. Both node 'b' and node 'a' are printed. But the output after prepend 
node 'b' of ```use_vle.sql``` is wrong. It only printed node 'a'.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to