首先定义接口
工具类
/**
* sql查询的基类
* @author taoxinwan
*
*/
public abstract class QueryBase {
protected static final Logger log = Logger.getLogger(QueryBase.class);
//ip
protected static String host;
//端口
protected static int port;
//类型
protected static int type;
protected static String username;
protected static String passsword;
/**
* 初始化上下文信息
* @param context
*/
protected void init(Context context){
host = context.getHost();
port = context.getPort();
type = context.getType();
username = context.getUsername();
passsword = context.getPasssword();
}
public abstract TOperationHandle submitQuery(String command) throws Exception;
public abstract String getQueryLog(TOperationHandle tOperationHandle) throws Exception;
public abstract TOperationState getQueryHandleStatus(TOperationHandle tOperationHandle) throws Exception;
public abstract Map<String, Object> getResultByOperation(TOperationHandle tOperationHandle) throws Exception;
public abstract void cancelQuery(TOperationHandle tOperationHandle) throws Exception;
}
工具类
/**
* 获取shrift client
*
* @param transport
* @param type
* 1=hive,2=impala
* @return
* @throws TTransportException
*/
public static TCLIService.Client getClientInstance(TTransport transport, int type) throws TTransportException {
TCLIService.Client client = null;
if (1 == type) {// hive
client = new TCLIServic