Hive的使用之脚本文件
来源:互联网 发布:浙江软件考试成绩查询 编辑:程序博客网 时间:2024/05/30 07:13
好处
在实际开发中,遇到复杂的hivesql,在文件里先写好再执行,比直接在控制台写更高效,纠错,修改更方便,也易于后期维护。
[hadoop@hello110 ~]$ 模式
$>hive -e "sql语句"
[hadoop@hello110 ~]$ hive -e "show tables"
which: no hbase in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/app/jdk1.8.0_73/bin:/home/hadoop/app/hadoop-2.7.2/bin:/home/hadoop/app/hadoop-2.7.2/sbin:/home/hive2.1/bin:/home/hadoop/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive2.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.7.2/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:/home/hive2.1/conf/hive-log4j2.properties Async: true
OK
array_test
map_test
student_test
test
test2
test3
Time taken: 3.503 seconds, Fetched: 6 row(s)
-------------------------------------------------------------------------
$>hive -e "sql语句">aaa
把sql执行结果覆盖到aaa文件里
[hadoop@hello110 ~]$ hive -e "show tables" > aaa
which: no hbase in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/app/jdk1.8.0_73/bin:/home/hadoop/app/hadoop-2.7.2/bin:/home/hadoop/app/hadoop-2.7.2/sbin:/home/hive2.1/bin:/home/hadoop/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive2.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.7.2/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:/home/hive2.1/conf/hive-log4j2.properties Async: true
OK
Time taken: 2.508 seconds, Fetched: 6 row(s)
[hadoop@hello110 ~]$ ll
total 384164
-rw-rw-r--. 1 hadoop hadoop 50 Sep 1 18:56 aaa
drwxrwxr-x. 4 hadoop hadoop 4096 Mar 13 04:44 app
-rw-rw-r--. 1 hadoop hadoop 629 Aug 26 05:47 derby.log
-rw-rw-r--. 1 hadoop hadoop 212046774 Mar 12 07:36 hadoop-2.7.2.tar.gz
-rw-rw-r--. 1 hadoop hadoop 181310701 Mar 9 13:31 jdk-8u73-linux-x64.tar.gz
drwxrwxr-x. 5 hadoop hadoop 4096 Aug 26 05:47 metastore_db
[hadoop@hello110 ~]$ more aaa
array_test
map_test
student_test
test
test2
test3
------------------------------------------------------------------------------
$>hive -e "sql语句">>aaa
把sql执行结果追加到aaa文件里
[hadoop@hello110 ~]$ hive -e "desc map_test" >> aaa
which: no hbase in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/app/jdk1.8.0_73/bin:/home/hadoop/app/hadoop-2.7.2/bin:/home/hadoop/app/hadoop-2.7.2/sbin:/home/hive2.1/bin:/home/hadoop/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive2.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.7.2/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:/home/hive2.1/conf/hive-log4j2.properties Async: true
OK
Time taken: 5.296 seconds, Fetched: 2 row(s)
[hadoop@hello110 ~]$ more aaa
array_test
map_test
student_test
test
test2
test3
id string
perf map<string,int>
----------------------------------------------------------------------------------------------
$>hive -S -e "">aaa -S
安静地,不打印出内容
-----------------------------------------------------------------------------------------------
$>hive -f file
在文件里写好sql语句,然后用 hive -f 文件 进行执行。[hadoop@hello110 ~]$ vi t.sql
show tables;
desc map_test;
[hadoop@hello110 ~]$ hive -f t.sql
which: no hbase in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/app/jdk1.8.0_73/bin:/home/hadoop/app/hadoop-2.7.2/bin:/home/hadoop/app/hadoop-2.7.2/sbin:/home/hive2.1/bin:/home/hadoop/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive2.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.7.2/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:/home/hive2.1/conf/hive-log4j2.properties Async: true
OK
array_test
map_test
student_test
test
test2
test3
Time taken: 19.658 seconds, Fetched: 6 row(s)
OK
id string
perf map<string,int>
Time taken: 26.635 seconds, Fetched: 2 row(s)
--------------------------------------------------------------------------------------------------
$>hive -i file
执行完了后,不退出hive,还能操作。[hadoop@hello110 ~]$ hive -i t.sql
which: no hbase in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/app/jdk1.8.0_73/bin:/home/hadoop/app/hadoop-2.7.2/bin:/home/hadoop/app/hadoop-2.7.2/sbin:/home/hive2.1/bin:/home/hadoop/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive2.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/app/hadoop-2.7.2/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:/home/hive2.1/conf/hive-log4j2.properties Async: true
array_test
map_test
student_test
test
test2
test3
id string
perf map<string,int>
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive>
---------------
hive> 模式
hive>source file
hive> source t.sql;
OK
array_test
map_test
student_test
test
test2
test3
Time taken: 1.988 seconds, Fetched: 6 row(s)
OK
id string
perf map<string,int>
Time taken: 0.604 seconds, Fetched: 2 row(s)
hive>
- Hive的使用之脚本文件
- hive之脚本执行
- hive 使用python脚本
- Hive的使用之控制台
- Hive的使用之hwi
- hive的脚本执行
- Hive使用脚本加载数据
- hive 使用streaming 的map 脚本来处理数据
- Hive 之使用mysql作为hive的metastore
- hive学习之hive的常用使用方式
- Hive之 load的使用注意事项
- 删除hive表的脚本
- HIVE的shell脚本模板
- 使用shell脚本执行hive、sqoop命令
- shell脚本之文件相关的命令
- Linux之防火墙的两个脚本文件
- hive优化之自动合并输出的小文件
- Hive 之 合并小文件
- BZOJ1598: [Usaco2008 Mar]牛跑步 次短路裸题
- android library projects cannot be launched 报错原因!
- ImageView的ScaleType详解
- 3.4 C++四种继承关系中内存分布
- [js] 变量 操作符 对象
- Hive的使用之脚本文件
- Android 接收短信
- 文章标题
- ROS实战之IDE的配置
- MySQL-API接口大全
- 文件上传 ,java.lang.IllegalStateException: File has been moved - cannot be read again org.springframewor
- Unity3D - Unity游戏Mono内存管理与泄漏
- Keyguard显示流程介绍
- myeclipse 优化内存设置