hive 字段中逗号怎么处理_在Hive中添加逗号分隔的表格

I have a very basic question which is: How can I add a very simple table to Hive. My table is saved in a text file (.txt) which is saved in HDFS. I have tried to create an external table in Hive which points out this file but when I run an SQL query (select * from table_name) I don't get any output.

Here is an example code:

create external table Data (

dummy INT,

account_number INT,

balance INT,

firstname STRING,

lastname STRING,

age INT,

gender CHAR(1),

address STRING,

employer STRING,

email STRING,

city STRING,

state CHAR(2)

)

LOCATION 'hdfs:///KibTEst/Data.txt';

KibTEst/Data.txt is the path of the text file in HDFS.

The rows in the table are seperated by carriage return, and the columns are seperated by commas.

Thanks for your help!

解决方案You just need to create an external table pointing to your file

location in hdfs and with delimiter properties as below:

create external table Data (

dummy INT,

account_number INT,

balance INT,

firstname STRING,

lastname STRING,

age INT,

gender CHAR(1),

address STRING,

employer STRING,

email STRING,

city STRING,

state CHAR(2)

)

ROW FORMAT DELIMITED

FIELDS TERMINATED BY ','

LINES TERMINATED BY '\n'

LOCATION 'hdfs:///KibTEst/Data.txt';

You need to run select query(because file is already in HDFS and external table directly fetches data from it when location is specified in create statement). So you test using below select statement:

SELECT * FROM Data;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值