查看錶結構 desc tablename
查看錶結構 desc extended tablename;
查看建表語句 show create tablename;
查看錶分隔符 desc formated tablename;
查看錶分區 show partitions tablename;
複製表 create table test2 like test1
複製表並複製數據create table test2 as select id,name from test1
查看添加了哪些jar:list jar ;
在hive命令行執行本地shell文件 source /home/hadoop/xxx.hql.sh
本地數據導入hive表 LOAD DATA LOCAL INPATH '/home/hadoop/test.log' INTO table hive_table;
本地數據導入hive分區表 LOAD DATA LOCAL INPATH '/home/hadoop/test.log' INTO table hive_table partition(dt='20150801');
HDFS數據導入hive表 LOAD DATA INPATH '/home/hadoop/test.log' INTO table hive_table;
修改表名 alter table table_name rename to new_table_name
修改列名 alter table tablename change column c1 c2 int comment 'XXXXX'
添加列 alter table tablename add columns(c1 string comment 'xxxx',c2 long cimment 'yyyyyy')
修改表分隔符 alter table table_name set serdeproperties('field.delim' = '\t')
添加分區並設置分隔符 alter table test partition(dt='xxxx') set serdeproperties ('field.delim'='\t')
設置null的表示方式 alter table tablename SET SERDEPROPERTIES ('serialization.null.format' = '');
修改表location alter table hive_table set location 'hdfs://hadoop1:9000/user/hive/warehouse/test.db/hive_table';
刪除表分區 ALTER TABLE table DROP PARTITION (dt='2016-04-08');
hive自定義函數配置(UDF通過這種方式不需要在hql上寫add jar 和create語句)
1.用戶下的.hiverc:vi ~/.hiverc
add jar /home/orange/udf/hiveUdf.jar;
create temporary function temp1 as 'com.hive.udf.temp1UDF';
create temporary function temp2 as 'com.hive.udf.temp2UDF';
2. 重啓hive console
3. 通過show functions 查看現有的方法列表。
4. 可以通過desc function ${function_name}查看方法描述。
按日期循環執行hive語句
創建腳本
vi test.sh
#!/bin/sh
startdate=`date -d "$1" +%Y-%m-%d`
enddate=`date -d "$2" +%Y-%m-%d`
while [[ $startdate < $enddate ]]
do
echo "########$startdate#########"
hive -hiveconf current_date=$startdate -f /data/orange/select.hql >> /data/orange/xx.log
startdate=`date -d "+1 day $startdate" +%Y-%m-%d`
done
保存
修改權限 chmod 755 test.sh
創建hql語句
vi select.hql
select * from table where dt = '${hiveconf:current_date}' ;
執行
/data/orange/test.sh 2015-10-01 2015-10-10
hive筆記
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.