-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-37646][SQL]Avoid touching Scala reflection APIs in the lit function #34901
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -932,7 +932,19 @@ class ColumnExpressionSuite extends QueryTest with SharedSparkSession { | |
| testData2.collect().toSeq.map(r => Row(r.getInt(0) ^ r.getInt(1) ^ 39))) | ||
| } | ||
|
|
||
| test("SPARK-37646: lit") { | ||
| assert(lit($"foo") == $"foo") | ||
|
Member
Author
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. I don't find any unit tests like this. So just add simple tests to cover 3 cases in the code. |
||
| assert(lit('foo) == $"foo") | ||
| assert(lit(1) == Column(Literal(1))) | ||
| assert(lit(null) == Column(Literal(null, NullType))) | ||
| } | ||
|
|
||
| test("typedLit") { | ||
| assert(typedLit($"foo") == $"foo") | ||
| assert(typedLit('foo) == $"foo") | ||
| assert(typedLit(1) == Column(Literal(1))) | ||
| assert(typedLit[String](null) == Column(Literal(null, StringType))) | ||
|
Member
Author
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. I was trying to switch the order in and then realized this would break this use case. So just added this test to ensure we won't make such change in future. |
||
|
|
||
| val df = Seq(Tuple1(0)).toDF("a") | ||
| // Only check the types `lit` cannot handle | ||
| checkAnswer( | ||
|
|
||
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.
Can you pass a column as a literal? if so, does it work this way currently?
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.
Yep. I just inlined
typedlit(literal)and changedColumn(Literal.create(literal))toColumn(Literal(literal)). I don't expect there is any behavior difference.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.
Oh OK. That just seems odd that it's allowed? a literal that isn't a literal
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.
Agree it's odd. I don't know the context either 😄