Skip to content

Instantly share code, notes, and snippets.

@bnyeggen
Created December 13, 2011 15:28
Show Gist options
  • Save bnyeggen/1472525 to your computer and use it in GitHub Desktop.
Save bnyeggen/1472525 to your computer and use it in GitHub Desktop.
Clojure to Hive via Thrift
(comment You will want just about everything in your hive/lib dir included in your Classpath)
(ns myproj.core
(:import [org.apache.hadoop.hive.service HiveClient]
[org.apache.thrift.transport TSocket]
[org.apache.thrift.protocol TBinaryProtocol]))
(defn send-hive
"Creates a new socket and Hive client connection, runs the query, pulls the result, and closes the connection.
Eventually modify to split and parse according to schema of result.
This should usually be wrapped in a future/used to populate a promise."
[query]
(with-open [sock (doto (TSocket. "MyHost" 10000) .open)]
(let [hive (doto (HiveClient. (TBinaryProtocol. sock)) (.execute query))]
(.fetchAll hive))))
(send-hive "select name from people")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment