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包: