Hive源码阅读--作业的提交--executeDriver

run方法最后调用了executeDriver方法,同时传入三个参数:

  • ss hiveconf用户配置
  • conf hiveconf默认配置
  • oproc 用户环境配置
private int executeDriver(CliSessionState ss, HiveConf conf, OptionsProcessor oproc) throws Exception {
		// 1.创建cli对象
        CliDriver cli = new CliDriver();
        // 将 -e 后的参数封装进cli(命令行执行的sql语句)
        cli.setHiveVariables(oproc.getHiveVariables());
        // 将 -database 后的参数封装进cli(数据库选项)
        cli.processSelectDatabase(ss);
        // 将 -i 后的参数封装进,如果未指定则加载.hiverc文件
        cli.processInitFiles(ss);
        // 2.如果hive -e后有参数(sql语句),则执行sql语句
        if (ss.execString != null) {
            int cmdProcessStatus = cli.processLine(ss.execString);
            return cmdProcessStatus;
        } else {
            try {
       // 如果hive -h后有参数(sql脚本文件),则执行脚本文件
                if (ss.fileName != null) {
                    return cli.processFile(ss.fileName);
                }
            } catch (FileNotFoundException var11) {
                System.err.println("Could not open input file for reading. (" + var11.getMessage() + ")");
                return 3;
            }
		// 3.如果是设定了执行引擎是mr,则告警提示
            if ("mr".equals(HiveConf.getVar(conf, ConfVars.HIVE_EXECUTION_ENGINE))) {
                this.console.printInfo(HiveConf.generateMrDeprecationWarning());
            }
		// 初始化控制台用于接收语句
            this.setupConsoleReader();
            int ret = 0;
            String prefix = "";
        // 4.进入默认的库中
            String curDB = getFormattedDb(conf, ss);
            String curPrompt = prompt + curDB;
        // 将字符串替换为空格
            String dbSpaces = spacesForString(curDB);
		// 5.这里是一个while循环,直到遇到分号的时候才执行命令。 
            while(true) {
                while(true) {
                    String line;
                    //  开始从命令行获取sql 语句,如果是以 ; 结尾,则开始执行sql
                    do {
                        if ((line = this.reader.readLine(curPrompt + "> ")) == null) {
                            return ret;
                        }
						// 换行
                        if (!prefix.equals("")) {
                            prefix = prefix + '\n';
                        }
                    
                    } 
                    // 忽略使用 -- 开头的行
                    while(line.trim().startsWith("--"));
					// 判断line是否以分号结尾,同时不以\\;(被注释)结尾
                    if (line.trim().endsWith(";") && !line.trim().endsWith("\\;")) {
                        line = prefix + line;
                        //  提交sql语句,开始执行hive命令
                        ret = cli.processLine(line, true);
                        prefix = "";
                        curDB = getFormattedDb(conf, ss);
                        curPrompt = prompt + curDB;
                        dbSpaces = dbSpaces.length() == curDB.length() ? dbSpaces : spacesForString(curDB);
                    } else {
                        prefix = prefix + line;
                        curPrompt = prompt2 + dbSpaces;
                    }
                }
            }
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寒 暄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值