Skip to content
Alan Malloy edited this page Oct 8, 2013 · 4 revisions

Custom lamina operators

  • topic.after(1h, action='login'). Accepts a window as its first argument, followed by any number of where clauses. Once it sees a message that satisfies all of the clauses, after starts saving up all messages until window time has expired, after which it emits a single message that is a list of all actions (including the first "trigger" action) since the window started. after is most useful when paired with group-by. For example user:action:*.group-by(id).after(1h, topic='user:action:login') will produce a map from user-id to lists meaning "all actions this user performed within an hour of logging in".

  • topic.where(actions contains 'login'). Looks inside each incoming map, and assumes that the :actions key is a collection. Emits only those messages where "login" is an element of the :actions collection.

  • topic.min(period: 1m), topic.max(period: 1m), topic.mean(period: 1m). Every period time, emits the min, max, or mean of all messages received in that period. If no messages were received, does not emit anything.

  • topic.scale(0.5), topic.add(-20). Multiplies or adds each message by a constant.

  • topic.format('%08.2f'). Applies a C-style printf to each message. Beware that attempting to print a float with %d, or an integer with %f, or really any other sort of type mismatch, will cause rendering to fail.

  • topic.top(10), topic.top(10 performance), topic.top(10 by: performance). Assumes that each received message is a map, and keeps only the top N (as specified) entries, with the N largest values. If the second argument (optionally preceded by by:) is specified, then the values are assumed to be maps, in which the value will be looked up.

  • topic.map(x.y). Assumes that each received message is a sequence, and uses the nested query on each element of the sequence.

  • topic.meta(). Looks up the metadata on each message. Is unlikely to be useful unless we find a reason to put metadata on messages.

  • topic.nonempty-vals(). Assumes that each message is a map, and removes entries whose values are empty.

  • topic.dissoc(x.y.z). Removes a nested field from each message.

  • topic.group-counts(facet, value). Receives a sequence as input, and produces a map from key to number, where facet is a query to group by, and value is a way to obtain a number from an item in the sequence. The value query will be summed across each facet. For example, topic.group-counts(user.type, friends) would convert [{user {type a}, friends 3}, {user {type b} friends 10}, {user {type a} friends 2}] into {a 5, b 10}.

  • topic.nil?(). Returns true if a message is the special value null, and false otherwise.

  • topic.exists?(). The opposite of nil?(): returns true unless the message is null.

  • topic.boolean(). Returns false if a message is either false or null, true otherwise.

  • topic.not(). The opposite of boolean().

Clone this wiki locally