Hive的使用之脚本文件
 
好處
在實際開發(fā)中,遇到復(fù)雜的hivesql,在文件里先寫好再執(zhí)行,比直接在控制臺寫更高效,糾錯,修改更方便,也易于后期維護。
 
[hadoop@hello110 ~]$ 模式
在hive沒有啟動的時候,非hive內(nèi),在linux用戶輸入命令界面。 輸入命令后,會啟動hive,然后執(zhí)行。執(zhí)行完退出hive,每執(zhí)行一條都要啟動,比較耗時。$>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執(zhí)行結(jié)果覆蓋到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執(zhí)行結(jié)果追加到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
安靜地,不打印出內(nèi)容
-----------------------------------------------------------------------------------------------
$>hive -f file?
在文件里寫好sql語句,然后用 hive -f 文件 ?進行執(zhí)行。[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
執(zhí)行完了后,不退出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>?
 
 
 
 
 
總結(jié)
以上是生活随笔為你收集整理的Hive的使用之脚本文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: count(*),count(1),co
- 下一篇: spring bean创建细节
