-
Couldn't load subscription status.
- Fork 28.9k
[SPARK-19254][SQL] Support Seq, Map, and Struct in functions.lit #16610
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
Conversation
|
Since spark possibly supports comparable |
|
Test build #71473 has finished for PR 16610 at commit
|
|
@hvanhovell Could you give me some insights? |
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.
Overal this seem pretty good. I just have some reservations about the lit2 function.
| * @group normal_funcs | ||
| * @since 2.2.0 | ||
| */ | ||
| def lit2[T : TypeTag](literal: T): Column = { |
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.
Do you think there is a way we can actually avoid this?
If we must why not name it typedLit?
cc @cloud-fan
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.
I just named this without strong thoughts, so typedLit looks good to me.
|
|
||
| def create[T : TypeTag](v: T): Literal = { | ||
| val ScalaReflection.Schema(dataType, _) = ScalaReflection.schemaFor[T] | ||
| val convert = CatalystTypeConverters.createToCatalystConverter(dataType) |
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.
Call create(v, dataType) instead?
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.
Aha, you're right. I'll fix this.
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, my bad. I found the code you suggested made some tests fail. Actually, CatalystTypeConverters.convertToCatalyst does not do the same thing with CatalystTypeConverters.createToCatalystConverter(dataType). For instance, CatalystTypeConverters.convertToCatalyst does not convert TupleX to GenericInternalRow.
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.
Ah ok.
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.
Shouldn't you be going to talks :)
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.
haha, actually I'm joining the dev talk now ;)
|
Test build #72652 has finished for PR 16610 at commit
|
|
Test build #72659 has finished for PR 16610 at commit
|
|
ping |
| * @group normal_funcs | ||
| * @since 2.2.0 | ||
| */ | ||
| def typedLit[T : TypeTag](literal: T): Column = { |
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.
cc @cloud-fan WDYT?
| * @since 2.2.0 | ||
| */ | ||
| def typedLit[T : TypeTag](literal: T): Column = { | ||
| literal match { |
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.
This match statement is slightly hair raising (I know this is copied from lit(..)), how about:
literal match {
case c: Column => c
case s: Symbol => new ColumnName(s.name)
case _ => Column(Literal.create(literal))
}You could also consider mapping the untyped lit(..) function to this function.
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.
okay, I'll update
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.
@hvanhovell How about the fix? 4f65fe2
|
Test build #73161 has finished for PR 16610 at commit
|
|
Test build #73162 has finished for PR 16610 at commit
|
|
Test build #73165 has finished for PR 16610 at commit
|
|
ping |
| val literalExpr = Literal(literal) | ||
| Column(literalExpr) | ||
| /** | ||
| * Creates a [[Column]] of literal value. |
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.
We should explain when you want to use this method instead of lit.
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.
okay, I'll update
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.
updated
| * @group normal_funcs | ||
| * @since 2.2.0 | ||
| */ | ||
| def typedLit[T : TypeTag](literal: T): Column = literal match { |
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.
cc @cloud-fan wdyt about the naming?
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.
The difference between this function and [[lit]] is that this function can handle parameterized scala types e.g.: List, Seq and Map.
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.
okay, updated. Thanks!
|
Test build #73752 has finished for PR 16610 at commit
|
|
Test build #73757 has finished for PR 16610 at commit
|
|
LGTM - merging to master. Thanks! |
What changes were proposed in this pull request?
This pr is to support Seq, Map, and Struct in functions.lit; it adds a new IF named
lit2withTypeTagfor avoiding type erasure.How was this patch tested?
Added tests in
LiteralExpressionSuite