-
Notifications
You must be signed in to change notification settings - Fork 28.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-44860][SQL] Add SESSION_USER function #42549
Changes from 4 commits
7474177
e7ae20e
5a9469a
bac7824
4366570
a7cbc32
a5fb8ae
0e37ddc
0aca570
917d27b
9de0157
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,6 +302,24 @@ case class CurrentUser() extends LeafExpression with Unevaluable { | |
final override val nodePatterns: Seq[TreePattern] = Seq(CURRENT_LIKE) | ||
} | ||
|
||
// scalastyle:off line.size.limit | ||
@ExpressionDescription( | ||
usage = """_FUNC_() - connected user name.""", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both this comment and the existing comment for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. converting to alias since session_user change is not relevent for non-external functions. |
||
examples = """ | ||
Examples: | ||
> SELECT _FUNC_(); | ||
mockingjay | ||
""", | ||
since = "3.5.0", | ||
group = "misc_funcs") | ||
// scalastyle:on line.size.limit | ||
case class SessionUser() extends LeafExpression with Unevaluable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not register as an alias with CurrentUser There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thank you! |
||
override def nullable: Boolean = false | ||
override def dataType: DataType = StringType | ||
override def prettyName: String = "session_user" | ||
final override val nodePatterns: Seq[TreePattern] = Seq(CURRENT_LIKE) | ||
} | ||
|
||
/** | ||
* A function that encrypts input using AES. Key lengths of 128, 192 or 256 bits can be used. | ||
* For versions prior to JDK 8u161, 192 and 256 bits keys can be used | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,15 +48,16 @@ class MiscFunctionsSuite extends QueryTest with SharedSparkSession { | |
checkAnswer(df.selectExpr("version()"), df.select(version())) | ||
} | ||
|
||
test("SPARK-21957: get current_user in normal spark apps") { | ||
test("SPARK-21957, SPARK-44860: get current_user, session_user in normal spark apps") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
val user = spark.sparkContext.sparkUser | ||
withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") { | ||
val df = sql("select current_user(), current_user, user, user()") | ||
checkAnswer(df, Row(user, user, user, user)) | ||
val df = | ||
sql("select current_user(), current_user, user, user(), session_user(), session_user") | ||
checkAnswer(df, Row(user, user, user, user, user, user)) | ||
} | ||
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true", | ||
SQLConf.ENFORCE_RESERVED_KEYWORDS.key -> "true") { | ||
Seq("user", "current_user").foreach { func => | ||
Seq("user", "current_user", "session_user").foreach { func => | ||
checkAnswer(sql(s"select $func"), Row(user)) | ||
checkError( | ||
exception = intercept[ParseException](sql(s"select $func()")), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done