hive建表相关技术

1、hive相关配置

1.1分隔符

row format delimited 使用默认行分隔符。

SerDe是Serialize/Deserilize的简称。

1.2文件格式

1.3支持行级更新

2、hive表分类


2.1内部表(managed table管理表)

drop table if exists ods.dictionary_table;

create table if not exists ods.dictionary_table as   //幂等操作

SELECT t1.name as name,t1.code,t2.NAME as table_name

FROM  ods.conf_dict t1  JOIN  ods.conf_dict_group t2  ON  t1.DICT_GROUP_ID = t2.ID;

2.2外部表

相对管理表,多了external和location 'hdfs_location'两项参数。

2.3分区表

create table lesson.t_partition_01

(id int,

name string)

partitioned by (dt string,hour string)

ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

分区表不适用直接拷贝数据文件到hdfs,需要load data inpath...并指定分区。分区字段是虚拟字段。

总的来说partition就是辅助查询,缩小查询范围加快数据的检索速度和对数据按照一定的规格和条件进行管理。

2.4分桶表

分区字段不是表中已存在的字段,分桶字段是表中已存在字段。

bucket走的mr程序。

Map-side join

create table lesson.t_bucket_01

(sno int,sname string,sex string,sage int,sdept string)

clustered by(sno)

into 4 buckets

row format delimited

fields terminated by ',';

装载程序示例:

insert into lesson.t_bucket_01 select * from lesson.t_stu_01  cluster by(sno)

2.5like复制

2.6表修改ddl

3、hive表装载数据

3.1非分区表装载数据


3.2分区表装载数据

create table lesson.t_partition_01(id int,

name string)partitioned by (dt string,hour string)

ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

(不走mr)load data local inpath '/opt/partition_01.txt' into table lesson.t_partition_01 partition(dt='20190515',hour='23');   //静态分区

3.3动态分区插入

create table t_dyna_data(day string,ip string) row format delimited fields terminated by ',';

load data inpath '/opt/dynamic.txt'  into table t_dyna_data;

//动态插入  已设置true和nonstrict

create table t_dynamic_01(ip string) partitioned by(month string,day string)

row format delimited fields terminated by ',';

(走mr,动态)insert overwrite table t_dynamic_01 partition(month,day) select ip,substr(day,1,7)as month,day from t_dyna_data;

动态分区通过位置对应分区字段,就是说month、day对应第二、第三个字段位置,不对应字段名称。分区表分区字段在字段最后位置。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容