Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user running HIVE job?

Tags:

java

hadoop

hive

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

like image 508
Harinder Avatar asked Dec 10 '13 11:12

Harinder


People also ask

How do I get users on Hive?

You can use logged_in_user() which returns current user name from the session state. This is the username provided when connecting to Hive.

What is Hive user?

Hive allows users to read, write, and manage petabytes of data using SQL. Hive is built on top of Apache Hadoop, which is an open-source framework used to efficiently store and process large datasets.

What is a Hive table?

Relational databases, or RDBMS, is a database that stores data in a structured format with rows and columns, a structured form called “tables.” Hive, on the other hand, is a data warehousing system that offers data analysis and queries.


2 Answers

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.

like image 166
Donald Miner Avatar answered Nov 07 '22 03:11

Donald Miner


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

like image 1
Binary01 Avatar answered Nov 07 '22 05:11

Binary01