【问题标题】:Can I add a subcolumn to a hive struct column using alter table?我可以使用 alter table 将子列添加到 hive 结构列吗?
【发布时间】:2017-11-14 19:19:22
【问题描述】:

我在hive中有一个非常复杂的表结构,假设如下表:

create table dirceu ( a struct<b:string,c:string>);

现在我确实需要在 a 列中添加另一个子列,它应该具有 b、c 和 d 结构,我正在尝试使用以下更改表:

alter table dirceu change column a a struct<b:string,c:string, d:string>;

但这会引发以下错误:

Error: Error while processing statement: 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 :
a (state=08S01,code=1)

有没有办法使用alter table 来做到这一点?我知道我可以使用创建表并复制数据来做到这一点,但我想知道是否有其他方法可以做到这一点。 更新 我正在使用蜂巢:2.1.0.2.6.1.0-129 HortonWorks:HDP-2.6.1.0

【问题讨论】:

    标签: hadoop hive


    【解决方案1】:

    这是你需要给出的命令,

    ALTER TABLE dirceu CHANGE COLUMN a a STRUCT<b:STRING, c:STRING, d:STRING>;
    

    您不能向 Collection 数据类型添加新字段。相反,您需要完全更改架构。 希望你喜欢这个答案。耶!

    【讨论】:

    • 您好 Krishna 感谢您回答这个问题,但此代码在这里不起作用。无法更改表。以下列的类型与各自位置的现有列不兼容:a (state=08S01,code=1)
    • 哦!它对我很有效。可能你的分布有问题。尝试在不同的系统上工作,如果问题仍然存在,请告诉我。
    【解决方案2】:

    我猜这个命令可以工作,

    alter table dirceu add column a struct<d:string>;
    

    如果它不起作用,请通过评论告诉我。

    【讨论】:

    • 嗨约翰,它没有工作错误:编译语句时出错:失败:ParseException 行 1:20 无法识别更改表语句中的“添加”“列”“a”附近的输入(状态 = 42000,代码=40000)
    • @John Deer 您需要更新架构。 “添加”命令不起作用。
    • 哦!谢谢@DSaiKrishna
    • @dirceusemighini 和 D Sai Krishna 我对此有疑问question.你能帮帮我吗?
    • 字段添加到复杂类型后无法删除。更多信息可以在这里找到:community.cloudera.com/t5/Interactive-Short-cycle-SQL/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 2021-04-01
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多