Last active
January 21, 2016 11:17
-
-
Save dvcama/031c4c32d8fa8481fd12 to your computer and use it in GitHub Desktop.
virtuoso : export all graphs (triple dump) - virtuoso 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE dump_nquads | |
( IN dir VARCHAR := 'dumps' | |
, IN start_from INT := 1 | |
, IN file_length_limit INTEGER := 100000000 | |
, IN comp INT := 1 | |
) | |
{ | |
DECLARE inx, ses_len INT | |
; DECLARE file_name VARCHAR | |
; DECLARE env, ses ANY | |
; | |
inx := start_from; | |
SET isolation = 'uncommitted'; | |
env := vector (0,0,0); | |
ses := string_output (10000000); | |
FOR (SELECT * FROM (sparql define input:storage "" SELECT ?s ?p ?o ?g { GRAPH ?g { ?s ?p ?o } . FILTER ( ?g != virtrdf: ) } ) AS sub OPTION (loop)) DO | |
{ | |
DECLARE EXIT HANDLER FOR SQLSTATE '22023' | |
{ | |
GOTO next; | |
}; | |
http_nquad (env, "s", "p", "o", "g", ses); | |
ses_len := LENGTH (ses); | |
IF (ses_len >= file_length_limit) | |
{ | |
file_name := sprintf ('%s/output%06d.nq', dir, inx); | |
string_to_file (file_name, ses, -2); | |
IF (comp) | |
{ | |
gz_compress_file (file_name, file_name||'.gz'); | |
file_delete (file_name); | |
} | |
inx := inx + 1; | |
env := vector (0,0,0); | |
ses := string_output (10000000); | |
} | |
next:; | |
} | |
IF (length (ses)) | |
{ | |
file_name := sprintf ('%s/output%06d.nq', dir, inx); | |
string_to_file (file_name, ses, -2); | |
IF (comp) | |
{ | |
gz_compress_file (file_name, file_name||'.gz'); | |
file_delete (file_name); | |
} | |
inx := inx + 1; | |
env := vector (0,0,0); | |
} | |
} | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment