Skip to content
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-19254][SQL] Support Seq, Map, and Struct in functions.lit #16610

Closed
wants to merge 5 commits into from

Conversation

maropu
Copy link
Member

@maropu maropu commented Jan 17, 2017

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 lit2 with TypeTag for avoiding type erasure.

How was this patch tested?

Added tests in LiteralExpressionSuite

@maropu
Copy link
Member Author

maropu commented Jan 17, 2017

Since spark possibly supports comparable MapType in future (#15970), it might also needs to support this type in functions.lit. However, Since I exactly know that adding new IFs is much arguable, anyone gives me some insights about this?

@SparkQA
Copy link

SparkQA commented Jan 17, 2017

Test build #71473 has finished for PR 16610 at commit 6a02490.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Feb 4, 2017

@hvanhovell Could you give me some insights?

Copy link
Contributor

@hvanhovell hvanhovell left a 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 = {
Copy link
Contributor

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

Copy link
Member Author

@maropu maropu Feb 9, 2017

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.

@@ -153,6 +154,12 @@ object Literal {
Literal(CatalystTypeConverters.convertToCatalyst(v), dataType)
}

def create[T : TypeTag](v: T): Literal = {
val ScalaReflection.Schema(dataType, _) = ScalaReflection.schemaFor[T]
val convert = CatalystTypeConverters.createToCatalystConverter(dataType)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok.

Copy link
Contributor

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 :)

Copy link
Member Author

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 ;)

@SparkQA
Copy link

SparkQA commented Feb 9, 2017

Test build #72652 has finished for PR 16610 at commit ca2e07f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 9, 2017

Test build #72659 has finished for PR 16610 at commit 8d26e8b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Feb 20, 2017

ping

* @group normal_funcs
* @since 2.2.0
*/
def typedLit[T : TypeTag](literal: T): Column = {
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll update

Copy link
Member Author

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

@SparkQA
Copy link

SparkQA commented Feb 20, 2017

Test build #73161 has finished for PR 16610 at commit 4f65fe2.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 20, 2017

Test build #73162 has finished for PR 16610 at commit 5eeba65.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 20, 2017

Test build #73165 has finished for PR 16610 at commit 028b19b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member Author

maropu commented Mar 1, 2017

ping

val literalExpr = Literal(literal)
Column(literalExpr)
/**
* Creates a [[Column]] of literal value.
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll update

Copy link
Member Author

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 {
Copy link
Contributor

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?

@@ -99,6 +99,8 @@ object functions {
* The passed in object is returned directly if it is already a [[Column]].
* If the object is a Scala Symbol, it is converted into a [[Column]] also.
* Otherwise, a new [[Column]] is created to represent the literal value.
* Different from [[lit]], this functions can handle all the types in Scala,
Copy link
Contributor

@hvanhovell hvanhovell Mar 2, 2017

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, updated. Thanks!

@SparkQA
Copy link

SparkQA commented Mar 2, 2017

Test build #73752 has finished for PR 16610 at commit 93639d1.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Mar 2, 2017

Test build #73757 has finished for PR 16610 at commit af2d70a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@hvanhovell
Copy link
Contributor

LGTM - merging to master. Thanks!

@asfgit asfgit closed this in 14bb398 Mar 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants