摘要:启动作用执行命令时实际上运行的类是。入口解析命令行参数,把的参数设置到环境变量,吧,和等参数添加到一个中初始化日志组件初始化,并根据实例化,设置输入输出流为标准控制台。
hive Cli 启动
[toc]
CliDriver作用: 执行命令:hive时 实际上运行的类是org.apache.hadoop.hive.cli.CliDriver.java 。
入口public static void main(String[] args) throws Exception { int ret = new CliDriver().run(args); System.exit(ret); } public int run(String[] args) throws Exception { //解析命令行参数, 把hiveconf 的参数设置到环境变量,吧define,和hivevar等参数添加到一个map中 OptionsProcessor oproc = new OptionsProcessor(); if (!oproc.process_stage1(args)) { return 1; } //初始化Log4j日志组件 // NOTE: It is critical to do this here so that log4j is reinitialized // before any of the other core hive classes are loaded boolean logInitFailed = false; String logInitDetailMessage; try { logInitDetailMessage = LogUtils.initHiveLog4j(); } catch (LogInitializationException e) { logInitFailed = true; logInitDetailMessage = e.getMessage(); } //初始化HiveConf,并根据HiveConf实例化CliSessionState,设置输入输出流为标准控制台。 //CliSessionState 继承了SessionState类, //创建了一些记录用户输入的字符串,在实例化的过程中,主要是用来记录HiveConf,并生成一个会话ID,参见SessionState构造函数. CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class)); //设置ss的输入,输出,把对ss的和hive cli的关联起来 ss.in = System.in; try { ss.out = new PrintStream(System.out, true, "UTF-8"); ss.info = new PrintStream(System.err, true, "UTF-8"); ss.err = new CachingPrintStream(System.err, true, "UTF-8"); } catch (UnsupportedEncodingException e) { return 3; } //根据stage1解析的参数内容,填充CliSessionState的字符串,比如用户输入了-e 则这个stage就把-e 对应的字符串赋值给CliSessionState的 execString成员。 // -S 表示 沉默状态 // -e 获取执行sql // -f 获取要执行的sql文件 // -v 是否详细显示 // 其他, 处理hiveconf 和 i 等参数 if (!oproc.process_stage2(ss)) { return 2; } //在允许打印输出的模式下,如果日志初始化失败,打印失败信息 if (!ss.getIsSilent()) { if (logInitFailed) { System.err.println(logInitDetailMessage); } else { SessionState.getConsole().printInfo(logInitDetailMessage); } } //将用户命令行输入的配置信息和变量等,覆盖HiveConf的默认值 // set all properties specified via command line HiveConf conf = ss.getConf(); for (Map.Entry初始化cli命令
private int executeDriver(CliSessionState ss, HiveConf conf, OptionsProcessor oproc) throws Exception { CliDriver cli = new CliDriver(); cli.setHiveVariables(oproc.getHiveVariables()); //设置使用的数据库 // use the specified database if specified cli.processSelectDatabase(ss); // Execute -i init files (always in silent mode) cli.processInitFiles(ss); //如果传递了要执行的sql 执行后退出 if (ss.execString != null) { int cmdProcessStatus = cli.processLine(ss.execString); return cmdProcessStatus; } //执行sql文件 try { if (ss.fileName != null) { return cli.processFile(ss.fileName); } } catch (FileNotFoundException e) { System.err.println("Could not open input file for reading. (" + e.getMessage() + ")"); return 3; } //获取命令行的reader ConsoleReader reader = getConsoleReader(); reader.setExpandEvents(false); reader.setBellEnabled(false); // reader.setDebug(new PrintWriter(new FileWriter("writer.debug", true))); for (Completer completer : getCommandCompleter()) { reader.addCompleter(completer); } //略去一部分不重要代码 int ret = 0; String prefix = ""; String curDB = getFormattedDb(conf, ss); String curPrompt = prompt + curDB; String dbSpaces = spacesForString(curDB); //开始从命令行获取sql 语句,如果是以 ; 结尾,则开始执行sql while ((line = reader.readLine(curPrompt + "> ")) != null) { if (!prefix.equals("")) { prefix += " "; } if (line.trim().endsWith(";") && !line.trim().endsWith(";")) { line = prefix + line; //开始执行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; continue; } } if (history != null) { history.flush(); } return ret; }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/69923.html
摘要:启动作用执行命令时实际上运行的类是。入口解析命令行参数,把的参数设置到环境变量,吧,和等参数添加到一个中初始化日志组件初始化,并根据实例化,设置输入输出流为标准控制台。 hive Cli 启动 [toc] CliDriver 作用: 执行命令:hive时 实际上运行的类是org.apache.hadoop.hive.cli.CliDriver.java 。 入口 public ...
摘要:跟踪每个的活动情况并协调查询语句的执行。是负责执行任务和处理数据。是负责从获取结果并返回最终结果给。例如,一个表的权限定名是,则是表名,是,是。运行启动命令日志在目录下记录服务初始化情况和一些的诊断。 Presto简介 不是什么 虽然Presto可以解析SQL,但它不是一个标准的数据库。不是MySQL、PostgreSQL或者Oracle的代替品,也不能用来处理在线事务(OLTP) 是...
摘要:看一个用例场景大量的数据存储在关系数据库管理系统环境中。当数据集越来越大时,关系数据库管理系统表现不佳。可在几分钟内部署集群。像其他服务一样,服务可以通过强大的和仪表板进行管理。编排即服务用于配置和编排数据处理集群的部署。 OpenStack 控制计算、存储和网络资源池。本文主要关注 OpenStack 如何在大数据用例中扮演关键角色。OpenStack 上的大数据现在,数据随处生成,数据量...
阅读 3112·2023-04-25 19:42
阅读 1116·2021-11-23 10:11
阅读 1860·2021-11-16 11:51
阅读 2301·2021-10-09 09:41
阅读 1791·2021-09-28 09:35
阅读 1442·2019-08-30 15:54
阅读 1926·2019-08-29 18:44
阅读 1490·2019-08-23 18:24