1.通过cli直接执行

2.hive -e "hql"

如:[root@host ~]# hive -e "use gamedw;show tables"

[root@host ~]# hive -e 'use gamedw;show tables'

3.执行文件
[root@host tmpdata]# cat hive.sql
select * from gamedw.v_cust

[root@host ~]# hive -f /root/tmpdata/hive.sql  

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

OK
tianyongtao     1       50      shenzhen
wangwu  1       85      shenzhen
zhangsan        1       20      shenzhen
liuqin  0       56      shenzhen
wangwu  0       47      shenzhen
liuyang 1       32      shenzhen
Time taken: 5.386 seconds, Fetched: 6 row(s)

[root@host ~]# hive -f /root/tmpdata/hive.sql >/root/tmpdata/hivelog.txt   //结果保存到本地

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

OK

Time taken: 4.75 seconds, Fetched: 6 row(s)
[root@host ~]# cat /root/tmpdata/hivelog.txt
tianyongtao     1       50      shenzhen
wangwu  1       85      shenzhen
zhangsan        1       20      shenzhen
liuqin  0       56      shenzhen
wangwu  0       47      shenzhen
liuyang 1       32      shenzhen

同样

 hive -i  /root/tmpdata/hive.sql  也可以执行hql同时开启cli

hive  -hivevar 传递参数

[root@host ~]# cat /root/tmpdata/hivevar.sql
select * from gamedw.v_cust where sex=${varsex} and age>${varage};

[root@host ~]# hive -hivevar varsex=0 -hivevar varage=20 -f /root/tmpdata/hivevar.sql

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true

OK
liuqin  0       56      shenzhen
wangwu  0       47      shenzhen
Time taken: 5.839 seconds, Fetched: 2 row(s)

[root@host ~]# hive -e "select * from gamedw.cust">>cust.txt SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in file:/root/hive/apache-hive-2.1.1/conf/hive-log4j2.properties Async: true OK Time taken: 9.204 seconds, Fetched: 19 row(s)

[root@host ~]# cat cust.txt
tianyt_touch100 1       50
wangwu  1       85
zhangsan        1       20
liuqin  0       56
wangwu  0       47
liuyang 1       32
hello   0       100
mahuateng       1       1001
tianyt_touch100 1       50
wangwu  1       85
zhangsan        1       20
liuqin  0       56
wangwu  0       47
xiaomage        NULL    51
nihao   1       5
liuyang 1       32
hello   0       100
mahuateng       1       1001
nihao   1       5

hive命令的执行方式的更多相关文章

  1. hive -help hive命令行执行sql参数

    在shell命令行执行 hive -help 结果如下: -d,--define <key=value> Variable substitution to apply to Hive co ...

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

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

  3. Linux下的Source命令及脚本的执行方式解析

    Linux Source命令及脚本的执行方式解析 http://blog.csdn.net/wangyangkobe/article/details/6595143 当我修改了/etc/profile ...

  4. Source命令及脚本的执行方式

    [Source命令及脚本的执行方式] source filename 与 sh filename 及./filename执行脚本的区别在那里呢? 1.当shell脚本具有可执行权限时,用sh file ...

  5. shell基础概念, if+命令, shell中引用python, shell脚本的几种执行方式

    说明: 虚拟机中shell_test目录用来练习shell, 其中有个test.log文件用来存放日志 #!/usr/bin/bash      # shell文件开头, 用来指定该文件使用哪个解释器 ...

  6. ansible的两种命令执行方式 : ad-hoc / playbook以及通过setup模块获取系统参数

    一.什么是ad-hoc和playbook  ad-hoc : 如果我们敲入一些命令去快速的完成一些操作,而不需要将这些执行过的命令刻意保存下来,这样的命令就叫做as-hoc命令,这里不做过多赘述. p ...

  7. hive 源码笔记(1):命令行执行的主流程。

    1. 'hive'命令是(默认为hive跟目录)./bin下的一个shell脚本,依次加载 ./bin/hive-config.sh, ./conf/hive-env.sh, 设置与hadoop.sp ...

  8. hadoop笔记之Hive的管理(CLI方式)

    Hive的管理(一) Hive的管理(一) Hive的启动方式 CLI(命令行)方式 Web界面方式 远程服务启动方式 CLI方式 1. 进入命令行方式 直接输入<HIVE_HOME>/b ...

  9. hive 命令行传入参数

    azkban实现任务重跑 我们执行sql的方式是将hql文件上传到服务器本地.然后执行shell命令 hive " -f ./test_scheduler.hql 注:hive -e 是执行 ...

随机推荐

  1. nginx - 性能优化,突破十万并发

    一般来说nginx配置文件中对优化比较有作用的为以下几项: worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数. worker_cpu_affinity ...

  2. 【Maven】从Maven中导出项目依赖的Jar包

    从SVN上下载源代码 svn export https://10.200.1.201/xxxx/PLATFORM code/ --force --username xxx --password xxx ...

  3. uoj#29. 【IOI2014】Holiday

    http://uoj.ac/problem/29 经过的点集一定是一个包含start的区间,为了经过这个区间内所有点,必须先到达一个区间端点,再到达另一个区间端点,剩余的步数则贪心选区间内最大价值的点 ...

  4. 关于Strategy和State设计模式

    之前,我在描述我所采用的设计模式时,一直在Strategy和State之间犹豫,略微有些拿捏不准,说哪种设计模式好.结果到最后,会根据自己所想,觉得是State就是State,觉得Strategy就是 ...

  5. python实现简单的登陆认证(含简单的文件操作)

    需求: 让用户输入用户名密码 认证成功后显示欢迎信息 输错三次后退出程序 可以支持多个用户登录 (提示,通过列表存多个账户信息) 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(本 ...

  6. Zabbix利用orabbix插件监控Oracle数据库

    一.jdk的安装(Orabbix Server) 1.软件解压,放到固定位置 1 2 tar zxf jdk-8u51-linux-x64.tar.gz mv jdk1.8.0_51/ /usr/lo ...

  7. win7右键菜单调整顺序

    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ Discardable\PostSetup\ShellNew ...

  8. SAS 数值转日期

    DATA _NULL_;FORMAT A YYMMDDN8.;B=PUT(20180101,$8.);A=INPUT(B,YYMMDD8.);PUT B= A=;RUN; 输出:47   DATA _ ...

  9. CRM 2016 IFrame 函数修改 父页面字段

    IFrame js 代码: parent.Xrm.Page.getAttribute("new_xxxx").setValue(123); 当然,可以设置 new_xxxx 字段的 ...

  10. CRM 报表中 Filtered 无数据

    数据源设置为以下才可以使用  Filtered+实体名称和  fn_FindBusinessGuid   和 fn_FindUserGuid