Hive導(dǎo)入csv文件示例
正文
現(xiàn)有文件為csv格式,需要導(dǎo)入hive中,設(shè)csv內(nèi)容如下
1001,zs,23 1002,lis,24
首先創(chuàng)建表
create table if not exists csv2(
uid int,
uname string,
age int
)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
stored as textfile ;導(dǎo)入數(shù)據(jù)及查詢
load data local inpath '/data/csv2.csv' into table csv2; select * from csv2;
其他注意事項(xiàng)
如果建表是parquet格式可否load導(dǎo)入csv文件?
drop table csv2;
create table if not exists csv2(
uid int,
uname string,
age int
)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
stored as parquet ;
load data local inpath '/data/csv2.csv' into table csv2;
select * from csv2;使用時(shí)會(huì)報(bào)錯(cuò)
Failed with exception java.io.IOException:java.lang.RuntimeException: hdfs://192.168.10.101:8020/user/hive/warehouse/csv2/csv2.csv is not a Parquet file. expected magic number at tail [80, 65, 82, 49] but found [44, 50, 52, 10]
**不可以,需要先導(dǎo)入成textfile,之后再?gòu)呐R時(shí)表導(dǎo)入成parquet,**如下
drop table csv2;
create table if not exists csv2
(
uid int,
uname string,
age int
)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
stored as textfile;
-- 先導(dǎo)入csv文件到表格csv2,保存格式是textfile
load data local inpath '/data/csv2.csv' into table csv2;
drop table csv3;
-- 創(chuàng)建csv3,保存格式parquet
create table if not exists csv3
(
uid int,
uname string,
age int
)
row format delimited
fields terminated by ','
stored as parquet;
-- 提取csv2的數(shù)據(jù)插入到csv3
insert overwrite table csv3 select * from csv2;總結(jié)
- 關(guān)鍵是要引入org.apache.hadoop.hive.serde2.OpenCSVSerde
csv要保存到hive的parquet,需要先保存成textfile
以上就是Hive導(dǎo)入csv文件示例的詳細(xì)內(nèi)容,更多關(guān)于Hive導(dǎo)入csv文件的資料請(qǐng)關(guān)注本站其它相關(guān)文章!
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信