This is an automated email from the ASF dual-hosted git repository.

jgemignani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-age.git


The following commit(s) were added to refs/heads/master by this push:
     new 95ca659  Allow global graph contexts to see currentCommandIds
95ca659 is described below

commit 95ca659fd037b265b385e5363acbfa01d00eb936
Author: John Gemignani <[email protected]>
AuthorDate: Thu May 19 09:51:45 2022 -0700

    Allow global graph contexts to see currentCommandIds
    
    Allow the global graph contexts to see the curcid - the snapshot
    copy of currentCommandId for that snapshot.
    
    This will allow the contexts to be refreshed, as needed, inside
    BEGIN/COMMIT blocks. This problem was brought up in issue #217
    
    Added regression tests.
---
 regress/expected/cypher_vle.out          | 75 ++++++++++++++++++++++++++++++++
 regress/sql/cypher_vle.sql               | 42 ++++++++++++++++++
 src/backend/utils/adt/age_global_graph.c |  5 ++-
 3 files changed, 121 insertions(+), 1 deletion(-)

diff --git a/regress/expected/cypher_vle.out b/regress/expected/cypher_vle.out
index 7fbef33..5ae8449 100644
--- a/regress/expected/cypher_vle.out
+++ b/regress/expected/cypher_vle.out
@@ -541,6 +541,81 @@ SELECT * FROM cypher('cypher_vle', $$MATCH 
p=()-[]->()-[*0..0]->() RETURN p $$)
  [{"id": 1407374883553283, "label": "middle", "properties": {}}::vertex, 
{"id": 2251799813685251, "label": "alternate_edge", "end_id": 1688849860263937, 
"start_id": 1407374883553283, "properties": {"name": "alternate edge", 
"number": 3, "packages": [2, 4, 6], "dangerous": {"type": "poisons", "level": 
"all"}}}::edge, {"id": 1688849860263937, "label": "end", "properties": 
{}}::vertex]::path
 (13 rows)
 
+--
+-- Test VLE inside of a BEGIN/COMMIT block
+--
+BEGIN;
+SELECT create_graph('mygraph');
+NOTICE:  graph "mygraph" has been created
+ create_graph 
+--------------
+ 
+(1 row)
+
+/* should create 1 path with 1 edge */
+SELECT * FROM cypher('mygraph', $$
+    CREATE (a:Node {name: 'a'})-[:Edge]->(c:Node {name: 'c'})
+$$) AS (g1 agtype);
+ g1 
+----
+(0 rows)
+
+/* should return 1 path with 1 edge */
+SELECT * FROM cypher('mygraph', $$
+    MATCH p = ()-[:Edge*]->()
+    RETURN p
+$$) AS (g2 agtype);
+                                                                               
                                                                g2              
                                                                                
                                                  
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ [{"id": 844424930131969, "label": "Node", "properties": {"name": 
"a"}}::vertex, {"id": 1125899906842625, "label": "Edge", "end_id": 
844424930131970, "start_id": 844424930131969, "properties": {}}::edge, {"id": 
844424930131970, "label": "Node", "properties": {"name": "c"}}::vertex]::path
+(1 row)
+
+/* should delete the original path and replace it with a path with 2 edges */
+SELECT * FROM cypher('mygraph', $$
+    MATCH (a:Node {name: 'a'})-[e:Edge]->(c:Node {name: 'c'})
+    DELETE e
+    CREATE (a)-[:Edge]->(:Node {name: 'b'})-[:Edge]->(c)
+$$) AS (g3 agtype);
+ g3 
+----
+(0 rows)
+
+/* should find 2 paths with 1 edge */
+SELECT * FROM cypher('mygraph', $$
+    MATCH p = ()-[:Edge]->()
+    RETURN p
+$$) AS (g4 agtype);
+                                                                               
                                                                g4              
                                                                                
                                                  
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ [{"id": 844424930131971, "label": "Node", "properties": {"name": 
"b"}}::vertex, {"id": 1125899906842626, "label": "Edge", "end_id": 
844424930131970, "start_id": 844424930131971, "properties": {}}::edge, {"id": 
844424930131970, "label": "Node", "properties": {"name": "c"}}::vertex]::path
+ [{"id": 844424930131969, "label": "Node", "properties": {"name": 
"a"}}::vertex, {"id": 1125899906842627, "label": "Edge", "end_id": 
844424930131971, "start_id": 844424930131969, "properties": {}}::edge, {"id": 
844424930131971, "label": "Node", "properties": {"name": "b"}}::vertex]::path
+(2 rows)
+
+/* should return 3 paths, 2 with 1 edge, 1 with 2 edges */
+SELECT * FROM cypher('mygraph', $$
+    MATCH p = ()-[:Edge*]->()
+    RETURN p
+$$) AS (g5 agtype);
+                                                                               
                                                                                
                                                                                
     g5                                                                         
                                                                                
                                                                                
            
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ [{"id": 844424930131969, "label": "Node", "properties": {"name": 
"a"}}::vertex, {"id": 1125899906842627, "label": "Edge", "end_id": 
844424930131971, "start_id": 844424930131969, "properties": {}}::edge, {"id": 
844424930131971, "label": "Node", "properties": {"name": "b"}}::vertex]::path
+ [{"id": 844424930131969, "label": "Node", "properties": {"name": 
"a"}}::vertex, {"id": 1125899906842627, "label": "Edge", "end_id": 
844424930131971, "start_id": 844424930131969, "properties": {}}::edge, {"id": 
844424930131971, "label": "Node", "properties": {"name": "b"}}::vertex, {"id": 
1125899906842626, "label": "Edge", "end_id": 844424930131970, "start_id": 
844424930131971, "properties": {}}::edge, {"id": 844424930131970, "label": 
"Node", "properties": {"name": "c"}}::vertex]::path
+ [{"id": 844424930131971, "label": "Node", "properties": {"name": 
"b"}}::vertex, {"id": 1125899906842626, "label": "Edge", "end_id": 
844424930131970, "start_id": 844424930131971, "properties": {}}::edge, {"id": 
844424930131970, "label": "Node", "properties": {"name": "c"}}::vertex]::path
+(3 rows)
+
+SELECT drop_graph('mygraph', true);
+NOTICE:  drop cascades to 4 other objects
+DETAIL:  drop cascades to table mygraph._ag_label_vertex
+drop cascades to table mygraph._ag_label_edge
+drop cascades to table mygraph."Node"
+drop cascades to table mygraph."Edge"
+NOTICE:  graph "mygraph" has been dropped
+ drop_graph 
+------------
+ 
+(1 row)
+
+COMMIT;
 --
 -- Clean up
 --
diff --git a/regress/sql/cypher_vle.sql b/regress/sql/cypher_vle.sql
index d184eec..193d30b 100644
--- a/regress/sql/cypher_vle.sql
+++ b/regress/sql/cypher_vle.sql
@@ -173,6 +173,48 @@ SELECT * FROM cypher('cypher_vle', $$MATCH 
p=(u)-[e*0..0]->(v) RETURN id(u), p,
 -- Each should return 13 and will be the same
 SELECT * FROM cypher('cypher_vle', $$MATCH p=()-[*0..0]->()-[]->() RETURN p 
$$) AS (p agtype);
 SELECT * FROM cypher('cypher_vle', $$MATCH p=()-[]->()-[*0..0]->() RETURN p 
$$) AS (p agtype);
+
+--
+-- Test VLE inside of a BEGIN/COMMIT block
+--
+BEGIN;
+
+SELECT create_graph('mygraph');
+
+/* should create 1 path with 1 edge */
+SELECT * FROM cypher('mygraph', $$
+    CREATE (a:Node {name: 'a'})-[:Edge]->(c:Node {name: 'c'})
+$$) AS (g1 agtype);
+
+/* should return 1 path with 1 edge */
+SELECT * FROM cypher('mygraph', $$
+    MATCH p = ()-[:Edge*]->()
+    RETURN p
+$$) AS (g2 agtype);
+
+/* should delete the original path and replace it with a path with 2 edges */
+SELECT * FROM cypher('mygraph', $$
+    MATCH (a:Node {name: 'a'})-[e:Edge]->(c:Node {name: 'c'})
+    DELETE e
+    CREATE (a)-[:Edge]->(:Node {name: 'b'})-[:Edge]->(c)
+$$) AS (g3 agtype);
+
+/* should find 2 paths with 1 edge */
+SELECT * FROM cypher('mygraph', $$
+    MATCH p = ()-[:Edge]->()
+    RETURN p
+$$) AS (g4 agtype);
+
+/* should return 3 paths, 2 with 1 edge, 1 with 2 edges */
+SELECT * FROM cypher('mygraph', $$
+    MATCH p = ()-[:Edge*]->()
+    RETURN p
+$$) AS (g5 agtype);
+
+SELECT drop_graph('mygraph', true);
+
+COMMIT;
+
 --
 -- Clean up
 --
diff --git a/src/backend/utils/adt/age_global_graph.c 
b/src/backend/utils/adt/age_global_graph.c
index a1b1f30..ec01882 100644
--- a/src/backend/utils/adt/age_global_graph.c
+++ b/src/backend/utils/adt/age_global_graph.c
@@ -75,6 +75,7 @@ typedef struct GRAPH_global_context
     HTAB *edge_hashtable;          /* hashtable to hold edge to vertex map */
     TransactionId xmin;            /* transaction ids for this graph */
     TransactionId xmax;
+    CommandId curcid;              /* currentCommandId graph was created with 
*/
     int64 num_loaded_vertices;     /* number of loaded vertices in this graph 
*/
     int64 num_loaded_edges;        /* number of loaded edges in this graph */
     ListGraphId *vertices;         /* vertices for vertex hashtable cleanup */
@@ -676,7 +677,8 @@ GRAPH_global_context *manage_GRAPH_global_contexts(char 
*graph_name,
 
         /* if the transaction ids have changed, we have an invalid graph */
         if (curr_ggctx->xmin != GetActiveSnapshot()->xmin ||
-            curr_ggctx->xmax != GetActiveSnapshot()->xmax)
+            curr_ggctx->xmax != GetActiveSnapshot()->xmax ||
+            curr_ggctx->curcid != GetActiveSnapshot()->curcid)
         {
             /*
              * If prev_ggctx is NULL then we are freeing the top of the
@@ -740,6 +742,7 @@ GRAPH_global_context *manage_GRAPH_global_contexts(char 
*graph_name,
     /* set the transaction ids */
     new_ggctx->xmin = GetActiveSnapshot()->xmin;
     new_ggctx->xmax = GetActiveSnapshot()->xmax;
+    new_ggctx->curcid = GetActiveSnapshot()->curcid;
 
     /* initialize our vertices list */
     new_ggctx->vertices = NULL;

Reply via email to