首页 > 解决方案 > 在 Hive 中将列格式从字符串更新为日期

问题描述

我在 Hive 中有一个外部表

Current:
col1 - string
col2 - string
col3 - string
col4 - float
col5 - int

我想将 col3 的日期类型更改为 date

Expected:
col1 - string
col2 - string
col3 - date
col4 - float
col5 - int

我尝试了常规的 sql 命令但没有用

alter table table_name modify col3 date;

Error:
Error while compiling statement: FAILED: ParseException line 1:32 cannot recognize input near 'modify' 'col3' 'date' in alter table statement

在这里请求帮助。提前致谢。

标签: hivehiveql

解决方案


正确的命令是:

alter table table_name change col3 col3 date;

column change 命令只会修改 Hive 的元数据,不会修改数据。用户应确保表/分区的实际数据布局符合元数据定义。

请参阅此处的语法和手册:更改列名称/类型/位置/注释


推荐阅读