onyx

FYI: alternative Onyx :onyx: chat is at <https://gitter.im/onyx-platform/onyx> ; log can be found at <https://clojurians-log.clojureverse.org/onyx/index.html>
n.kulish 2017-12-22T13:40:43.000141Z

Hi! I see /onyx-savepoints/latest/tenancy-id/job-id in zookeeper contains data for resume point creation. It’s populated after the job is completed, but killing the job prevents this data from being created. Could this data be populated even in the case the job is killed?

lucasbradstreet 2017-12-22T20:15:50.000104Z

I suspect what is happening is that you are killing the job before a barrier makes it the whole way through the job. It will be populated if given enough time in relation to the barrier period peer-config setting (check the cheat sheet, I’m on my phone)

schmee 2017-12-22T21:06:02.000047Z

hello gents! how can I modify the word count example in the onyx-examples repo to emit a map of all counts every trigger instead of printing to stdout? https://github.com/onyx-platform/onyx-examples/tree/0.12.x/aggregation

schmee 2017-12-22T21:06:35.000221Z

I’ve managed to find a solution involving a custom aggregation function but it seems like there should be an easier way

schmee 2017-12-22T21:07:20.000056Z

the info in the user guide around aggregation seems to have fallen behind the last couple of releases, hopefully I can submit a couple of updates to it once I have figured out what to do 🙂

lucasbradstreet 2017-12-22T21:09:01.000281Z

Hi @schmee, that’d be great if you could help us with the docs! When you say emit, do you mean to a downstream task?

schmee 2017-12-22T21:09:09.000283Z

indeed

lucasbradstreet 2017-12-22T21:10:21.000125Z

You can use this in lieu of trigger/sync http://www.onyxplatform.org/docs/cheat-sheet/latest/#trigger-entry/:trigger/emit

schmee 2017-12-22T21:10:30.000003Z

I think I am misunderstanding something, cause I expected the state map received in the dump-window! function to be this map, but it seems like it only contains one word at a time?

lucasbradstreet 2017-12-22T21:10:59.000177Z

An example can be found in a test here: https://github.com/onyx-platform/onyx/blob/0.12.x/test/onyx/windowing/emit_aggregate_test.clj

lucasbradstreet 2017-12-22T21:11:11.000065Z

I’d love another onyx example demonstrating this

lucasbradstreet 2017-12-22T21:11:45.000216Z

That example might be using the discarding refinement

lucasbradstreet 2017-12-22T21:11:58.000030Z

Rather than the accumulating refinement

lucasbradstreet 2017-12-22T21:12:15.000161Z

I’m on my phone so it’s hard to look too hard

schmee 2017-12-22T21:13:22.000186Z

ahh, I see, no worries 🙂

schmee 2017-12-22T21:14:00.000106Z

unfortunately the info around refinements is one of the parts that are really lacking from the docs at the moment

schmee 2017-12-22T21:14:32.000298Z

the changelog says that they have been replaced by pre- and post-evictors but there is no info on how to use these in the guide

schmee 2017-12-22T21:14:41.000029Z

I’ll play around a bit and see if I can figure it out 🙂

lucasbradstreet 2017-12-22T21:14:54.000245Z

Hmm, yes that’s true.

lucasbradstreet 2017-12-22T21:15:44.000284Z

Yes, the state in this example is just the count

lucasbradstreet 2017-12-22T21:15:50.000338Z

Because it’s using the count aggregation

lucasbradstreet 2017-12-22T21:16:00.000132Z

So it is not due to the evict or

schmee 2017-12-22T21:16:53.000148Z

hmm, I must be misinterpreting the docs: http://www.onyxplatform.org/docs/user-guide/latest/#_grouping

schmee 2017-12-22T21:17:01.000260Z

>>> For example, if you had the catalog entry set to :onyx/group-by-key with value :name, and you used a window aggregate of :onyx.windowing.aggregation/count, and you sent through segments [{:name “john”} {:name “tiffany”} {:name “john”}], the aggregate map would look like {“john” 2 “tiffany” 1}.

lucasbradstreet 2017-12-22T21:18:57.000190Z

Ah yes, but the trigger is scoped to the group

lucasbradstreet 2017-12-22T21:19:22.000173Z

So each segment will result in you only getting the state for that group

schmee 2017-12-22T21:20:35.000231Z

I see! Is there any way to get my hands on the mentioned “aggregate map” or is that an internal data structure?

lucasbradstreet 2017-12-22T21:21:44.000205Z

That’s internal unless you build your own aggregation which maintains the whole thing

schmee 2017-12-22T21:21:51.000156Z

btw, here is how I rolled my own type counting example, I’m just curious if there is a better solution or if this is the canonical way to do it 🙂

(defn sum-init-fn [window]
  {})

(defn sum-aggregation-fn [window segment]
  {(:type segment) 1})

(defn sum-application-fn [window state value]
  (merge-with + state value))

(def sum
  {:aggregation/init sum-init-fn
   :aggregation/create-state-update sum-aggregation-fn
   :aggregation/apply-state-update sum-application-fn})

twashing 2017-12-30T21:26:07.000046Z

@schmee @lucasbradstreet :aggregation/create-state-update fn signature has changed from (window, state, segment) to (window, segment). (https://github.com/onyx-platform/onyx/blob/0.12.x/changes.md#0110). But what’s the return type expected by sum-application-fn? The code below gives me an error

Handling uncaught exception thrown inside task lifecycle :lifecycle/assign-windows. Killing the job. -&gt; Exception type: java.lang.IllegalArgumentException. Exception message: Don't know how to create ISeq from: clojure.lang.Keyword

twashing 2017-12-30T21:26:22.000005Z

(defn sum-init-fn [window]
  {})

(defn sum-aggregation-fn [window segment]
  (let [k (second (:window/aggregation window))]
    {:set-value k}))

(defn sum-application-fn [window state value]
  (merge-with + state value))

lucasbradstreet 2017-12-30T21:27:52.000014Z

Can you post the rest of the stack trace?

lucasbradstreet 2017-12-30T21:28:15.000069Z

It might be from the second on (:window/aggregation window)?

lucasbradstreet 2017-12-30T21:28:21.000052Z

What’s that set to?

twashing 2017-12-30T22:16:45.000029Z

@lucasbradstreet Yeah, it was my bad. My payloads are A). And I changed the code to B).

A)
70144dea-cdd1-443d-9e7f-55cc5d0928d7,{:name "John" :age 49}
dbe61f62-257a-4f00-b85a-6d4c0cca44cd,{:name "Madeline" :age 55}
8e5998ab-5424-4ccb-9e54-5f3676aaa0b6,{:name "Geoffrey" :age 14}

;; B)

(defn sum-init-fn [window]
  0)

(defn sum-aggregation-fn [window segment]
  (let [k (-&gt; segment :message :age)]
    {:set-value k}))

(defn sum-application-fn [window state value]
  (merge-with + state value))

twashing 2017-12-30T22:26:53.000006Z

So far I’ve been been able to implements Aggregation &amp; State Management pretty cleanly.

lucasbradstreet 2017-12-30T22:31:03.000009Z

Great 🙂

lucasbradstreet 2017-12-30T22:31:17.000010Z

If you see anything in the docs that could be clarified, PRs are always welcome!

twashing 2017-12-30T22:31:23.000014Z

Triggers are also firing as expected 👍:skin-tone-5:

twashing 2017-12-30T22:32:09.000002Z

Yeah, I was following the Aggregation &amp; State Management portion of the user guide. http://www.onyxplatform.org/docs/user-guide/0.12.x/#aggregation-state-management

twashing 2017-12-30T22:32:21.000001Z

I think that just needs to be updated.

twashing 2017-12-30T22:32:31.000080Z

I’ll try to whip up a PR. I really appreciate all the help!

lucasbradstreet 2017-12-30T22:34:40.000059Z

Cool, I think we already received a PR there, so please branch off master if you decide to make fixes 🙂 https://github.com/onyx-platform/onyx/pull/835

twashing 2017-12-30T22:40:33.000006Z

master. Ok, lemme have a look….

schmee 2017-12-22T21:22:21.000087Z

I guess this is what you mean by “building your own aggregation”

lucasbradstreet 2017-12-22T21:22:27.000117Z

Exactly, yes

schmee 2017-12-22T21:22:53.000043Z

sweet, then I’m on the right track, thanks for taking your time 👍

lucasbradstreet 2017-12-22T21:23:06.000098Z

Good to hear. My reception is getting bad anyway. :)

schmee 2017-12-22T22:57:10.000134Z

@lucasbradstreet here’s a PR with a couple of doc fixes, I’ll make more as I go along 🙂 https://github.com/onyx-platform/onyx/pull/835