Created
July 26, 2016 18:01
-
-
Save aaronsteers/08fb66815eff56d53675e4016211fc96 to your computer and use it in GitHub Desktop.
query the hive metastore from http://stackoverflow.com/a/21141578/4298208
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
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.ResultSet; | |
import java.sql.Statement; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.hive.conf.HiveConf; | |
import org.apache.hadoop.hive.conf.HiveConf.ConfVars; | |
public class HiveMetastoreJDBCTest { | |
public static void main(String[] args) throws Exception { | |
Connection conn = null; | |
try { | |
HiveConf conf = new HiveConf(); | |
conf.addResource(new Path("file:///path/to/hive-site.xml")); | |
Class.forName(conf.getVar(ConfVars.METASTORE_CONNECTION_DRIVER)); | |
conn = DriverManager.getConnection( | |
conf.getVar(ConfVars.METASTORECONNECTURLKEY), | |
conf.getVar(ConfVars.METASTORE_CONNECTION_USER_NAME), | |
conf.getVar(ConfVars.METASTOREPWD)); | |
Statement st = conn.createStatement(); | |
ResultSet rs = st.executeQuery( | |
"select t.tbl_name, s.location from tbls t " + | |
"join sds s on t.sd_id = s.sd_id"); | |
while (rs.next()) { | |
System.out.println(rs.getString(1) + " : " + rs.getString(2)); | |
} | |
} | |
finally { | |
if (conn != null) { | |
conn.close(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment