Created
December 13, 2011 15:28
-
-
Save bnyeggen/1472525 to your computer and use it in GitHub Desktop.
Clojure to Hive via Thrift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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