hadoop中hive常用的交互式操作

hive的帮助命令:

[hadoop@master 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 Hive
                                  commands. 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  --不进入交互式,直接执行

[hadoop@master 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

[hadoop@master tmp]$ more hivef.sql
select * from db_hive.u2;

 hive -f hivef.sql

[hadoop@master 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)

还可以重定向到文件中:

[hadoop@master 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)

查看文件:

[hadoop@master 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
[hadoop@master 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相互使用

猜你喜欢

转载自www.cnblogs.com/hello-wei/p/10646230.html