Skip to content

Instantly share code, notes, and snippets.

@bnyeggen
Created December 13, 2011 15:12
Show Gist options
  • Save bnyeggen/1472470 to your computer and use it in GitHub Desktop.
Save bnyeggen/1472470 to your computer and use it in GitHub Desktop.
Clojure to Hive via JDBC
(comment Add [org.clojure/java.jdbc "0.1.1"] to project dependencies)
(ns myproject.core
(:use [clojure.java.jdbc :only [with-connection, with-query-results]]))
(let [db-host "MyHost"
db-port 10000
db-name "default"]
(def db {:classname "org.apache.hadoop.hive.jdbc.HiveDriver" ; must be in classpath
:subname (str "//" db-host ":" db-port "/" db-name)
:subprotocol "hive"}))
(with-connection db
(with-query-results rs ["select * from people"]
(dorun (map #(println (:name %)) rs))))
@belablotski
Copy link

Thanks a lot.
For HiveServer2:

(def hive-db {:subprotocol "hive2"
          :classname "org.apache.hive.jdbc.HiveDriver"
              :subname "//hiveserver2:10001"
              :user ""
              :password ""})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment