hive -e "select * from mytable limit 3";
hive -S -e "select * from mytable limit 3" > /tmp/myquery
[root@** config]# hive -S -e "set" | grep warehouse; hive.metastore.warehouse.dir=/user/hive/warehouse hive.warehouse.subdir.inherit.perms=true
4.从文件中查询:
hive -f /path/to/file/query.hql
hive> source /path/to/file/query.hql
hive> dfs -ls /;
Found 12 items
drwxrwxrwx - trafodion trafodion 0 2017-08-25 17:30 /bulkload
drwxr-xr-x - hdfs supergroup 0 2017-06-27 15:06 /cy
drwxr-xr-x - hbase hbase 0 2017-08-24 16:31 /hbase
drwxr-xr-x - hbase hbase 0 2017-08-24 15:31 /hbase-staging
drwxr-xr-x - trafodion trafodion 0 2017-08-24 15:31 /lobs
drwxr-xr-x - hdfs supergroup 0 2017-06-26 14:25 /opt
drwxr-xr-x - hdfs supergroup 0 2017-07-18 15:16 /pacc
drwxr-xr-x - hdfs supergroup 0 2017-09-06 15:59 /pcc
drwxr-xr-x - hdfs supergroup 0 2017-07-23 03:55 /test
drwxrwxrwt - hdfs supergroup 0 2017-09-06 13:42 /tmp
drwxrwxrwx - trafodion trafodion 0 2017-08-24 15:31 /trafodion_backups
drwxr-xr-x - hdfs supergroup 0 2017-08-30 14:37 /user
6. 设置显示字段名称,默认是关闭的:
hive> set hive.cli.print.header=true;
7.设置在使用hive时避免产生MapReduce:
set hive.exec.mode.local.auto=true;
create table employees ( name string, salary float, subordinates Array<string>, deductions Map<string, float>, address Struct<street:string, ciity: string, state:string,zip:int> );
create external table if not exists stocks( exchange string, symbol string, ... ... ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/data/stocks';
alter table a rename to b;
alter table a add if not exists partition (year = 2011,month=1,day = 1) location '/logs/2011/1/1';
五、向表中插入数据
load data local inpath '/path/california-employees' overwrite into table employees partition (county = 'us' , state = 'ca')
insert overwrite table emp partition (country = 'US', state = 'OR') select * from s_emp se where se.cnty = 'US' and se.st = 'OR';
insert overwrite table emp partition (country , state) select ..., se.cnty, se.st from s_emp se;

select year(ymd), avg(price) from stocks group by year(ymd);
SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer HAVING SUM(OrderPrice)<2000
浙公网安备 33010602011771号