码迷,mamicode.com
首页 > 其他好文 > 详细

CliDriver续

时间:2017-01-17 13:52:04      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:run   是什么   driver   div   out   edm   ast   ini   start   

cliDriver 调用

 processCmd(String cmd) 
public int processCmd(String cmd) {
CliSessionState ss = (CliSessionState) SessionState.get();
ss.setLastCommand(cmd);

ss.updateThreadName();

在这个方法里

 

     try {
        CommandProcessor proc = CommandProcessorFactory.get(tokens, (HiveConf) conf);
        ret = processLocalCmd(cmd, proc, ss);
      } catch (SQLException e) {
        console.printError("Failed processing command " + tokens[0] + " " + e.getLocalizedMessage(),
          org.apache.hadoop.util.StringUtils.stringifyException(e));
        ret = 1;
      }

其中首先看

CommandProcessor  是什么?

public static CommandProcessor get(String[] cmd, HiveConf conf)
      throws SQLException {
    CommandProcessor result = getForHiveCommand(cmd, conf);
    if (result != null) {
      return result;
    }
    if (isBlank(cmd[0])) {
      return null;
    } else {
      if (conf == null) {
        return new Driver();
      }
      Driver drv = mapDrivers.get(conf);
这这里可以判断
Driver
if (drv == null) { drv = new Driver(); mapDrivers.put(conf, drv); } else { drv.resetQueryState(); } drv.init(); return drv; } }

 

processLocalCmd 这个方法
首先判断是否是接口是是否 Driver 如果是调用Driver.run

hive不管CliDirver 所有客户端最终都会调用 Diver.run方法。


  int processLocalCmd(String cmd, CommandProcessor proc, CliSessionState ss) {
    int tryCount = 0;
    boolean needRetry;
    int ret = 0;

    do {
      try {
        needRetry = false;
        if (proc != null) {
          if (proc instanceof Driver) {
            Driver qp = (Driver) proc;
            PrintStream out = ss.out;
            long start = System.currentTimeMillis();
            if (ss.getIsVerbose()) {
              out.println(cmd);
            }

            qp.setTryCount(tryCount);
            ret = qp.run(cmd).getResponseCode();
            if (ret != 0) {
              qp.close();
              return ret;
            }

 

 

CliDriver续

标签:run   是什么   driver   div   out   edm   ast   ini   start   

原文地址:http://www.cnblogs.com/itxuexiwang/p/6292558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!