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)文章!
相關(guān)文章
新推出的金融版eXtremeDB 6.0功能改進(jìn)預(yù)覽
這篇文章主要介紹了新推出的金融版eXtremeDB 6.0功能改進(jìn)預(yù)覽,如運(yùn)用SQL, Python實(shí)現(xiàn)的基于矢量的統(tǒng)計(jì)功能、分布式的查詢處理、市場(chǎng)數(shù)據(jù)壓縮等內(nèi)容,需要的朋友可以參考下2014-10-10利用SQL腳本導(dǎo)入數(shù)據(jù)到不同數(shù)據(jù)庫(kù)避免重復(fù)的3種方法
這篇文章主要給大家介紹了關(guān)于利用SQL腳本導(dǎo)入數(shù)據(jù)到不同數(shù)據(jù)庫(kù)避免重復(fù)的3種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10SQL WHERE IN參數(shù)化編譯寫法簡(jiǎn)單示例
這篇文章主要給大家介紹了關(guān)于SQL WHERE IN參數(shù)化編譯寫法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用SQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11SQL知識(shí)點(diǎn)之列轉(zhuǎn)行Unpivot函數(shù)
這篇文章主要給大家介紹了關(guān)于SQL知識(shí)點(diǎn)之列轉(zhuǎn)行Unpivot函數(shù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用SQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09SQL注入篇學(xué)習(xí)之盲注/寬字節(jié)注入
盲注是注入的一種,指的是在不知道數(shù)據(jù)庫(kù)返回值的情況下對(duì)數(shù)據(jù)中的內(nèi)容進(jìn)行猜測(cè),實(shí)施SQL注入,下面這篇文章主要給大家介紹了關(guān)于SQL注入篇之盲注/寬字節(jié)注入的相關(guān)資料,需要的朋友可以參考下2022-03-03