Uh oh!
There was an error while loading. Please reload this page.
[SPARK-7160][SQL] Support converting DataFrames to typed RDDs. - #5713
[SPARK-7160][SQL] Support converting DataFrames to typed RDDs.#5713rayortigas wants to merge 1 commit into
Conversation
punya
commented
Apr 27, 2015
Is there a way to make the code paths for Scala types ( |
rayortigas
commented
Apr 27, 2015
Hi @punya. Re: Scala and Java types, are you talking about: a) the code similarities between b) the general approach for Scala/Java-Catalyst conversions? I can see that ScalaReflection and JavaTypeInference do similar things, but don't know enough about the design to know whether this is ripe for refactoring. If it hasn't been done or scheduled, maybe someone should do a survey of the current state of things. |
rayortigas
commented
Apr 27, 2015
Now I see a thread on spark-dev (which I just joined) about availability/discoverability of design docs in general. :D If there isn't one for this conversion stuff, it is probably a candidate for a design doc. |
marmbrus
commented
Apr 28, 2015
ok to test |
SparkQA
commented
Apr 28, 2015
Test build #31174 has finished for PR 5713 at commit
|
rxin
commented
May 4, 2015
Thanks for doing this. We are fairly busy with 1.4 release deadline. I'd like to revisit this pull request in Spark 1.5 in the context of making user-defined types and closures more usable in DataFrames. |
rayortigas
commented
May 4, 2015
Thanks for the update, Reynold! I'm just glad it's in the queue. :D Looking forward to the 1.4 release and will keep an eye out for any feedback on this PR... |
JoshRosen
commented
May 17, 2015
Just a head's up: I have a WIP patch which performs a significant refactoring of CatalystTypeConveters (#6222). I think that my patch should make the changes here easier to implement / understand, so I'd love to get your feedback on my proposed refactorings. |
rayortigas
commented
May 18, 2015
@JoshRosen: As you saw from my comment on #6222 I think it looks good. As for this PR, yeah, it should be re-implemented on top of your patch. I think the conversion would still use the type hints given by deftoScala(universeType: universe.Type, @NullablecatalystValue: CatalystType):ScalaTypeor given a default param, e.g.: deftoScala(
@NullablecatalystValue: CatalystType,
universeType: Option[universe.Type] =None
):ScalaTypeAnd In any case, looks doable and should be cleaner. If you like, I can update this PR after you merge your patch. |
rayortigas
commented
Jun 8, 2015
JoshRosen
commented
Jun 8, 2015
Jenkins, this is ok to test. |
SparkQA
commented
Jun 8, 2015
Test build #34456 has finished for PR 5713 at commit
|
3711a3e to
0ee742dCompareSparkQA
commented
Aug 23, 2015
Test build #41415 has finished for PR 5713 at commit
|
rayortigas
commented
Aug 23, 2015
Hi @marmbrus, just repeating what I wrote at https://issues.apache.org/jira/browse/SPARK-7160, I updated this PR to bring it in sync with master. I rebased on yesterday and integrated with Thanks, |
There was a problem hiding this comment.
This is also a kind of a nit, but could you limit the scope of the intercept. I think this is right, but with the extra casts I'm worried the wrong thing might be throwing ClassCastException
marmbrus
commented
Sep 3, 2015
Sorry for the unreasonable delay reviewing this. Over all it looks pretty good to me. I have a few small comments and there is a conflict (which is fortunately easy to resolve this time) |
marmbrus
commented
Sep 3, 2015
Actually, I have one other concern. It doesn't seem that this works in the spark shell. Unfortunately, I'm not sure if there is an easy way around this. |
There was a problem hiding this comment.
We should probably move this into its own suite.
marmbrus
commented
Sep 4, 2015
After spending some more time trying to fix the above issue, I wonder if it wouldn't be better to make this a whole separate code path, instead of trying to handle both cases inside of catalyst converters. That class is already pretty hard to follow and adding a whole set of branches everywhere makes it even worse. Another concern is that the extra branches might affect the performance of the other case. Thoughts? |
rayortigas
commented
Sep 4, 2015
First off, thanks for the code review, Michael. Re: spark-shell, I thought I'd bumped into a known limitation of the REPL (e.g. https://groups.google.com/forum/#!msg/spark-users/bwAmbUgxWrA/HwP4Nv4adfEJ) but I should've raised it, so sorry. The workaround (in my head) was that people should just not use case classes defined within the REPL. Not sure what to do here, I'll have to think about it. Re: a separate code path, I actually had it that way when I submitted the first version of this PR. But then Josh refactored the converters and it seemed reasonable to follow his refactored code paths, since it was easier to track (and probably maintain) the conversions for each type, so that was the second (previous) version of this PR. I can see arguments either way. If we don't expect to add more converters/conversions, then maybe a separate code path would be fine. |
marmbrus
commented
Sep 4, 2015
Regarding the REPL issues, I'm wondering if there isn't some way to handle the common case, where the outer pointer that is getting added to the class isn't actually needed for anything. I was hoping there would be some way to just pass For the separate code path issue. My biggest motivation here is I see a lot of things that aren't great from a performance perspective (the old code is the same). I think if this becomes popular we are going to have to code-generate the conversion functions. Having it separate would make this transition easier. |
rayortigas
commented
Sep 4, 2015
Got it. I'll refactor back to a separate code path then (and address the other issues you identified). After that I'll try to figure out the REPL stuff. If you figure it out, then great. :D Hope that works. |
0ee742d to
6d4bec2Comparerayortigas
commented
Sep 28, 2015
Hi @marmbrus, I updated this PR to use a separate code path as you requested. I don't think I can solve the REPL thing, and I'm at the limits of my understanding of Scala reflection. fwiw, json4s seems to recommend just compiling case classes out-of-band, and then importing them into the REPL, for functionality similar to |
rayortigas
commented
Sep 28, 2015
btw I force-pushed when updating this PR, since the diff would've otherwise looked weird. I rebased on a commit from 9/25. |
There was a problem hiding this comment.
Addressing feedback, this error message provides more details when things go wrong calling the constructor.
SparkQA
commented
Sep 28, 2015
Test build #43055 has finished for PR 5713 at commit
|
FurcyPin
commented
Nov 3, 2015
Hi @rayortigas, I have been working on a similar feature. So far I have something that work similarly but that is a little less easy to use, caseclassDemoCC(int: Int, boolean: Boolean, string: Option[String]) extendsSerializableobjectDemo {
defmain(args: Array[String]):Unit= {
valsc=newSparkContext()
valsqlContext=newSQLContext(sc)
valinputData:Seq[Row] =Seq(
Row(true,1,"A",2.0),
Row(true,2,null,4.0),
Row(false,3,"C",9.0)
)
valschema=StructType(Seq(
StructField("boolean",BooleanType),
StructField("int",IntegerType),
StructField("string",StringType),
StructField("double",DoubleType)
))
valrdd:RDD[Row] = sc.parallelize(inputData,3)
valdf:DataFrame= sqlContext.createDataFrame(rdd,schema)
/* The permutationPlan can be serialized, so we generate it once and for all on the driver. This will perform a preliminary check as well */valpermutationPlan=PermutationPlan[DemoCC](df)
/* The transformer cannot be serialized because TypeTag is not (really) serializable in scala 2.10 */@transient lazyvaltransformer=newRowToCaseClassTransformer[DemoCC](permutationPlan)
/* Using "df.map(transformer)" instead would not work... */valres= df.map{r => transformer(r)}
res.collect.foreach{println}
}
}I tried implementing On the other hand, I tried to be as generic as possible, and my implementation supports I've just found this pull request, and would love to contribute, but I am not sure how to proceed. I would love to discuss this further with you. I am not sure this is the most suitable place to do so. Regards, Furcy PS: thanks for the |
marmbrus
commented
Nov 3, 2015
Hey, I'm really sorry for letting this sit so long. I got wrapped up trying to get ready for Spark 1.6. It would be great if you can look at SPARK-9999, which adds a new method |
There was a problem hiding this comment.
If there are any test cases here that aren't covered by ExpressionEncoderSuite it would be awesome to add them.
marmbrus
commented
Dec 16, 2015
Now that Spark 1.6 is almost release I think we can close this issue. Thanks again for working on it. |
https://issues.apache.org/jira/browse/SPARK-7160
databricks/spark-csv#52
cc:
@rxin (who made the original suggestion)
@vlyubin#5279
@punya#5578
@davies#5350
@marmbrus (ScalaReflection and more)