Coverage report: /development/source/library/org/datagraph/spocq-shard/src/algebra/operators/ask.lisp
| Kind | Covered | All | % |
| expression | 66 | 68 | 97.1 |
| branch | 1 | 2 | 50.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Base: 10; Package: org.datagraph.spocq.implementation; -*-
3
(in-package :org.datagraph.spocq.implementation)
5
(:documentation "This file defines the ask query form operator for the 'org.datagraph.spocq' RDF engine."
8
"Copyright 2010 [datagraph inc](mailto:james@datagraph.org) All Rights Reserved.")
11
"The query forms (ask, construct, describe, and select) use the result of the algebra expression to
12
generate the response. ask produces a boolean result which indicatees whether any solution satisfied
15
See core;processing.lisp.
19
(defmacro spocq.a:|ask| (expression)
20
"( ( solutionField ) xsd:boolean )
21
The ASK form yields true iff the solution field is not empty.
22
No information is returned about the possible query solutions, just whether or not a solution exists."
23
(macroexpand-ask expression))
25
(defun macroexpand-ask (expression)
26
(if (slice-form-p expression)
27
`(spocq.e:ask ,expression)
28
`(spocq.e:ask (spocq.a:|slice| (spocq.e::with-join-scope ,(gensym "ask-") ,expression) :start 0 :end 1))))
31
(defgeneric spocq.e:ask (solution-field)
32
(:documentation "Yield true iff the solution field is not empty.")
34
(:method :before ((field t))
35
(incf-stat *algebra-operations*)
36
(trace-algebra spocq.e:ask field))
38
(:method ((solution-field solution-generator))
39
(spocq.e::stream-ask solution-field)))
42
(defun spocq.e:stream-ask (field-generator)
43
;; page length and channel depth are not significant, as there is no solution page
44
(let ((result-channel (make-unit-table-channel :name (cons 'spocq.a:|ask| (task-id *query*)))))
45
(flet ((run-ask-thread (result-channel field-generator)
46
(let* ((base-dimensions (solution-generator-dimensions field-generator))
47
(base-channel (solution-generator-channel field-generator))
48
(base-expression (solution-generator-expression field-generator))
49
(*thread-operations* (cons (list 'spocq.a:|ask| base-dimensions)
50
*thread-operations*)))
51
(push 'spocq.a:|ask| (channel-name base-channel))
52
(query-run-in-thread *query* base-expression)
53
(process-ask result-channel base-channel)
55
(make-boolean-generator :operator 'spocq.a:|ask|
56
:expression (list #'run-ask-thread result-channel field-generator)
57
:channel result-channel
58
:constituents (list field-generator)))))
60
#+(or) ;; for null testing
61
(defun spocq.e:stream-ask (field-generator)
62
"For testing, just emit false.
63
nb. this does something to threads and/or operations wrt a query
64
which then causes the query to hang."
65
(let ((result-channel (make-unit-table-channel :name (cons 'spocq.a:|ask| (task-id *query*)))))
66
(make-boolean-generator :operator 'spocq.a:|ask|
67
:expression (list #'complete-field result-channel)
68
:channel result-channel
69
:constituents (list field-generator))))
72
(defmethod process-ask ((result-field array-page-channel)
73
(base-field array-page-channel))
74
"Emit just the first field page - if present, to indicate true, or just complete the field."
76
(let ((solution-page (get-field-page base-field)))
77
(incf-stat *solutions-processed*)
79
(put-field-page result-field (unit-table)))
80
(complete-field result-field)))