学习配置单元,创建表并尝试从csv文件插入数据,不会引发错误,但插入的数据都是空的(不是来自.csv文件的实际数据)。.csv输入文件中有100条记录(文件上传到hdfs)。请提前帮助我。
以下是执行的命令序列
hive> CREATE TABLE IF NOT EXISTS CampaignDB (isano int,MemberName string,cityordist string,state string,mobile int,email string,memtype string) comment 'Doc Campaign data' row format delimited stored as textfile;
OK
Time taken: 0.323 seconds
hive> desc CampaignDB;
OK
isano int None
membername string None
cityordist string None
state string None
mobile int None
email string None
memtype string None
Time taken: 0.212 seconds, Fetched: 7 row(s)
hive> LOAD DATA INPATH '/user/hadoop/input/campaignDB-sample.csv' OVERWRITE INTO TABLE CampaignDB;
Loading data to table default.campaigndb
Deleted hdfs://localhost:9000/user/hive/warehouse/campaigndb
Table default.campaigndb stats: [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 239, raw_data_size: 0]
OK
Time taken: 0.536 seconds
hive> CREATE TABLE IF NOT EXISTS CampaignDB (isano int,MemberName string,cityordist string,state string,mobile int,email string,memty select * from CampaignDB;
OK
NULL NULL NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL NULL NULL
Time taken: 0.161 seconds, Fetched: 3 row(s)
答案 0 :(得分:2)
CREATE TABLE IF NOT EXISTS CampaignDB
(isano int,
MemberName string,
cityordist string,
state string,
mobile int,
email string,
memtype string)
comment 'Doc Campaign data'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' --if it is comma separated file
STORED AS TEXTFILE;
location '/user/hadoop/input/campaignDB-sample.csv';
以上将创建元数据。要加载数据,
LOAD DATA LOCAL INPATH' /user/hadoop/input/campaignDB-sample.csv' OVERWRITE INTO TABLE CampaignDB;
- 如果您没有指定文件中的数据使用的分隔符,则可能会发生这种情况。
答案 1 :(得分:1)
包括字段终止符。在“ROW FORMAT DELIMITED”之后添加FIELDS TERMINATED BY'|'或任何角色分裂你的领域。 csv文件所以可能是一个逗号。