Subject: bug#26807: closed (Re: bug#26807: [PATCH] graph: Add Cypher backend.)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 11 May 2017 14:31:02 +0000

Your bug report

#26807: [PATCH] graph: Add Cypher backend.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
26807: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=26807
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#26807: [PATCH] graph: Add Cypher backend.
From: Roel Janssen <[email-masked]>
To: Ludovic Courtès <[email-masked]>
Cc: [email-masked]
Date: Thu, 11 May 2017 16:29:44 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Roel Janssen writes:

> Ludovic Courtès writes:
>
>> Hi,
>>
>> Roel Janssen <[email-masked]> skribis:
>>
>>> Ludovic Courtès writes:
>>>
>>>> Hello!
>>>>
>>>> Roel Janssen <[email-masked]> skribis:
>>>>
>>>>> From 0e9c95ef3473fa7066ccd5991b1c14400aaa7076 Mon Sep 17 00:00:00 2001
>>>>> From: Roel Janssen <[email-masked]>
>>>>> Date: Sat, 6 May 2017 23:15:03 +0200
>>>>> Subject: [PATCH] graph: Add Cypher backend.
>>>>>
>>>>> * guix/graph.scm (%cypher-backend): New variable.
>>>>
>>>> If Neo4j is free software and packageable (is it Java?), why not!
>>>
>>> Yes, it's Java, so a lot of work to package.
>>>
>>> Fortunately, there is also AgensGraph which is similar to the PostgreSQL
>>> package, and it supports openCypher as well.  So I tried it, and the
>>> queries will work with the latest git checkout of AgensGraph.  Their
>>> latest release does not support automatically creating labels for the
>>> nodes and edges, which was fixed in this commit:
>>>
>>> https://github.com/bitnine-oss/agensgraph/commit/5eaecc1d429a08165bb964013ab8ee5516a062e7
>>>
>>> So I think the output of what my patch produces should be fine for
>>> multiple implementations of openCypher.
>>
>> OK.  Do these tools support interactive visualization in addition to
>> graph queries?
>
> Neo4j does that in a web browser, see:
> https://neo4j.com/developer/guide-data-visualization/
>
> AgensGraph does not AFAIK.  It just looks like (and it is) a PostgreSQL
> prompt.
>
>>
>>>> Could you add a few lines in guix.texi under “Invoking guix graph”?
>>>> Maybe give an example invocation of cypher and explain how it differs
>>>> from the other backends (interactive features maybe?).
>>>
>>> Would the attached patch be fine for the manual?
>>
>> Yes, perfect (please squash it with the patch that adds the new
>> backend).
>>
>> Thank you!
>>
>> Ludo’.
>
> Great!  I will do that.

Pushed in 5899fafbfefcd7682aec8f2caaaad3add678a3c4.

Thanks!

Kind regards,
Roel Janssen

Subject: [PATCH] graph: Add Cypher backend.
From: Roel Janssen <[email-masked]>
To: [email-masked]
Date: Sat, 06 May 2017 23:21:32 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

>From 0e9c95ef3473fa7066ccd5991b1c14400aaa7076 Mon Sep 17 00:00:00 2001
From: Roel Janssen <[email-masked]>
Date: Sat, 6 May 2017 23:15:03 +0200
Subject: [PATCH] graph: Add Cypher backend.

* guix/graph.scm (%cypher-backend): New variable.
---
 guix/graph.scm | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/guix/graph.scm b/guix/graph.scm
index 7af2cd3b8..d7fd5f3e4 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -229,6 +229,35 @@ nodeArray.push(nodes[\"~a\"]);~%"
                  emit-d3js-prologue emit-d3js-epilogue
                  emit-d3js-node emit-d3js-edge))
 
+
+
+;;;
+;;; Cypher export.
+;;;
+
+(define (emit-cypher-prologue name port)
+  (format port ""))
+
+(define (emit-cypher-epilogue port)
+  (format port ""))
+
+(define (emit-cypher-node id label port)
+  (format port "MERGE (p:Package { id: ~s }) SET p.name = ~s;~%"
+          id label ))
+
+(define (emit-cypher-edge id1 id2 port)
+  (format port "MERGE (a:Package { id: ~s });~%" id1)
+  (format port "MERGE (b:Package { id: ~s });~%" id2)
+  (format port "MATCH (a:Package { id: ~s }), (b:Package { id: ~s }) CREATE UNIQUE (a)-[:NEEDS]->(b);~%"
+          id1 id2))
+
+(define %cypher-backend
+  (graph-backend "cypher"
+                 "Generate Cypher queries."
+                 emit-cypher-prologue emit-cypher-epilogue
+                 emit-cypher-node emit-cypher-edge))
+
+
 
 ;;;
 ;;; Shared.
@@ -236,7 +265,8 @@ nodeArray.push(nodes[\"~a\"]);~%"
 
 (define %graph-backends
   (list %graphviz-backend
-        %d3js-backend))
+        %d3js-backend
+        %cypher-backend))
 
 (define* (export-graph sinks port
                        #:key
-- 
2.12.2

Dear Guix,

I would like to add another backend to the 'guix graph' command.  This
backend will return a bunch of queries that can be used to create a
graph database for any database engine that uses openCypher (although I
only know one engine and it's called neo4j, which should be GPLv3 code).

If there was a way to ensure node definitions are written to the output
before the edges, I could simplify the queries a bit.  But I believe it
is quite fast anyway.

Thanks!

Kind regards,
Roel Janssen