-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathnq_dump.sql
More file actions
91 lines (83 loc) · 3.02 KB
/
Copy pathnq_dump.sql
File metadata and controls
91 lines (83 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
drop procedure NQ_DUMP;
create procedure NQ_DUMP(in dir varchar := 'dumps', in file_length_limit integer := 100000000)
{
declare file_name varchar;
declare buf, tmpbuf any;
declare buf_len, max_buf_len, file_len, file_idx integer;
set isolation = 'uncommitted';
max_buf_len := 1000000;
file_len := 0;
file_idx := 1;
file_name := sprintf ('%s/dump_%06d.nq', dir, file_idx);
buf := string_output();
for (select * from (sparql define input:storage "" select ?s ?p ?o ?g where { graph ?g { ?s ?p ?o } }) as sub option(loop)) do {
-- subject
tmpbuf := string_output();
http_nt_object("s", tmpbuf);
tmpbuf := string_output_string(tmpbuf);
if (starts_with(tmpbuf, 'b')) {
http('_:', buf);
}
http(tmpbuf, buf);
http(' ', buf);
-- predicate (cannot be blank node)
http_nt_object("p", buf);
http(' ', buf);
-- object
tmpbuf := string_output();
http_nt_object("o", tmpbuf);
tmpbuf := string_output_string(tmpbuf);
if (starts_with(tmpbuf, 'b')) {
http('_:', buf);
}
http(tmpbuf, buf);
http(' ', buf);
-- graph (cannot be blank node)
http_nt_object("g", buf);
http(' .\n', buf);
buf_len := length (buf);
if (buf_len > max_buf_len) {
file_len := file_len + buf_len;
if (file_len > file_length_limit) {
file_len := 0;
file_idx := file_idx + 1;
file_name := sprintf('%s/dump_%06d.nq', dir, file_idx);
}
string_to_file(file_name, buf, -1);
buf := string_output ();
}
}
if (length(buf) > 0) {
string_to_file(file_name, buf, -1);
}
};
DROP PROCEDURE NQ_LOAD;
CREATE PROCEDURE NQ_LOAD (in dir varchar := 'dumps/')
{
declare arr any;
arr := sys_dirlist (dir, 1);
log_enable (2, 1);
foreach (varchar f in arr) do {
if (f like '*.nq') {
declare continue handler for sqlstate '*' {
log_message (sprintf ('Error in %s', f));
};
-- flags
-- 1 - Single quoted and double quoted strings may with newlines.
-- 2 - Allows bnode predicates (but SPARQL processor may ignore them!).
-- 4 - Allows variables, but triples with variables are ignored.
-- 8 - Allows literal subjects, but triples with them are ignored.
-- 16 - Allows '/', '#', '%' and '+' in local part of QName ("Qname with path")
-- 32 - Allows invalid symbols between '<' and '>', i.e. in relative IRIs.
-- 64 - Relax TURTLE syntax to include popular violations.
-- 128 - Try to recover from lexical errors as much as it is possible.
-- 256 - Allows TriG syntax, thus loading data in more than one graph.
-- 512 - Allows loading N-quad dataset files with and optional context value to
-- indicate provenance as detailed
--
-- we use 1 | 2 | 4 | 8 | 128 | 512 = 655
DB.DBA.TTLP_MT (file_open (dir || '/' || f), '', 'http://example.org/', 655, 1);
}
}
exec ('checkpoint');
};