0

学习配置单元,创建一个表并尝试从 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)
4

2 回答 2

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';

以上将创建元数据。要加载数据,

加载数据本地输入路径'/user/hadoop/input/campaignDB-sample.csv'覆盖到表CampaignDB;

-- 如果您没有指定文件中的数据使用的分隔符,则可能会发生这种情况。

于 2014-07-23T22:00:49.650 回答
1

包括一个字段终止符。在“行格式分隔”之后添加由“|”终止的字段 或任何字符将您的字段分开。csv 文件,所以可能是逗号。

于 2013-10-28T16:48:01.437 回答