-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18717][SQL] Make code generation for Scala Map work with immutable.Map also #16161
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
|
Test build #69696 has finished for PR 16161 at commit
|
| StaticInvoke( | ||
| ArrayBasedMapData.getClass, | ||
| ObjectType(classOf[Map[_, _]]), | ||
| ObjectType(classOf[scala.collection.immutable.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.
I don't know this bit well, but the comments on the JIRA indicate that immutable maps aren't supported. However, this change should be a no-op because Predef.Map is already immutable.Map right -- how does this address it?
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.
@srowen scala.collection.Map is imported at the beginning of RowEncoder and ScalaReflection.
|
cc @cloud-fan |
|
can you highlight your approach to fix this bug? It looks to me that this is not a general fix, e.g. |
|
The approach is to change the deserializer (via |
|
Test build #69741 has finished for PR 16161 at commit
|
|
OK, it sounds like what you're doing is unsupported at the moment and this doesn't change that, and you have a workaround. Is this worth merging? |
|
Right now it's not supported to have the following: (using the scala Predef version of Map) The documented way to do this is: and it works fine. However if someone did not read the documentation carefully and used the former, instead of a reasonable error they get a compile error on the code spark generates. Therefore IMHO there are two options:
If the consensus is that this PR is not worth it then I'll be happy to work on option 2. But in my opinion as a Spark user option 1 is better. |
|
option 1 is better, but this PR only adds the support for I think we need a general solution to support custom collection type. |
|
I would be happy to create a seperate PR for adding support for |
Yea, and a general solution would be, remember the original type and create that type when converting catalyst value to external value. But this may be hard to implement, it may worth to merge this simple PR, as the |
…-codegen # Conflicts: # sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala
|
Test build #70027 has finished for PR 16161 at commit
|
|
thanks, merging to master! |
…able.Map also ## What changes were proposed in this pull request? Fixes compile errors in generated code when user has case class with a `scala.collections.immutable.Map` instead of a `scala.collections.Map`. Since ArrayBasedMapData.toScalaMap returns the immutable version we can make it work with both. ## How was this patch tested? Additional unit tests. Author: Andrew Ray <[email protected]> Closes apache#16161 from aray/fix-map-codegen.
…able.Map also ## What changes were proposed in this pull request? Fixes compile errors in generated code when user has case class with a `scala.collections.immutable.Map` instead of a `scala.collections.Map`. Since ArrayBasedMapData.toScalaMap returns the immutable version we can make it work with both. ## How was this patch tested? Additional unit tests. Author: Andrew Ray <[email protected]> Closes apache#16161 from aray/fix-map-codegen.
|
Shall we backport this to branch-2.1? I'd consider this as a bug because the following snippet fail in Spark 2.1: case class Wrapper1(value: Option[Map[String, String]])
case class Wrapper2(value: Map[String, String])
val ds1 = Seq.empty[Wrapper1].toDS() // Fail
val ds2 = Seq.empty[Wrapper2].toDS() // Succeed |
|
I'm fine to backport this |
|
Thanks. Backported to branch-2.1. |
…able.Map also ## What changes were proposed in this pull request? Fixes compile errors in generated code when user has case class with a `scala.collections.immutable.Map` instead of a `scala.collections.Map`. Since ArrayBasedMapData.toScalaMap returns the immutable version we can make it work with both. ## How was this patch tested? Additional unit tests. Author: Andrew Ray <[email protected]> Closes #16161 from aray/fix-map-codegen. (cherry picked from commit 46d30ac) Signed-off-by: Cheng Lian <[email protected]>
What changes were proposed in this pull request?
Fixes compile errors in generated code when user has case class with a
scala.collections.immutable.Mapinstead of ascala.collections.Map. Since ArrayBasedMapData.toScalaMap returns the immutable version we can make it work with both.How was this patch tested?
Additional unit tests.