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;使用時會報(bào)錯
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,之后再從臨時表導(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文件的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
使用Navicat導(dǎo)入和導(dǎo)出sql語句的圖文教程
Navicat是MySQL非常好用的可視化管理工具,功能非常強(qiáng)大,能滿足我們?nèi)粘?shù)據(jù)庫開發(fā)的所有需求,下面這篇文章主要給大家介紹了關(guān)于使用Navicat導(dǎo)入和導(dǎo)出sql語句的相關(guān)資料,需要的朋友可以參考下2023-03-03
RBAC簡介_動力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了RBAC簡介,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08
mybatis 項(xiàng)目配置文件實(shí)例詳解
這篇文章主要介紹了mybatis 項(xiàng)目配置文件實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-03-03
OceanBase自動生成回滾SQL的全過程(數(shù)據(jù)庫變更時)
在開發(fā)中,數(shù)據(jù)的變更與維護(hù)工作一般較頻繁,當(dāng)我們執(zhí)行數(shù)據(jù)庫的DML操作時,必須謹(jǐn)慎考慮變更對數(shù)據(jù)可能產(chǎn)生的后果,以及變更是否能夠順利執(zhí)行,所以本文給大家介紹了數(shù)據(jù)庫變更時,OceanBase如何自動生成回滾 SQL,需要的朋友可以參考下2024-04-04

