1、创建数据库并赋权
create database if not exists test001;
grant all on database test001 to user hive;
2、模糊搜索表
show tables like ‘*name*’;
3、查看表结构
desc table_name;
desc formatted table_name;
4、查看建表语句
show create table table_name;
5、创建表
create table test001
(card_type string
,start_data string
,end_date string
)
PARTITIONED BY(dt STRING) –分区
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘,’ –分隔符
STORED AS TEXTFILE;
6、删除/清理分区
ALTER TABLE test001 DROP/truncate IF EXISTS PARTITION (dt=’2017-01-08′);
7、添加列
ALTER TABLE test001 ADD COLUMNS (col_name STRING);
8、修改列
ALTER TABLE test001 CHANGE col1 col2 INT;
9、删除列
ALTER TABLE test001 REPLACE COLUMNS (
card_type string
,start_data string
);
10、复制表结构
CREATE TABLE test002 LIKE test001;
11、修改表结构
ALTER TABLE test001 RENAME TO test002;
12、清空数据
truncate table test001;
13、数据插入
insert/overwrite into table test001
select c1,c2 from test002;
load data local inpath ‘test001.txt’ into/overwrite table test001;
14、数据提取
hive -database bss -e “set mapred.job.queue.name=datagather;
select * from ts_u_user_all limit 10 ” >/data/test/test001.csv
带字段名字的数据导出:
hive -S -e”set hive.cli.print.header=true;
select * from test001″ > test001.csv
hive -database bss -e”select * from ts_u_user_all limit 10″
15、转换文件的分隔符
sed -i ‘s//t/,/g’ test001.csv
16、函数引入
add jar /home/webusr/UDFAddByMe.jar ;
create temporary function ADD_MONTHS as ‘org.apache.hadoop.hive.ql.udf.UDFAddMonths’;
17、指定队列
set mapred.job.queue.name=datagather;
set mapred.job.queue.name=thirdpart;
18、工作查杀
进入目录/home/webusr/hadoop-2.4.0.2.1.2.0-402/bin
hadoop job -list
hadoop job -kill job_1436177979246_7826
———————-
19、查询文件大小
hdfs dfs -du -h /apps/hive/warehouse/dwd.db/dd_par_user_flag_jf_d
20、查看hdfs文件信息
hdfs dfs -ls /apps/hive/warehouse/
21、下载文件到某目录
hdfs dfs -get /user/jrjt/warehouse/ods.db/o_h02_click_log_i_new/dt=2014-01-21/000212_0 /data/test/work/;
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/192370.html