1.创建hive表,插入数据
创建test_a
create table test_a(id int,a string,p_day_id string);
insert into table test_a select 1,'a1','20230201';
insert into table test_a select 2,'a2','20230201';
创建test_b
create table test_b(id int,b string,p_day_id string,month_number int);
insert into table test_b select 1,'b1','20230201',1;
insert into table test_b select 2,'b2','20230201',null;
创建test_c合并两天数据,分区为month_number
hive> create table test_c(id int,a string,b string,p_day_id string) PARTITIONED BY(month_number int);
编写插入数据的sql
hive> select a.id,a.a,b.b,a.p_day_id,b.month_number from test_a a left join test_b b on a.id=b.id where a.p_day_id=b.p_day_id and a.p_day_id='20230201';
1 a1 b1 20230201 1
2 a2 b2 &nb
Hive表操作:创建、插入数据及动态分区问题

文章展示了在Hive中创建表`test_a`和`test_b`,插入数据,并通过`leftjoin`合并数据到新表`test_c`,使用动态分区插入数据。过程中遇到了null分区和数据覆盖的问题,特别是在插入新账期数据时,原有的分区数据被覆盖。
最低0.47元/天 解锁文章
345

被折叠的 条评论
为什么被折叠?



