安装 hive后 在命令行 如输入 Hive -h

-后面随便输入。让让他报错进入命令提示界面

-d 定义一个变量 两种形式

-d A=B or --define A=B

-e 执行sql语句  hive -e "select * from a"

-f 执行一个sql片段。或者包含sql语句的文本文件

-i  初始化 sql文件。或者包含sql语句的文本文件

[cloudera@quickstart Desktop]$ hive -i
Missing argument for option: i
usage: hive
-d,--define <key=value> Variable subsitution to apply to hive
commands. e.g. -d A=B or --define A=B
--database <databasename> Specify the database to use
-e <quoted-query-string> SQL from command line
-f <filename> SQL from files
-H,--help Print help information
--hiveconf <property=value> Use value for given property
--hivevar <key=value> Variable subsitution to apply to hive
commands. e.g. --hivevar A=B
-i <filename> Initialization SQL file
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the
console)

-hiveconf mapred.reduce.tasks=32 修改hive/conf 配置文件默认的值

下面对于的源代码,看是不是很熟悉。

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package org.apache.hadoop.hive.cli; import java.util.HashMap;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties; import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.hadoop.hive.common.cli.CommonCliOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; /**
* OptionsProcessor.
*
*/
public class OptionsProcessor {
protected static final Logger l4j = LoggerFactory.getLogger(OptionsProcessor.class.getName());
private final Options options = new Options();
private org.apache.commons.cli.CommandLine commandLine;
Map<String, String> hiveVariables = new HashMap<String, String>(); @SuppressWarnings("static-access")
public OptionsProcessor() { // -database database
options.addOption(OptionBuilder
.hasArg()
.withArgName("databasename")
.withLongOpt("database")
.withDescription("Specify the database to use")
.create()); // -e 'quoted-query-string'
options.addOption(OptionBuilder
.hasArg()
.withArgName("quoted-query-string")
.withDescription("SQL from command line")
.create('e')); // -f <query-file>
options.addOption(OptionBuilder
.hasArg()
.withArgName("filename")
.withDescription("SQL from files")
.create('f')); // -i <init-query-file>
options.addOption(OptionBuilder
.hasArg()
.withArgName("filename")
.withDescription("Initialization SQL file")
.create('i')); // -hiveconf x=y
options.addOption(OptionBuilder
.withValueSeparator()
.hasArgs(2)
.withArgName("property=value")
.withLongOpt("hiveconf")
.withDescription("Use value for given property")
.create()); // Substitution option -d, --define
options.addOption(OptionBuilder
.withValueSeparator()
.hasArgs(2)
.withArgName("key=value")
.withLongOpt("define")
.withDescription("Variable substitution to apply to Hive commands. e.g. -d A=B or --define A=B")
.create('d')); // Substitution option --hivevar
options.addOption(OptionBuilder
.withValueSeparator()
.hasArgs(2)
.withArgName("key=value")
.withLongOpt("hivevar")
.withDescription("Variable substitution to apply to Hive commands. e.g. --hivevar A=B")
.create()); // [-S|--silent]
options.addOption(new Option("S", "silent", false, "Silent mode in interactive shell")); // [-v|--verbose]
options.addOption(new Option("v", "verbose", false, "Verbose mode (echo executed SQL to the console)")); // [-H|--help]
options.addOption(new Option("H", "help", false, "Print help information")); } public boolean process_stage1(String[] argv) {
try {
commandLine = new GnuParser().parse(options, argv);
Properties confProps = commandLine.getOptionProperties("hiveconf");
for (String propKey : confProps.stringPropertyNames()) {
// with HIVE-11304, hive.root.logger cannot have both logger name and log level.
// if we still see it, split logger and level separately for hive.root.logger
// and hive.log.level respectively
if (propKey.equalsIgnoreCase("hive.root.logger")) {
CommonCliOptions.splitAndSetLogger(propKey, confProps);
} else {
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));
}
} catch (ParseException e) {
System.err.println(e.getMessage());
printUsage();
return false;
}
return true;
} public boolean process_stage2(CliSessionState ss) {
ss.getConf(); if (commandLine.hasOption('H')) {
printUsage();
return false;
} ss.setIsSilent(commandLine.hasOption('S')); ss.database = commandLine.getOptionValue("database"); ss.execString = commandLine.getOptionValue('e'); ss.fileName = commandLine.getOptionValue('f'); ss.setIsVerbose(commandLine.hasOption('v')); String[] initFiles = commandLine.getOptionValues('i');
if (null != initFiles) {
ss.initFiles = Arrays.asList(initFiles);
} if (ss.execString != null && ss.fileName != null) {
System.err.println("The '-e' and '-f' options cannot be specified simultaneously");
printUsage();
return false;
} if (commandLine.hasOption("hiveconf")) {
Properties confProps = commandLine.getOptionProperties("hiveconf");
for (String propKey : confProps.stringPropertyNames()) {
ss.cmdProperties.setProperty(propKey, confProps.getProperty(propKey));
}
} return true;
} private void printUsage() {
new HelpFormatter().printHelp("hive", options);
} public Map<String, String> getHiveVariables() {
return hiveVariables;
}
}
hasArg()方法
  public static OptionBuilder hasArg()
{
OptionBuilder.numberOfArgs = 1; return INSTANCE;
}
    public static Option create(String opt) throws IllegalArgumentException
{
Option option = null;
try
{
// create the option
option = new Option(opt, description); // set the option properties
option.setLongOpt(longopt);
option.setRequired(required);
option.setOptionalArg(optionalArg);
option.setArgs(numberOfArgs);
option.setType(type);
option.setValueSeparator(valuesep);
option.setArgName(argName);
}
finally
{
// reset the OptionBuilder properties
OptionBuilder.reset();
} // return the Option instance
return option;
}

  最终一下面形式存储

 */
public class Option implements Cloneable, Serializable
{
/** constant that specifies the number of argument values has not been specified */
public static final int UNINITIALIZED = -1; /** constant that specifies the number of argument values is infinite */
public static final int UNLIMITED_VALUES = -2; /** The serial version UID. */
private static final long serialVersionUID = 1L; /** the name of the option */
private final String opt; /** the long representation of the option */
private String longOpt; /** the name of the argument for this option */
private String argName; /** description of the option */
private String description; /** specifies whether this option is required to be present */
private boolean required; /** specifies whether the argument value of this Option is optional */
private boolean optionalArg; /** the number of argument values this option can have */
private int numberOfArgs = UNINITIALIZED; /** the type of this Option */
private Class<?> type = String.class; /** the list of argument values **/
private List<String> values = new ArrayList<String>(); /** the character that is the value separator */
private char valuesep; /**
* Private constructor used by the nested Builder class.
*
* @param builder builder used to create this option
*/
private Option(final Builder builder)
{
this.argName = builder.argName;
this.description = builder.description;
this.longOpt = builder.longOpt;
this.numberOfArgs = builder.numberOfArgs;
this.opt = builder.opt;
this.optionalArg = builder.optionalArg;
this.required = builder.required;
this.type = builder.type;
this.valuesep = builder.valuesep;
}

  

.hive命令的3种调用方式 以及源码的更多相关文章

  1. hive命令的3种调用方式

    方式1:hive –f  /root/shell/hive-script.sql(适合多语句) hive-script.sql类似于script一样,直接写查询命令就行 例如: [root@cloud ...

  2. hive命令的三种执行方式

    hive命令的3种调用方式 方式1:hive –f  /root/shell/hive-script.sql(适合多语句) hive-script.sql类似于script一样,直接写查询命令就行 不 ...

  3. 2018.11.20 Struts2中对结果处理方式分析&struts2内置的方式底层源码剖析

    介绍一下struts2内置帮我们封装好的处理结果方式也就是底层源码分析 这是我们的jar包里面找的位置目录 打开往下拉看到result-type节点 name那一列就是我们的type类型取值 上一篇博 ...

  4. 【转载】Redis的Java客户端Jedis的八种调用方式(事务、管道、分布式…)介绍

    转载地址:http://blog.csdn.net/truong/article/details/46711045 关键字:Redis的Java客户端Jedis的八种调用方式(事务.管道.分布式…)介 ...

  5. 【转】SVG与HTML、JavaScript的三种调用方式

    原文:https://www.cnblogs.com/guohu/p/5085045.html SVG与HTML.JavaScript的三种调用方式 一.在HTMl中访问SVG的DOM 1 2 3 4 ...

  6. 同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调用方式

    1. 概念理解        在进行网络编程时,我们常常见到同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调用方式:   同步/异步主要针对C端: 同步:    ...

  7. 线程系列1--Java创建线程的几种方式及源码分析

    线程--创建线程的几种方式及源码分析 开始整理下线程的知识,感觉这块一直是盲区,工作中这些东西一直没有实际使用过,感觉也只是停留在初步的认识.前段时间一个内推的面试被问到,感觉一脸懵逼.面试官说,我的 ...

  8. android Service Activity三种交互方式(付源码)(转)

    android Service Activity三种交互方式(付源码) Android应用服务器OSBeanthread  android Service Binder交互通信实例 最下边有源代码: ...

  9. Java的三种代理模式&完整源码分析

    Java的三种代理模式&完整源码分析 参考资料: 博客园-Java的三种代理模式 简书-JDK动态代理-超详细源码分析 [博客园-WeakCache缓存的实现机制](https://www.c ...

随机推荐

  1. FileFilter与FilenameFilter实例

    下面的例子中我们创建了一个FileFilter类,此类根据文件名的扩展名是否为.txt来筛选文件.创建FileFilter实例之后需要将此实例作为参数传给File的listFiles(fileFilt ...

  2. PAT (Advanced Level) 1061. Dating (20)

    简单模拟. #include<stdio.h> #include<string.h> ],s2[],s3[],s4[]; ][]={"MON ", &quo ...

  3. localStorage、sessionStorages 使用

    html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage.sessionStorage用于本地存储一个会话(session)中的数据,这些数据只有 ...

  4. Android网络开发之OkHttp--基本用法实例化各个对象

    1.实例化OkHttpClient对象,OkHttpClient包含了以下属性,以及set()和get()方法.但并没有包含具体的执行方法,详情见源码. //实例化OkHttpClent对象 priv ...

  5. postgres 数据库命令行客户端psql的使用命令总结

    1.切换到 postgres 用户: 2.输入: psql , 进入到postgresql的客户端psql: 3.\l           查看当前所有的数据库: 4.psql database1   ...

  6. 我对hibernate的对象的3种状态的理解

    老师的说法 Hibernate中对象的状态    在Hibernate使用中,对象的状态有以下三种    a.临时对象 : 在程序中使用new方式创建的对象    b.持久对象 : 在程序中与sess ...

  7. 路过Haxe

    刚才在看Nape的时候,看到Haxe的代码,意外的感觉到亲切. 因为之前写过as2代码,最近学习了python,所以对haxe看起来很亲切,于是路过一下写了个HelloWorld. 另外,估计很长时间 ...

  8. ReactiveNative学习之Diff算法

    React 源码剖析系列 - 不可思议的 react diff深入浅出React(四):虚拟DOM Diff算法解析React diff 算法总结链接引用的文章React出于性能的考虑,为了避免频繁操 ...

  9. Tengine TCP 负载均衡

    tar jxvf jemalloc-3.5.1.tar.bz2 cd jemalloc-3.5.1 ./configure make && make install echo '/us ...

  10. 程序ajax请求公共组件app-jquery-http.js中url参数部分的项目应用

    结合微信登录以及微信支付的案例:= =||| (案例比较奇葩复杂) 简述项目流程: 1.获取用于公众号支付的openid(公众平台):在微信内置浏览器中打开网页链接,刚进入页面就通过微信公众平台获取该 ...