Fork me on GitHub
#sql
<
2019-12-03
>
boyanb15:12:56

Hm, this doesn't feel good.

boyanb15:12:17

So, I'm looking to migrating to next-jdbc. We have a nice wraper around clojure.jdbc that we use for lazy batch processing(millions of rows, doseq/partition-all based).

boyanb15:12:32

I've written it in two different ways with next-jdbc and both feel "unnatural". I first wrote it with next.jdbc/plan + an eduction

(eduction (map transformation-goes-here) (partitiona-all batch-count) (jdbc/plan ....))
and afterwards a reduce over it

boyanb15:12:16

Then with channels, dispatching from inside a simple reduce over jdbc/plan (and a lazy-seq on the channel). Neither, I feel, gives the flexibility of a simple "lazy-seq".

boyanb15:12:52

Am I missing something obvious or should I get used to transducers as the new reality for cursors?

seancorfield16:12:10

How were you doing it with clojure.java.jdbc?

seancorfield16:12:43

plan is a refinement of reducible-query which is what you should have been using already I would expect.

boyanb16:12:23

We were using a custom :result-set-fn that was tying into a sink/source abstraction.

boyanb16:12:46

I wouldn't say it's equivalent and I am very open to trying the new next-jdbc way.

boyanb16:12:09

But does what I wrote above make sense? Are those the two approaches we have with plan?

seancorfield16:12:29

Then just use reduce over plan with a variant of that function

boyanb16:12:05

Yeah, the eduction variant above is pretty much that, no?

seancorfield16:12:13

I think the two approaches you described are overkill

boyanb16:12:36

I am missing something them. My impression is that if I reduce the plan directly, I can't actually batch.

boyanb16:12:44

because the unit is always one row, so I def needs to partition before reducing.

boyanb16:12:47

is that incorrect assumption?

seancorfield16:12:47

The result set fn must be eager by definition

seancorfield16:12:52

A transducer can be stateful and handle partitioning if you need that

seancorfield16:12:53

So transduce over plan if you need more than reduce.

boyanb16:12:04

Wait, if I understand correctly.

boyanb16:12:13

as plan is already reducible, I don't need the eduction?

seancorfield16:12:46

And your result set fn before had to be eager

seancorfield16:12:02

So you're not losing laziness here

boyanb16:12:06

But in this case, the ONLY eager fn required is the final reduce, right?

boyanb16:12:34

I think I get it, thanks. Let's see if I can dumb down this a bit in code.

seancorfield16:12:50

That's just how transducers work : they are eager

boyanb16:12:29

ty. btw, I was surprised by how few people seem to have migrated to next-jdbc.

boyanb16:12:25

I understand it, somehow. But still, I hope it actually picks up. The API is a lot nicer.

boyanb16:12:55

(and still similar to make a migration relatively painless)

seancorfield16:12:46

I'm actually quite pleased with how fast adoption is going -- given Clojure's slow pace of change in general 😁

👍 12