To build the table
create table mydb.userinfo(name string,addressi string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;
Create a partition table
CREATE TABLE mydb.userinfo --创建表
(col1 string, col2 date, col3 double),
partitioned by (datekey date), --可以多个字段的组合分区
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
Stored AS TEXTFILE;
Data into the table mydb.userinfo
load data local inpath "/home/dahaizi/data/userinfo.txt"
overwrite into table mydb.userinfo;
Inserting data into the table
insert into table(col1,col2,col3) values('a','b','c')
The query data is inserted into an existing table
INSERT INTO TABLE table_Name
PARTITION (DateKey),
SELECT col1,col2,col3,DateKey FROM otherTable
WHERE DATEKEY IN ('2017-02-26','2013-06-12','2013-09-24'),
GROUP BY col1,col2,col3,DateKey
DISTRIBUTE BY DateKey
The hdfs catalog query data stored
insert overwrite directory '/jc_bdcqs/qsy'
row format delimited
fields terminated by ','
select * from zqs_gs_g60_0730_list;
!quit
HQL queries Common settings
1) Set the fault rate is calculated (to prevent an error calculation program aborted): set mapred.max.map.failures.percent=100;
2) limit the number of query output file set mapred.reduce.tasks=1;
3) reduce the maximum number of the control, does not affect the setting mapred.reduce.tasks set hive.exec.reducers.max = 100;
4) a job will how many reducer to deal with, the default is 1Gset hive.exec.reducers.bytes.per.reducer = 1000000000;
Set dynamic partitioning
set hive.exec.dynamic.partition=true;(可通过这个语句查看:set hive.exec.dynamic.partition;),
set hive.exec.dynamic.partition.mode=nonstrict;
SET hive.exec.max.dynamic.partitions=100000;(如果自动分区数大于这个参数,将会报错),
SET hive.exec.max.dynamic.partitions.pernode=100000;
Delete table
drop table tb_name;
Or empty tabletruncate table table_name;
Delete partition
ALTER TABLE table_Name DROP PARTITION (Datekey='20190606');
New zoning
alter table tb_name add partition (Datekey = ‘20190606’);