Harinder
Harinder

Reputation: 11944

Get user running HIVE job?

I am running a HIVE job with my UDF extended class. I want to get the name of the user that submits my job, so i am using

System.getProperty("user.name");

to get the username but the problem is this is returning user mapred, and on the jobtracker the job is showing user name hdfs. I am currentely logged in as hdfs so the job is submitted by hdfs, so y is

  System.getProperty("user.name");

retuning an incorrect value:- mapred

Can anyone please tell me why this is happening and any alternate of getting the user name in the evaluate method of UDF

Upvotes: 8

Views: 2350

Answers (3)

user3263540
user3263540

Reputation: 25

You need to pass the username as a parameter from outside. Then use it inside UDF class

Upvotes: 1

Binary01
Binary01

Reputation: 695

I think you can look into this Job History API to get the username of the job submitter. I hope this may help.Job History link

Upvotes: 1

Donald Miner
Donald Miner

Reputation: 39903

Assuming you don't have Kerberos authentication enabled, the system tasks will be ran as the same user the TaskTrackers are running as (in this case mapred, which is pretty common). This is because the TaskTrackers are running your process, not you.

Sorry, I can only answer half of your question. I don't know how to get the information from a Hive UDF.


Considering all of your UDF calls to the job have the same user... just "inject" it from outside of the script somewhere. For example, you can just add whoami to your invocation of the sql:

hive -e "select a.col, '`whoami`' from tab1 a"

Besides, just getting it once is probably better than connecting to the JobTracker every single time the UDF runs.

Upvotes: 2

Related Questions