Fork me on GitHub
#sql
<
2017-10-31
>
uwo05:10:20

I have the result of a clojure.jdbc/reducible-query that I’d like to put onto a channel, however both to-chan and onto-chan appear to rely on the seq interface, which is giving me this error. (I also happen to be applying an eduction to the query result, but i don’t think that’s relevant):

java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.java.jdbc$reducible_query$reify__16834
        at clojure.lang.RT.seqFrom(RT.java:547)
        at clojure.lang.RT.seq(RT.java:527)
        at clojure.lang.RT.iter(RT.java:603)
        at clojure.core.Eduction.iterator(core.clj:7560)
        at clojure.lang.RT.seqFrom(RT.java:537)
        at clojure.lang.RT.seq(RT.java:527)
        at clojure.core$seq__6407.invokeStatic(core.clj:137)
        at clojure.core$seq__6407.invoke(core.clj:137)
        at clojure.core.async$bounded_count.invokeStatic(async.clj:629)
        at clojure.core.async$bounded_count.invoke(async.clj:623)
        at clojure.core.async$to_chan.invokeStatic(async.clj:653)
        at clojure.core.async$to_chan.invoke(async.clj:649)

seancorfield05:10:18

@uwo Yeah, I was a bit surprised that there doesn't seem to be an obvious way to reduce a collection onto a channel. It's been a while since I looked at it, and I didn't dig very deeply.

uwo05:10:52

@seancorfield interesting! thanks for the response.

uwo15:10:42

@seancorfield do you remember why you decided to go with IReduce, instead of IReduceInit?

seancorfield15:10:08

@uwo To support more use cases. A number of constructs in core support IReduce (cycle, repeat, range, iterable, persistent list, persistent vector), and IReduce is a superset of IReduceInit so reducible-query is acceptable to both.

uwo15:10:31

any idea why an eduction over the result of reducible-query would lead to at clojure.lang.RT.seq getting called?

uwo15:10:52

it appears my problem was further up the chain, before onto-chan was called. attempts to reduce over (eduction xf (clojure.jdbc/reducible-query ...)) ultimately result in clojure.lang.RT.iter calling seq.

hiredman23:10:49

what version of clojure?

hiredman23:10:30

I guess reducible-query requires something with IReduce

hiredman23:10:09

are you reducing without giving an initial value?

hiredman23:10:36

Eduction only implements clojure.lang.IReduceInit not clojure.lang.IReduce

hiredman23:10:43

(so because it doesn't implement IReduce, reducing goes through its implementation of Iterable, which is what calls RT.iter)