背景
- 有一份csv文件,需要加载到hive的orc表
步骤
- 将orc表内容复制到notepad++,这里到notepad++出来的分隔符默认是tab符。
- 我们将分隔符替换成你hive的分隔符,我这边分隔符是/u0001。
- Ctrl+Shift+A:/u0001
- 然后保存成txt文件,上传到linux目录下 我一直rz上传不成功,直接拖拽就成功了(csv文件load进去会乱码的)
- 先load到存储格式为textfile的临时表,然后insert overwrite导入到orc的表
load data local inpath '/home/city.txt' into table dwd.xzqh_tmp;
insert overwrite table dwd.xzqh select * from dwd.xzqh_tmp;
- 导入完毕后验证下数据准确性,即可删除tmp表
create table if not exists dwd.xzqh (
cityid string
,cityname string
,provid string
,provname string
)
comment '身份证前四位匹配_行政区划' row format delimited fields terminated by '\u0001' stored as orc
;
create table if not exists dwd.xzqh_tmp (
cityid string
,cityname string
,provid string
,provname string
)
comment '身份证前四位匹配_行政区划' row format delimited fields terminated by '\u0001' stored as textfile
;