Question

I'm working through the following example in a lein repl in a clone from the cascalog project. I've run:

(def src [[1] [3] [2]])

(def queryx (<- [?x ?y] (src ?x) (inc ?x :> ?y)))

(?<- (stdout) [?x ?y] 
(queryx ?x ?y))
-- works

(?- (stdout) queryx) ;; produces (([1 2] [2 3] [3 4]))
-- works

(?- (stdout) (first-n queryx 1 :sort ["?x"] :reverse true))
--works

But when I try this one:

(?<- (stdout) [?x ?y] (first-n queryx 1 :sort ["?x"] :reverse true))

I get

IllegalArgumentException Unable to join predicates together  jackknife.core/throw-illegal (core.clj:100)

This seems to be a query creation vs execution thing. Is it possible to create a query that executes this query?

Was it helpful?

Solution

As per the doc, first-n returns a query and a query object also works as a source of data.

Taking your own example if you do:

(?<- (stdout) [?x ?y] (queryx ?x ?y))

You are binding ?x and ?y to the output of the query and hence it works.

In the faulty code there is no binding for ?x and ?y and that's why the exception. Just add the binding and it will work.

(?<- (stdout) [?x ?y] ((first-n queryx 1 :sort ["?x"] :reverse true) ?x ?y))

Remember the ?x and ?y inside queryx definition are only for that query and they are not automatically available to where ever you are using that queryx as data srouce and hence you need to explicitly bind them as shown above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top