Hiba Rehman
Hiba Rehman

Reputation: 137

How to overwrite into local directory from hive table?

I am using cloudera and I run the query in hive

insert overwrite local directory '/home/cloudera/Documents/test' row 
format delimited fields terminated by ',' select * from stocks sort 
by close desc;

But I gives me the error which is

Copying data to local directory /home/cloudera/Documents/test
Failed with exception Unable to delete the existing destination 
directory: /home/cloudera/Documents/test
FAILED: Execution Error, return code 1 from 
org.apache.hadoop.hive.ql.exec.MoveTask

Upvotes: 1

Views: 729

Answers (1)

Secespitus
Secespitus

Reputation: 709

The user that executes the command needs to have write permissions on the parent directory, in this case /home/cloudera/Documents, to delete the whole directory and create a new one. Furthermore the user needs to have the write permission to delete all files currently present in the directory.

  • Check which user is executing the command
  • Make sure that the parent directory /home/cloudera/Documents has permission settings that allow the user to write
  • Make sure that the user has write permission on all files inside /home/cloudera/Documents/test

To make sure that this should work you can:

  • Become the user that is executing the command
  • Navigate to /home/cloudera/Documents/test and delete all files
  • Navigate to /home/cloudera/Documents and delete the directory "test"

If this works the query will work. If it doesn't you need to check which particular permission setting is messing with your plan.

Upvotes: 2

Related Questions