hive 源码学习一 -hive入口

昨天和师兄混了一天,中午还一起做了个饭,下午来我这游泳,晚上dota到深夜,挺hi的,谈了很多关于心态的,很久没这么沟通了
周日把hive wiki差不都看完了,hivesql也很久了,一直没有时间去看下hive源码,才把源码checkout下来,导入eclipse,找到clidriver,入口了,明天继续阅读,对了,checkout出来的项目是ant的,eclipse导入需要手动配置 .classpath .projece2个文件,内容如下:
.project
<?xml version="1.0" encoding="UTF-8"?> 
<projectDescription> 
<name>hivesource<项目名></name> 
<comment></comment> 
<projects> 
</projects> 
<buildSpec> 
  <buildCommand> 
   <name>org.eclipse.jdt.core.javabuilder</name> 
   <arguments> 
   </arguments> 
  </buildCommand> 
</buildSpec> 
<natures> 
  <nature>org.eclipse.jdt.core.javanature</nature> 
</natures> 
</projectDescription>


.classpath
<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry kind="src" path="src"/> 
    <classpathentry kind="src" path="othersrc"/> 
       <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 
    <!--<classpathentry kind="lib" path="lib/dom4j.jar"/>--> 
    <classpathentry kind="output" path="classes"/> 
</classpath> 

总结:夫祸患常积于忽微 而智勇多困于所溺,有点跑题,没事反正收视率也不高,我一个人知道就好了
言归正传,下载下来找到cli目录,如下图有5个类,有的版本是4个,打开主类cliDriver

——————CliDriver类——————————
主类中有主要的几个方法,当然main是入口,下图是引用别人画的

其中maim方法会把参数传给run()
run中会用到OptionsProcessor.process_stage1(args) 根据传入的参数进行一些初始话
commandLine = new GnuParser().parse(options, argv);
      Properties confProps = commandLine.getOptionProperties("hiveconf");
      for (String propKey : confProps.stringPropertyNames()) {
        System.setProperty(propKey, confProps.getProperty(propKey));
      }

      Properties hiveVars = commandLine.getOptionProperties("define");
      for (String propKey : hiveVars.stringPropertyNames()) {
        hiveVariables.put(propKey, hiveVars.getProperty(propKey));
      }

      Properties hiveVars2 = commandLine.getOptionProperties("hivevar");
      for (String propKey : hiveVars2.stringPropertyNames()) {
        hiveVariables.put(propKey, hiveVars2.getProperty(propKey));
      }

如果返回false则直接结束,返回1,也就是我们经常看到的报错信息,return code 1
类似过程还有
!oproc.process_stage2(ss) 传入session //貌似是将sql中的一些配置参数解析然后存入session

—————————— processLine(Cmd)
run中继续调用processLine(cmd)
循环解析cmd 以‘;’作为分隔符,传入processCmd(cmd)
// 读入cmd:‘;’之前的所有字符串都读入(不做任何检查),之后的都会忽略。读完后,传入processCmd处理
—————————— processCmd()
/– 读入cmd,并分情况处理,总共分为以下五种情况,根据命令的开头字符串来确定用什么方法处理。
// 1.set.. 设置operator参数,hive环境参数
// 2.quit or exit — 退出Hive环境
// 3.! 开头
// 4.dfs 开头 交给FsShell处理
// 5.hivesql 正常hivesql执行语句,我们最关心的是这里。语句交给了、、Hive真正的核心引
核心语句:ret = qp.run(cmd).getResponseCode(); qp是Driver对象

———————CliSessionState.java—————————————



执行计划:
http://blog.csdn.net/wf1982/article/details/9122543

猜你喜欢

转载自songpo-ath-taobao-com.iteye.com/blog/1573353