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

joshinnis pushed a commit to branch AGEHA
in repository https://gitbox.apache.org/repos/asf/age.git


The following commit(s) were added to refs/heads/AGEHA by this push:
     new cf182b59 Added a new Function named IsWriteQuery. (#767)
cf182b59 is described below

commit cf182b59486d43f718039b95c755f6e3a4851f4e
Author: Muhammad Zahid <[email protected]>
AuthorDate: Mon Apr 3 10:19:23 2023 +0500

    Added a new Function named IsWriteQuery. (#767)
    
    Checks Whether the query is a write query or not.
---
 src/age/age_pool.c                | 29 ++++++++++++++++++++++++++++-
 src/include/age/age_pool.h        |  1 +
 src/protocol/pool_proto_modules.c |  1 +
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/age/age_pool.c b/src/age/age_pool.c
index 6df6ea75..87edc5fe 100644
--- a/src/age/age_pool.c
+++ b/src/age/age_pool.c
@@ -146,7 +146,11 @@ isCypherQuery (Node* node, char** retstr)
        return false; 
 }
 
-List* extractCypherFuncs(List *ParsedCyphertreeList)
+List* 
+/* Returns all the Cypher Nodes
+   in the given parse tree.
+*/
+extractCypherFuncs(List *ParsedCyphertreeList)
 {
 
        ListCell *resultfl;
@@ -168,4 +172,27 @@ List* extractCypherFuncs(List *ParsedCyphertreeList)
        }
        
        return cypher_funcs_list;
+}
+
+bool 
+/* Returns true if the given cypher node
+   is a write query.
+*/
+IsWriteQuery(List *cypher_funcs_list){
+       ListCell *cypherfl;
+       foreach (cypherfl, cypher_funcs_list)
+       {
+               char *cypher_func = (char *)lfirst(cypherfl);
+
+
+               // DETACH DELETE is covered under cypher_delete.
+            // REMOVE command is covered under cypher_set.
+        if (is_ag_node(cypher_func, cypher_create) || is_ag_node(cypher_func, 
cypher_set) ||
+        is_ag_node(cypher_func, cypher_delete) || is_ag_node(cypher_func, 
cypher_merge))
+        {
+               return true;
+        }
+       }
+
+       return false;
 }
\ No newline at end of file
diff --git a/src/include/age/age_pool.h b/src/include/age/age_pool.h
index 341017a7..36c7c5cd 100644
--- a/src/include/age/age_pool.h
+++ b/src/include/age/age_pool.h
@@ -25,6 +25,7 @@
 bool isCypherQuery (Node* node, char** str);
 void preprocess_cypherstr(char *target);
 List* extractCypherFuncs(List* ParsedCyphertreeList);
+bool IsWriteQuery(List* cypher_funcs_list);
 
 
 #endif
diff --git a/src/protocol/pool_proto_modules.c 
b/src/protocol/pool_proto_modules.c
index 22a41642..67097b86 100644
--- a/src/protocol/pool_proto_modules.c
+++ b/src/protocol/pool_proto_modules.c
@@ -319,6 +319,7 @@ SimpleQuery(POOL_CONNECTION * frontend,
                        Node *temp = llast(cyphertree);
                list_delete_ptr(cyphertree, temp);
                        List* cypher_funcs_list = 
extractCypherFuncs(cyphertree);
+                       bool isWriteQuery = IsWriteQuery(cypher_funcs_list);
                        
                }
 

Reply via email to