Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit b06ab37cbfcaad2cb9d301d655e78c3135efc08e @bmuller committed Mar 15, 2012
Showing with 109 additions and 0 deletions.
  1. +10 −0 .gitignore
  2. +15 −0 README.md
  3. +19 −0 project.clj
  4. +58 −0 src/clive/core.clj
  5. +7 −0 test/clive/core_test.clj
@@ -0,0 +1,10 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
@@ -0,0 +1,15 @@
+# clive
+
+I'm an app. Or maybe I'm a library? I haven't decided yet.
+
+The choice is up to you!
+
+## Usage
+
+FIXME
+
+## License
+
+Copyright © 2012 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,19 @@
+(defproject clive "0.1.0-SNAPSHOT"
+ :description "FIXME: write description"
+ :url "http://example.com/FIXME"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :dependencies [[org.clojure/clojure "1.3.0"]
+ [org.apache.hadoop.hive/hive-cli "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-common "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-contrib "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-exec "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-hwi "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-jdbc "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-metastore "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-serde "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-service "0.7.1-cdh3u3"]
+ [org.apache.hadoop.hive/hive-shims "0.7.1-cdh3u3"]
+ ]
+ :repositories {"cloudera" "https://repository.cloudera.com/artifactory/cloudera-repos/"}
+ :main clive.core)
@@ -0,0 +1,58 @@
+(ns clive.core
+ (:import [org.apache.hadoop.hive.service HiveClient]
+ [org.apache.thrift.transport TSocket]
+ [org.apache.thrift.protocol TBinaryProtocol]))
+
+(defonce _connection (atom nil))
+(defonce _socket (atom nil))
+
+(defn hive-socket
+ [host port]
+ (doto (TSocket. host port) .open))
+
+(defn hive-client
+ [socket]
+ (HiveClient. (TBinaryProtocol. socket)))
+
+(defn open
+ [host port]
+ (println "Opening connection")
+ (let [sock (hive-socket host port)]
+ (reset! _connection (hive-client sock))
+ (reset! _socket sock)))
+
+(defn close
+ []
+ (println "Closing connection")
+ (.close @_socket))
+
+(defn fetch-all
+ [q]
+ (.execute @_connection q)
+ (.fetchAll @_connection))
+
+(defmacro openclose
+ [host port & body]
+ `(open host port)
+ `(do ~@body)
+ `(close)
+ )
+
+(defn -main
+ [& args]
+ (openclose "b57" 10000 (println (fetch-all "describe deals_production_people"))))
+
+
+;(defn -main
+; [& args]
+; (connect "b57" 10000)
+; (println (fetch-all "describe deals_production_people"))
+; (disconnect))
+
+;(defn -main
+; [& args]
+; (with-open [sock (hive-socket "b57" 10000)]
+; (let [client (hive-client sock)
+; result (.execute client "describe deals_production_people")]
+; (.fetchAll client))))
+
@@ -0,0 +1,7 @@
+(ns clive.core-test
+ (:use clojure.test
+ clive.core))
+
+(deftest a-test
+ (testing "FIXME, I fail."
+ (is (= 0 1))))

0 comments on commit b06ab37

Please sign in to comment.