通过Thrift 方式访问 Hive

 

package com.netqin.hive.kpi;

import org.apache.hadoop.hive.service.HiveClient;
import org.apache.hadoop.hive.service.HiveServerException;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

public class AndroidKpi {
	
	// Thrift Server IP Address
	private static String HOST = "192.168.0.59";
	// Thrift Server Port
	private static int PORT = 10000;
	public static final Logger logger = Logger.getLogger(AndroidKpi.class); // logger
	
    public static void main(String[] args) {
    	
    	   TTransport transport  = new TSocket(HOST, PORT);
           TProtocol protocol = new TBinaryProtocol(transport);
           HiveClient client = new HiveClient(protocol);
           String tableName = "tableName";
           try {
			transport.open();
			// Execute Hive Query Language Command
			client.execute("select count(*) from "+tableName);
			System.out.println(client.fetchOne());
			//logger.debug("size "+client.fetchOne());
		} catch (TTransportException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		} catch (HiveServerException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		} catch (TException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
    }

}


运行以上的程序所必需的Jar包:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值