Coverage report: /development/source/library/org/datagraph/spocq-shard/src/core/query-deconstruction.lisp
| Kind | Covered | All | % |
| expression | 0 | 58 | 0.0 |
| branch | 0 | 6 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; -*- package: spocq.i; -*-
3
(in-package :org.datagraph.spocq.implementation)
5
(defgeneric run-deconstructed-query (query repository &key agent)
6
(:documentation "Execute a query by walking the algebra tree depth-first
7
to execute each node in turn and save the individual results for later analysis.
8
Return a tree of the individual counts and execution times.")
9
(:method ((query query) repository &key (agent (task-agent query)))
10
(run-deconstructed-query (query-sse-expression query) repository :agent agent))
12
(:method ((query string) repository &rest args)
13
(apply #'run-deconstructed-query (parse-sparql query) repository args))
16
(:method ((query cons) repository &key agent)
17
(declare (ignore agent))
19
(labels ((run-clause (form)
21
(let ((start-time (get-internal-real-time))
22
(result (ignore-errors (run-sparql
23
`(sparql.parser:sparql :select
25
:vars (?count ?distinctCount)
27
((?@aggregate-1 (:count :* :distinct t))
28
(?@aggregate-2 (:count :*))
29
(?distinctCount (:_assign ?@aggregate-1))
30
(?count (:_assign ?@aggregate-2))))
31
:results-format :lists)))
32
(end-time (get-internal-real-time)))
34
(destructuring-bind ((count distinct-count)) result
35
(push `(:time ,(- end-time start-time)
36
:count ,(upi-model-value count)
37
:distinct-count ,(upi-model-value distinct-count)
40
(loop for form in (rest form)
41
when (traceable-form-p form)
42
do (run-clause form))))))
43
(cond ((eq (first query) 'sparql.parser:sparql)
44
(run-clause (getf (cddr query) :where)))
45
((traceable-form-p query)
49
(:method ((query cons) repository &key agent)
50
(labels ((run-clause (form)
51
(let ((start-time (get-internal-real-time)))
52
(multiple-value-bind (result condition)
53
(ignore-errors (run-sparql
56
((?::|count| (spocq.a:|count| SPOCQ.S:*))
57
(?::|distinctCount| (spocq.a:|count| SPOCQ.S:*
58
:DISTINCT spocq.a:|distinct|))))
59
:repository-id repository
62
(destructuring-bind ((count distinct-count)) result
63
(let ((children (unless (member (first form) '(spocq.a:|bgp| spocq.a:|service|))
64
;; suppress forms for which no sub-expression should stand independent
65
;; eg. pushed filters in bgp forms and all service sub-expressions
66
(loop for form in (rest form)
67
when (traceable-form-p form)
68
collect (run-clause form)))))
69
`(:operator ,(string (first form))
70
:time ,(- (get-internal-real-time) start-time)
72
:distinct-count ,distinct-count
74
:children ,children))))
76
`(:form ,form :error ,(format nil "~a" condition))))))))
79
(defparameter *traceable-operators*
100
"A list of the operators for which to perform deconstructed tracing")
102
(defun traceable-form-p (form)
104
(member (first form) *traceable-operators*)))
110
(sparql:parse-sparql "
111
select (count (distinct *) as ?distinctCount) (count (*) as ?count)
117
(let ((*triple-store-name* "aegl-formerprod-nosensors-009-20140527-02-20140725"))
119
(format-deconstruction
120
(run-deconstructed-query
121
"select (count (*) as ?count)
122
where { { ?s a <http://www.w3.org/2002/07/owl#Class> }
124
{ ?s <http://eu.sekkat.gl/pred#internalRealTime> ?time }
127
:stream *trace-output*)))
129
(let ((*triple-store-name* "aegl-formerprod-nosensors-009-20140527-02-20140725"))
132
(sparql:run-sparql "select distinct ?p where {?s ?p ?o} limit 10"
133
:results-type :lists))))
134
(let ((*triple-store-name* "aegl-formerprod-nosensors-009-20140527-02-20140725"))
137
(sparql:run-sparql "select distinct ?o where {?s a ?o} limit 10"
138
:results-type :lists))))
140
(run-deconstructed-query "select * where { {?s ?p ?o} union { graph ?g {?s ?p ?o} } }"