【问题标题】:Unable to get the hive remote metastore table information over thrift无法通过 thrift 获取配置单元远程元存储表信息
【发布时间】:2015-10-02 17:53:21
【问题描述】:

我可以使用以下程序在我的本地 mysql 元存储设置中获取元存储表信息。

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 MetaStoreTest {

    public static void main(String[] args) throws Exception {

        Connection conn = null;
        try {
            HiveConf conf = new HiveConf();
            conf.addResource(new Path("/home/hadoop/hive-0.12.0/conf/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();
            }
        }

    }
}

目前正在尝试使用上述程序从远程元存储中获取元存储表。在我当前的 hive-site.xml 中,我有这些参数,

hive.metastore.uris = thrift://host1:9083, thrift://host2:9083
hive.metastore.local = false

没有参数:

javax.jdo.option.ConnectionDriverName, javax.jdo.option.ConnectionUserName, javax.jdo.option.ConnectionPassword

那么,我如何通过 thrift 协议获取元表信息。我在host2上运行上面的代码。请提出建议。

当我运行上面的代码时,它会显示以下信息:

METASTORE_CONNECTION_DRIVER as derby connection embedded driver, 
METASTORECONNECTURLKEY as jdbc:mysql://<host name>/<database name>?createDatabaseIfNotExist=true, 
METASTORE_CONNECTION_USER_NAME as "APP" and 
METASTOREPWD as "mine"

【问题讨论】:

  • 您似乎有些不匹配:您的连接 URL 是 MySQL 模式,但您已指定 Derby JDBC 驱动程序。这两个可能不会很好地结合在一起。

标签: mysql hadoop hive derby thrift


【解决方案1】:

替换这部分代码

conf.addResource(new Path("/home/hadoop/hive-0.12.0/conf/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));

如下

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://host2:3306/metastore", "urusername", "urpassword");

[注意:根据您的设置相应地更改元存储数据库名称、用户和密码。]

现在

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("show tables");
while (rs.next()) {
   System.out.println("Tables:" +rs.getString(1));
}

看看你是否得到了元存储表名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多