about summary refs log tree commit diff
path: root/visualize-schema.scm
diff options
context:
space:
mode:
authorArun Isaac2021-12-24 14:58:17 +0530
committerArun Isaac2021-12-24 14:58:17 +0530
commitea43eb9bfb4acbc9aa882a3ca3b44a506e3330ed (patch)
tree776b0c7cbaf71b10480cc74b795026aeb9a2bbec /visualize-schema.scm
parenta2cd075131597e9150897ccd46c07a2c924c519f (diff)
downloadgn-transform-databases-ea43eb9bfb4acbc9aa882a3ca3b44a506e3330ed.tar.gz
Fetch entire table schema in single SPARQL query.
* visualize-schema.scm (tables): Fetch entire table schema in single
SPARQL query.
Diffstat (limited to 'visualize-schema.scm')
-rw-r--r--visualize-schema.scm40
1 files changed, 17 insertions, 23 deletions
diff --git a/visualize-schema.scm b/visualize-schema.scm
index af86477..8fa27a6 100644
--- a/visualize-schema.scm
+++ b/visualize-schema.scm
@@ -118,33 +118,27 @@ return #f. ALL-TABLES is a list of all tables in the database."
   "Return list of all tables in DB. Each element of the returned list
 is a <table> object."
   (map (match-lambda
-         ((table size)
+         ((table size fields field-types field-dumped)
           (make-table table
-                      ;; FIXME: Why is size coming out as a string?
                       (string->number size)
-                      (map (match-lambda
-                             ((field type) (make-column field type)))
-                           (sparql-query-records
-                            ;; We use format to construct the query instead of
-                            ;; select due to an outstanding bug in
-                            ;; guile-sparql. See
-                            ;; https://github.com/roelj/guile-sparql/issues/5
-                            (format
-                             "SELECT ?fieldname ?fieldtype
+                      (map make-column
+                           (string-split fields #\,)
+                           (string-split field-types #\,)
+                           (map (cut string=? <> "1")
+                                (string-split field-dumped #\,))))))
+       (sparql-query-records
+        "PREFIX gn: <http://genenetwork.org/>
+SELECT SAMPLE(?tablename) SAMPLE(?size) GROUP_CONCAT(?fieldname ; separator=\",\") GROUP_CONCAT(?fieldtype ; separator=\",\") GROUP_CONCAT(EXISTS{ ?dump rdf:type gn:dump . ?dump gn:dependsOn ?field .} ; separator=\",\")
 WHERE
 {
-  ?table <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://genenetwork.org/sqlTable> .
-  ?table <http://genenetwork.org/name> ~s .
-  ?field <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://genenetwork.org/sqlTableField> .
-  ?table <http://genenetwork.org/hasField> ?field .
-  ?field <http://genenetwork.org/name> ?fieldname .
-  ?field <http://genenetwork.org/sqlFieldType> ?fieldtype .
-}" table))))))
-       (sparql-query-records
-        (select '(tablename size)
-                `((table ,(rdf "type") ,(gn "sqlTable"))
-                  (table ,(gn "name") tablename)
-                  (table ,(gn "hasSize") size))))))
+  ?table rdf:type gn:sqlTable ;
+         gn:name ?tablename ;
+         gn:hasSize ?size ;
+         gn:hasField ?field .
+  ?field rdf:type gn:sqlTableField ;
+         gn:name ?fieldname ;
+         gn:sqlFieldType ?fieldtype .
+} GROUP BY ?table")))
 
 (define (foreign-key-graphviz-edges tables)
   "Return the list of graphviz edges representing foreign key