Database Reference
In-Depth Information
3.
Even with more than one generator, we can still include one or more test predicates.
Here's a query that only returns companions for the modern-era Doctors:
user=> (?<- (stdout) [?name]
(full-name ?c ?name) (doctor ?c ?dr)
(>= ?dr 9) )
RESULTS
-----------------------
Adelaide Brooke
Amy Pond
Astrid Peth
Christina de Souza
Craig Owens
Donna Noble
4. Test predicates can be used to do more than just ilter data. We can also use them
to generate data. For example, in the next query, we add a modern lag to each
row in order to indicate whether they are from the modern era or not. We do this by
assigning the test predicate's output to a variable binding using the :> operator:
user=> (?<- (stdout)
[?name ?modern]
(full-name ?c ?name) (doctor ?c ?dr)
(>= ?dr 9 :> ?modern ))
RESULTS
-----------------------
Ace false
Adam Mitchell true
Adelaide Brooke true
Adric false
Adric false
Amy Pond true
Astrid Peth true
Out of the simple building blocks of generator and predicates, Cascalog makes it easy
to build complex queries in an intuitive way. We'll see even more complex queries in the
upcoming recipes, but composing generators and predicates and sharing bindings are the
basis of all of them.
 
Search WWH ::




Custom Search