在蜂巢中,是否有一种方法可以指定在哪个列之间添加新列? [英] In hive, is there a way to specify between which columns to add a new column to?

查看:80
本文介绍了在蜂巢中,是否有一种方法可以指定在哪个列之间添加新列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以做到

ALTER TABLE table_name ADD COLUMNS (user_id BIGINT)

ALTER TABLE table_name ADD COLUMNS (user_id BIGINT)

在非分区列的末尾和分区列之前添加一个新列.

to add a new column to the end of my non-partition columns and before my partition columns.

是否可以将新列添加到非分区列中的任何位置? 例如,我想将此新列user_id用作表的第一列

Is there any way to add a new column to anywhere among my non-partition columns? For example, I would like to put this new column user_id as the first column of my table

推荐答案

是的,只有在使用 CHANGE COLUMN

Yes it is possible to change the location of columns but only after adding it in the table using CHANGE COLUMN

以您为例,首先使用以下命令将user_id列添加到表中:

In your case, first add the column user_id to the table with below command:

ALTER TABLE table_name ADD COLUMNS (user_id BIGINT);

现在要使user_id列成为表的第一列,请在 FIRST 子句中使用 change column :

Now to make user_id column as the first column in your table use change column with FIRST clause:

 ALTER TABLE table_name CHANGE COLUMN user_id user_id BIGINT first;

这会将user_id列移到第一位置.

This will move the user_id column to the first position.

类似地,如果要将指定的列移动到其他任何列之后,可以使用之后而不是第一.就像我说的那样,我想将dob列移到user_id列之后.然后我的命令将是:

Similarly you can use After instead of first if you want to move the specified column after any other column. Like say, I want to move dob column after user_id column. Then my command would be:

ALTER TABLE table_name CHANGE COLUMN dob dob date AFTER user_id;

请注意,此命令仅更改元数据.如果要移动列,则数据必须已经与新模式匹配,或者必须通过其他方式将其更改为匹配.

Please note that this commands changes metadata only. If you are moving columns, the data must already match the new schema or you must change it to match by some other means.

这篇关于在蜂巢中,是否有一种方法可以指定在哪个列之间添加新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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