You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by "Lavelle, Shawn" <Sh...@osii.com.INVALID> on 2022/02/21 23:38:51 UTC
Spark-SQL : Getting current user name in UDF
Hello Spark Users,
I have a UDF I wrote for use with Spark-SQL that performs a look up. In that look up, I need to get the current sql user so I can validate their permissions. I was using org.apach.spark.sql.util.Utils.getCurrentUserName() to retrieve the current active user from within the UDF but today I discovered that that call returns a different user based on the context:
select myUDF();
returns the SQL user
select myUDF() from myTable <where clause>;
returns the operating system (application?) user.
I can provide a code example if needed, but it's just calling Utils.getCurrentUserName() from within the UDF code.
Does this sound like expected behavior or a defect? Is there another way I can get the active SQL user inside a UDF?
Thanks in advance,
~ Shawn
PS I can't add username as a parameter to the UDF because I can't rely the user to not submit someone else's username.
[OSI Logo]
Shawn Lavelle
Software Development
OSI Digital Grid Solutions
4101 Arrowhead Drive
Medina, Minnesota 55340-9457
Phone: 763 551 0559
Email: Shawn.Lavelle@osii.com
Website: www.osii.com<https://www.osii.com>
[Emerson Logo]
We are proud to
now be a part of
Emerson.
RE: Spark-SQL : Getting current user name in UDF
Posted by "Lavelle, Shawn" <Sh...@osii.com.INVALID>.
Apologies, this is Spark 3.2.0.
~ Shawn
From: Lavelle, Shawn
Sent: Monday, February 21, 2022 5:39 PM
To: 'user@spark.apache.org' <us...@spark.apache.org>
Subject: Spark-SQL : Getting current user name in UDF
Hello Spark Users,
I have a UDF I wrote for use with Spark-SQL that performs a look up. In that look up, I need to get the current sql user so I can validate their permissions. I was using org.apach.spark.sql.util.Utils.getCurrentUserName() to retrieve the current active user from within the UDF but today I discovered that that call returns a different user based on the context:
select myUDF();
returns the SQL user
select myUDF() from myTable <where clause>;
returns the operating system (application?) user.
I can provide a code example if needed, but it's just calling Utils.getCurrentUserName() from within the UDF code.
Does this sound like expected behavior or a defect? Is there another way I can get the active SQL user inside a UDF?
Thanks in advance,
~ Shawn
PS I can't add username as a parameter to the UDF because I can't rely the user to not submit someone else's username.
[OSI Logo]
Shawn Lavelle
Software Development
OSI Digital Grid Solutions
4101 Arrowhead Drive
Medina, Minnesota 55340-9457
Phone: 763 551 0559
Email: Shawn.Lavelle@osii.com
Website: www.osii.com<https://www.osii.com>
[Emerson Logo]
We are proud to
now be a part of
Emerson.