Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (ns tester.namespace
  2.   (:use cascalog.api
  3.         [clojure.string :only (join)])
  4.   (:require [cascalog.ops :as c])
  5.   (:import [org.apache.hadoop.io.serializer JavaSerialization]))  
  6.  
  7. (defmacro with-serializations
  8.   [serial-vec & forms]
  9.   `(with-job-conf
  10.      {"io.serializations"
  11.       ~(->> serial-vec
  12.             (map #(if (string? %) % (.getName (resolve %))))
  13.             (concat ["cascading.tuple.hadoop.BytesSerialization"
  14.                      "cascading.tuple.hadoop.TupleSerialization"
  15.                      "org.apache.hadoop.io.serializer.WritableSerialization"])
  16.             (join ","))}
  17.      ~@forms))
  18.  
  19. (defn count-if-something-init
  20.   [[word tester]]
  21.   (if (= tester word) 1 0))
  22.  
  23. (defparallelagg count-if-something*
  24.   :init-var #'count-if-something-init
  25.   :combine-var #'+)
  26.  
  27. (defn vectorize [& tuple] [tuple])
  28.  
  29. (defn count-if-something [word]
  30.  (<- [?word :> ?count]
  31.    (vectorize ?word word :> ?v)
  32.    (count-if-something* ?v :> ?count)))
  33.  
  34. (with-serializations [JavaSerialization]
  35.   (?<- (stdout) [?count]
  36.        ([["awesome"] ["aaa"] ["awesome"] ["bbb"]] ?word)
  37.        ((count-if-something "awesome") ?word :> ?count)))