Support Questions

Find answers, ask questions, and share your expertise

How to change the ownership of a existing table in hive

avatar
Contributor

Hi Team,

I have a table called 'test' and its owner is 'ben', I need to change the ownership of the same table from 'ben' to 'sam' and i don't have login access to sam.

How can i achieve this , Is there any possibility to change the ownership or is there any command to change the ownership

Regards,

Mathivanan

3 REPLIES 3

avatar

Hey @Mathi Murugan!
Hm, could you share with us more details? Is your environment secure (kerberos, ranger, knox, hdfs acl)?
If it isn't, then try to add permission to your user through chmod (to have write/read permissions) or take the ownership through chown, would be smtg like this:

hdfs dfs -chmod - R 777 /apps/hive/warehouse/salaries --TABLE SALARIES
hdfs dfs -chown -R hive:hadoop /apps/hive/warehouse/salaries --Changing the ownership from root to hive
Just remember that you'll need to run these commands as hdfs user or have the same permission as hdfs.

Hope this helps!

avatar
New Contributor

Hdfs chown command would be ok, but Hive meta also maintains owner information such as tbls.owner in mysql. I think it is better to use Hive command if provided.

avatar
Master Mentor

@Mathi Murugan

I see that currently ALTER (DATABASE|SCHEMA) database_name SET OWNER [USER|ROLE] user_or_role; does not give the desired fine-grained option for only a specific table in a schema/database, so I think the best option would be to use Ranger and give a select privilege on the particular database or underlying table to the new user who can then issue a Create Table As Select (CTAS) which will automatically change the ownership to the issuer of the CTAS.

HTH