hive笔记

查看表结构 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章