在实际开发中,遇到复杂的hivesql,在文件里先写好再执行,比直接在控制台写更高效,纠错,修改更方便,也易于后期维护。
[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)
-------------------------------------------------------------------------
把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
------------------------------------------------------------------------------
把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
----------------------------------------------------------------------------------------------
安静地,不打印出内容
-----------------------------------------------------------------------------------------------
[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
Time taken: 26.635 seconds, Fetched: 2 row(s)
--------------------------------------------------------------------------------------------------
[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
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> 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
Time taken: 0.604 seconds, Fetched: 2 row(s)
hive>