文本文件到sql显示空值

qvtsj1bj  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(309)

我的数据-:

id      name                    alpha_2 alpha_3
4       Afghanistan             af      afg
8       Albania                 al      alb
12      Algeria                 dz      dza
20      Andorra                 ad      and
24      Angola                  ao      ago
28      Antigua and Barbuda     ag      atg

我的代码-:

create table futurecart_case_country_details (
  id int, 
  Name varchar(75), 
  Alpha_2 varchar(2), 
  Alpha_3 varchar(2));

load data local infile 'project/futurecart_case_country_details.txt' 
into table edureka_667602_futurecart_case_country_details 
fields terminated by " " 
lines terminated by "\n";

sql中的输出-:

0       null    null    null
4       null    null    null
8       null    null    null
12      null    null    null
20      null    null    null
24      null    null    null
28      and     Ba      null

请帮帮我,我不知道我做错了什么,似乎有些小事。

bwntbbo3

bwntbbo31#

下面的方法可能会对您有所帮助,

-- input data with '\t'  as a delimiter(tab)
vim /home/sathya/test-datasets/hive-data.txt 

id      name    alpha_2 alpha_3
4       Afghanistan     af      afg
8       Albania al      alb
12      Algeria dz      dza
20      Andorra ad      and
24      Angola  ao      ago
28      Antigua and Barbuda     ag      atg

--in hive shell;
create database storage;
use storage;
create table storage.futurecart_case_country_details(id string, name string, alpha_2 string, alpha_3 string) row format delimited  fields terminated by '\t' lines terminated by '\n' stored as textfile;
alter table storage.futurecart_case_country_details SET TBLPROPERTIES ("skip.header.line.count"="1");

--OK
--Time taken: 0.786 seconds

load data local inpath '/home/sathya/test-datasets/hive-data.txt' into table futurecart_case_country_details;
--Loading data to table storage.futurecart_case_country_details
--Table storage.futurecart_case_country_details stats: [numFiles=1, numRows=0, totalSize=145, rawDataSize=0]
--OK
--Time taken: 1.889 seconds
select * from storage.futurecart_case_country_details;
/*
4       Afghanistan     af      afg
8       Albania al      alb
12      Algeria dz      dza
20      Andorra ad      and
24      Angola  ao      ago
28      Antigua and Barbuda     ag      atg

* /

--Time taken: 0.067 seconds, Fetched: 7 row(s)
select name from storage.futurecart_case_country_details;
/*
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda
Time taken: 0.101 seconds, Fetched: 7 row(s)

* /

select alpha_2 from storage.futurecart_case_country_details;
/*
af
al
dz
ad
ao
ag
Time taken: 0.142 seconds, Fetched: 7 row(s)

* /

select alpha_3 from storage.futurecart_case_country_details;
/*
afg
alb
dza
and
ago
atg
Time taken: 0.054 seconds, Fetched: 7 row(s)

* /

select id from storage.futurecart_case_country_details;
/*
4
8
12
20
24
28
Time taken: 0.193 seconds, Fetched: 7 row(s)

* /

show create table storage.futurecart_case_country_details;

/*
CREATE TABLE `hrdt_all_storage.futurecart_case_country_details`(
  `id` string,
  `name` string,
  `alpha_2` string,
  `alpha_3` string)
ROW FORMAT DELIMITED
  FIELDS TERMINATED BY '\t'
  LINES TERMINATED BY '\n'
STORED AS INPUTFORMAT
  'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'hdfs://localhost:9000/apps/hive/warehouse/storage.db/futurecart_case_country_details'
TBLPROPERTIES (
  'last_modified_by'='g.t1hrdtapp.001',
  'last_modified_time'='1596623083',
  'numFiles'='1',
  'numRows'='0',
  'rawDataSize'='0',
  'skip.header.line.count'='1',
  'totalSize'='145',
  'transient_lastDdlTime'='1596623083')

* /

相关问题