在 hive 中,有没有办法指定在哪些列之间添加新列? [英] In hive, is there a way to specify between which columns to add a new column to?

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

问题描述

我能做到

<代码>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 列设为表中的第一列,使用 change columnFIRST 子句:

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.

同样,如果您想将指定的列移动到任何其他列之后,您可以使用 After 而不是 first.就像说,我想在 user_id 列之后移动 dob 列.那么我的命令是:

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.

这篇关于在 hive 中,有没有办法指定在哪些列之间添加新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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