hadoop中hive常用的交互式操作
阿新 • • 發佈:2019-04-03
-i ken cif init mas variable rom sil ati
hive的幫助命令:
[[email protected] tmp]$ hive -help usage: hive -d,--define <key=value> Variable substitution to apply to Hive commands. e.g. -d A=B or --define A=B --database <databasename> Specify the database to use -e <quoted-query-string> SQL from command line -f <filename> SQL from files -H,--help Print help information --hiveconf <property=value> Use value for given property --hivevar <key=value> Variable substitution to apply to Hivecommands. e.g. --hivevar A=B -i <filename> Initialization SQL file -S,--silent Silent mode in interactive shell -v,--verbose Verbose mode (echo executed SQL to the console)
*hive -e --不進入交互式,直接執行
[[email protected] tmp]$ hive -e "select * from db_hive.u2;"
Logging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: true
OK
u2.id u2.name u2.age u2.month u2.day
1 xm1 16 9 14
2 xm2 18 9 14
3 xm3 22 9 14
4 xh4 20 9 14
5 xh5 22 9 14
6 xh6 23 9 14
7 xh7 25 9 14
8 xh8 28 9 14
9 xh9 32 9 14
Time taken: 5.155 seconds, Fetched: 9 row(s
*hive -f <filename>
先準備一個文件:hivef.sql
[[email protected] tmp]$ more hivef.sql select * from db_hive.u2;
hive -f hivef.sql
[[email protected] tmp]$ hive -f hivef.sql Logging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: true OK u2.id u2.name u2.age u2.month u2.day 1 xm1 16 9 14 2 xm2 18 9 14 3 xm3 22 9 14 4 xh4 20 9 14 5 xh5 22 9 14 6 xh6 23 9 14 7 xh7 25 9 14 8 xh8 28 9 14 9 xh9 32 9 14 Time taken: 5.398 seconds, Fetched: 9 row(s)
還可以重定向到文件中:
[[email protected] tmp]$ hive -f hivef.sql>hive_result.txt Logging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: true OK Time taken: 5.224 seconds, Fetched: 9 row(s)
查看文件:
[[email protected] tmp]$ ls -rlt -rw-rw-r--. 1 hadoop hadoop 26 Apr 2 23:38 hivef.sql -rw-rw-r--. 1 hadoop hadoop 163 Apr 2 23:49 hive_result.txt [[email protected] tmp]$ more hive_result.txt u2.id u2.name u2.age u2.month u2.day 1 xm1 16 9 14 2 xm2 18 9 14 3 xm3 22 9 14 4 xh4 20 9 14 5 xh5 22 9 14 6 xh6 23 9 14 7 xh7 25 9 14 8 xh8 28 9 14 9 xh9 32 9 14
hive -i <filename> 與用戶udf相互使用
hadoop中hive常用的交互式操作