Skip to content

Instantly share code, notes, and snippets.

@sorenmacbeth
Created May 15, 2013 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorenmacbeth/5587982 to your computer and use it in GitHub Desktop.
Save sorenmacbeth/5587982 to your computer and use it in GitHub Desktop.
(defn cascalog-map
[op-var output-fields & {:keys [stateful?]}]
(let [ser (ops/fn-spec op-var)]
(proxy [BaseOperation Function] [^Fields output-fields]
(prepare [^FlowProcess flow-process ^OperationCall op-call]
(let [op (serfn/deserialize-val ser)]
(-> op-call
(.setContext [op (if stateful? (op))]))))
(operate [^FlowProcess flow-process ^FunctionCall fn-call]
(let [[op] (.getContext fn-call)
collector (-> fn-call .getOutputCollector)
^Tuple tuple (-> fn-call .getArguments .getTuple)]
(->> (Util/coerceFromTuple tuple)
(apply op)
(Util/coerceToTuple)
(.add collector))))
(cleanup [flow-process ^OperationCall op-call]
(if stateful?
(let [[op state] (.getContext op-call)]
(op state)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment