hive1.2.1与Hadoop2.6.0搭建的环境,hive thrift连接执行命令无结果,10000端口不能用

lijie_198871 2015-07-14 09:35:59
如题 ,使用hive1.2.1版本和Hadoop2.6.0搭建的环境,现在的问题是这样的:

try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
Connection con = DriverManager.getConnection("jdbc:hive2://hadoop.master:10000/default","hadoop","hadoop");
Statement sta = con.createStatement();
ResultSet result = sta.executeQuery("select * from test");
while(result.next()){

System.out.println(result.getString(1));
}
con.close();
} catch(SQLException e) {
e.printStackTrace();
}

可以正常返回结果:

15/07/14 09:26:35 INFO jdbc.Utils: Supplied authorities: hadoop.master:10000
15/07/14 09:26:35 INFO jdbc.Utils: Resolved authority: hadoop.master:10000
15/07/14 09:26:35 INFO jdbc.HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2://hadoop.master:10000/default
1
1


使用这种方式连接hive编程,也可以正常返回结果,注意端口号不是10000

TTransport transport = null;
try {
// transport = new TSocket("172.199.10.3", 9083);
transport = new TSocket("192.168.159.128", 9083);

// 指定通信协议为二进制流协议
TProtocol protocol = new TBinaryProtocol(transport);

System.out.println("开始");
try {
transport.open();
System.out.println(transport.isOpen());
} catch (TTransportException e) {
throw new SQLException("Could not establish connecton to: "
+ e.getMessage(), "08S01");
}

ThriftHive.Client client = new ThriftHive.Client(protocol);
List<String> dbs = client.get_all_databases();

for (String db : dbs) {
System.out.println("数据库:" + db);
List<String> tbs = client.get_all_tables(db);

for (String t : tbs) {
System.out.println(" 表:" + t);

List<FieldSchema> fields = client.get_fields(db, t);
for (FieldSchema f : fields) {
System.out.println(" 字段:" + f.getName());
}
}
}
} catch (Exception x) {
x.printStackTrace();
} finally {
if (null != transport) {
try {
transport.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}


结果如下:

开始
true
数据库:default
表:test
字段:id
表:test2
字段:id
表:test3
字段:id
表:test8
字段:id


把上面的端口号改为 10000,就有问题了,一直无结果返回,也无异常,一直停留在

List<String> dbs = client.get_all_databases();

一直不动,也不报超时的异常


下面这个情况更离奇,使用9083端口,报了一个找不到方法的异常,代码如下:

TTransport transport = null;
try {
// transport = new TSocket("172.199.10.3", 9083);
transport = new TSocket("192.168.159.128", 9083);

// 指定通信协议为二进制流协议
TProtocol protocol = new TBinaryProtocol(transport);

System.out.println("开始");
try {
transport.open();
System.out.println(transport.isOpen());
} catch (TTransportException e) {
throw new SQLException("Could not establish connecton to: "
+ e.getMessage(), "08S01");
}

ThriftHive.Client client = new ThriftHive.Client(protocol);
client.execute("use default");
client.execute("show tables");
List<String> list = client.fetchAll();
for (String l : list) {
System.out.println(l);
}
System.out.println("OK");

} catch (Exception x) {
x.printStackTrace();
} finally {
if (null != transport) {
try {
transport.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}


异常:

开始
true
org.apache.thrift.TApplicationException: Invalid method name: 'execute'
at org.apache.thrift.TApplicationException.read(TApplicationException.java:111)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:71)
at org.apache.hadoop.hive.service.ThriftHive$Client.recv_execute(ThriftHive.java:116)
at org.apache.hadoop.hive.service.ThriftHive$Client.execute(ThriftHive.java:103)
at hiveDemo.testHiveClient.main(testHiveClient.java:49)



如果把端口号改为10000,就变成了一直停留在 client.execute("use default"); 的状态,和上面的现象一样,不结束也不抛异常。


求大神帮忙解决,是我配置文件的问题还是新版本的问题,还是jar包的问题?


...全文
4572 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jia1986119 2018-12-07
  • 打赏
  • 举报
回复
<dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-service</artifactId> <version>1.1.0</version> </dependency>
五哥 2018-07-25
  • 打赏
  • 举报
回复
我用的是cdh版本的thrift
private static TCLIService.Client client;
碧水幽幽泉 2017-09-15
  • 打赏
  • 举报
回复
刚刚整理的,借贴发下。
碧水幽幽泉 2017-09-15
  • 打赏
  • 举报
回复
--Hive中日期函数总结:
--1.时间戳函数
--日期转时间戳
select unix_timestamp(); --获得当前时区的UNIX时间戳
select unix_timestamp('2017-09-15 14:23:00');
select unix_timestamp('2017-09-15 14:23:00','yyyy-MM-dd HH:mm:ss');
select unix_timestamp('20170915 14:23:00','yyyyMMdd HH:mm:ss');
--时间戳转日期:从1970-01-01 00:00:00 UTC到指定时间的秒数
select from_unixtime(1505456567);
select from_unixtime(1505456567,'yyyyMMdd');
select from_unixtime(1505456567,'yyyy-MM-dd HH:mm:ss');
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'); --获取系统当前时间

--2.获取当前日期: current_date
hive> select current_date from dual
2017-09-15

--3.日期时间转日期:to_date(string timestamp)
hive> select to_date('2017-09-15 11:12:00') from dual;
2017-09-15

--3.获取日期中的年/月/日/时/分/秒/周
with dtime as(select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') as dt)
select year(dt),month(dt),day(dt),hour(dt),minute(dt),second(dt),weekofyear(dt)
from dtime

--4.计算两个日期之间的天数: datediff
hive> select datediff('2017-09-15','2017-09-01') from dual;
14

--5.日期增加和减少: date_add/date_sub(string startdate,int days)
hive> select date_add('2017-09-15',1) from dual;
2017-09-16
hive> select date_sub('2017-09-15',1) from dual;
2017-09-14
--其他日期函数
查询当前系统时间(包括毫秒数): current_timestamp;
查询当月第几天: dayofmonth(current_date);
月末: last_day(current_date)
当月第1天: date_sub(current_date,dayofmonth(current_date)-1)
下个月第1天: add_months(date_sub(current_date,dayofmonth(current_date)-1),1)
Honxs_xu 2017-07-01
  • 打赏
  • 举报
回复
解决了吗?。。。
sijifeng11 2016-03-28
  • 打赏
  • 举报
回复
也遇到了这个问题 楼主解决了吗
沧海_Sea 2016-02-03
  • 打赏
  • 举报
回复
hive 的bin 目录下有个 beeline的工具 你用这个试试能连上不
tutvppp 2016-02-02
  • 打赏
  • 举报
回复
我也遇到这样的问题 楼主解决了么
lijie_198871 2015-07-17
  • 打赏
  • 举报
回复
为什么没人回复一下呢

20,808

社区成员

发帖
与我相关
我的任务
社区描述
Hadoop生态大数据交流社区,致力于有Hadoop,hive,Spark,Hbase,Flink,ClickHouse,Kafka,数据仓库,大数据集群运维技术分享和交流等。致力于收集优质的博客
社区管理员
  • 分布式计算/Hadoop社区
  • 涤生大数据
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧