在Hive中更改列数据类型 [英] Alter column data type in Hive

查看:2247
本文介绍了在Hive中更改列数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要将表列数据类型从字符串更改为日期.在尝试执行操作时遇到以下错误.你能帮忙吗?

we need to alter the table column data type from string to date. While am trying to do am getting the below error. Could you please help.

hive>描述sales_staging;

hive> describe sales_staging;

cust_id字符串prod_num字符串
数量int sale_date字符串

cust_id string prod_num string
qty int sale_date string

sale_id字符串 耗时:0.151秒, 已提取:5行

sale_id string Time taken: 0.151 seconds, Fetched: 5 row(s)

hive>更改表sales_staging更改sale_date sale_date DATE;

hive> alter table sales_staging CHANGE sale_date sale_date DATE ;

失败:执行错误,返回代码1 org.apache.hadoop.hive.ql.exec.DDLTask.无法更改表格.这 以下列的类型与以下现有列不兼容 他们各自的职位:sale_date

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions :sale_date

蜂巢>

推荐答案

您不能为要更改其数据类型的列提供相同的名称.这样使用

You can't give same name to column you wish to change datatype of. use like this

ALTER TABLE sales_staging CHANGE sale_date sale_date_new DATE;

请参阅 Apache Hive Wiki

这篇关于在Hive中更改列数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆