日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hive的使用之脚本文件

發布時間:2025/3/11 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hive的使用之脚本文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


好處

在實際開發中,遇到復雜的hivesql,在文件里先寫好再執行,比直接在控制臺寫更高效,糾錯,修改更方便,也易于后期維護。


[hadoop@hello110 ~]$ 模式

在hive沒有啟動的時候,非hive內,在linux用戶輸入命令界面。 輸入命令后,會啟動hive,然后執行。執行完退出hive,每執行一條都要啟動,比較耗時。

$>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的使用之脚本文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。