向 hive 分区表中插入数据

1、创建分区表的外部表(外部表防止数据被误删)


CREATE EXTERNAL TABLE IF NOT EXISTS stg_hive_es_test (
id  BIGINT COMMENT '主键id',
road_id  STRING COMMENT '路线id',
road_name  STRING COMMENT '路线name',
road_dir_no  BIGINT COMMENT '行驶方向 1:北京方向,2:雄安方向',

flow  double COMMENT '车流量保留2位小数',
time string comment '时间'

) COMMENT '路况类指标-平均速度-离线-按天更新'
PARTITIONED BY (
dt  STRING COMMENT 'yyyy-MM-dd'
)
ROW FORMAT
SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'field.delim' = '\u0001',
'serialization.format' = '\u0001'
)
STORED AS
INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat';

2、向分区表中插入数据

insert into table  stg_hive_es_test partition(dt='2022-03-31') values
(1,'10001','京雄test',2,65.21,'2022-03-31 00:09:08'),
(2,'10002','京雄test',2,65.21,'2022-03-31 00:09:09');

你可能感兴趣的:(hive,hadoop,hive,hadoop)