Uh oh!
There was an error while loading. Please reload this page.
[SPARK-24762][SQL] Enable Option of Product encoders - #21732
Conversation
SparkQA
commented
Jul 9, 2018
Test build #92729 has finished for PR 21732 at commit
|
viirya
commented
Jul 9, 2018
retest this please. |
SparkQA
commented
Jul 9, 2018
Test build #92739 has finished for PR 21732 at commit
|
viirya
commented
Jul 9, 2018
retest this please. |
SparkQA
commented
Jul 9, 2018
Test build #92748 has finished for PR 21732 at commit
|
viirya
commented
Jul 9, 2018
I'm wondering should we add encoders of Option of Product into object |
viirya
commented
Jul 9, 2018
cloud-fan
commented
Jul 10, 2018
how about we treat the top level |
viirya
commented
Jul 10, 2018
It sounds like much more behavior changing? |
cloud-fan
commented
Jul 10, 2018
yes it is, but it makes the encoder framework more consistent. And making a failure case into runnable is a safe behavior change. |
viirya
commented
Jul 17, 2018
Non top-level and top-level encoders for As you said, top-level For non top-level one, we can't apply the same change because it is already a struct column. We don't want to change current behavior of it from a struct column to a struct column of a struct column. This means that we can remove the limitation of top-level @cloud-fan Do you want to incorporate top-level |
viirya
commented
Jul 19, 2018
ping @cloud-fan |
cloud-fan
commented
Jul 19, 2018
Can we treat them the same but at the end of encoder creation, we flatten the |
viirya
commented
Jul 19, 2018
At the end of encoder creation? You mean at the end of calling |
| } | ||
| case class OptionBooleanIntAggregator(colName: String) | ||
| extends Aggregator[Row, Option[(Boolean, Int)], Option[(Boolean, Int)]] { |
There was a problem hiding this comment.
what's the expected schema after we apply an aggregator with Option[Product] as buffer/output?
There was a problem hiding this comment.
For a non top-level encoder, the output schema of Option[Product] should be struct column.
There was a problem hiding this comment.
assuming non top level, Option[Product] is same as Product?
There was a problem hiding this comment.
Yes. For non top level, [Option[Product] is same as Product. The difference is additional WrapOption and UnwrapOption around expressions.
viirya
commented
Jul 26, 2018
cloud-fan
commented
Jul 27, 2018
Again, can we always support |
viirya
commented
Jul 27, 2018
@cloud-fan We can. Just wondering if you think it is good to have that in this PR too? |
cloud-fan
commented
Jul 28, 2018
This PR is just a special handling for |
b6c6e9f to
4f5628dCompareSparkQA
commented
Jul 30, 2018
Test build #93763 has finished for PR 21732 at commit
|
SparkQA
commented
Jul 30, 2018
Test build #93762 has finished for PR 21732 at commit
|
SparkQA
commented
Jul 30, 2018
Test build #93764 has finished for PR 21732 at commit
|
SparkQA
commented
Jul 30, 2018
Test build #93765 has finished for PR 21732 at commit
|
cloud-fan
commented
Nov 21, 2018
last comment, LGTM otherwise |
SparkQA
commented
Nov 22, 2018
Test build #99177 has finished for PR 21732 at commit
|
SparkQA
commented
Nov 22, 2018
Test build #99178 has finished for PR 21732 at commit
|
SparkQA
commented
Nov 24, 2018
Test build #99222 has finished for PR 21732 at commit
|
cloud-fan
commented
Nov 26, 2018
thanks, merging to master, great work! |
| * flattened to top-level row, because in Spark SQL top-level row can't be null. This method | ||
| * returns true if `T` is serialized as struct and is not `Option` type. | ||
| */ | ||
| def isSerializedAsStructForTopLevel: Boolean = isSerializedAsStruct && !isOptionType |
There was a problem hiding this comment.
can you send a followup PR to inline isOptionType if it's only used here?
## What changes were proposed in this pull request? This is follow-up of #21732. This patch inlines `isOptionType` method. ## How was this patch tested? Existing tests. Closes#23143 from viirya/SPARK-24762-followup. Authored-by: Liang-Chi Hsieh <viirya@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
HyukjinKwon
commented
Dec 27, 2018
Hm .. sorry for joining this party late. I was reading and testing it by myself. scala>Seq((1, "a"), (2, "b")).toDF.show()
+---+---+| _1| _2|+---+---+|1| a||2| b|+---+---+
scala>Seq(1, 2).toDF.show()
+-----+|value|+-----+|1||2|+-----+scala>Seq(Some((1, "a")), Some((2, "b"))).toDF.show()
+------+| value|+------+|[1, a]||[2, b]|+------+
scala>Seq(Some(1), Some(2)).toDF.show()
+-----+|value|+-----+|1||2|+-----+I think this behaviour can be actually controversial. If we interpret |
commented
Dec 27, 2018
@HyukjinKwon What do you mean we interpret Option as Tuple1? |
commented
Dec 27, 2018
|
commented
Dec 27, 2018 •
re: #21732 (comment) I was thinking both below Seq(Some((1, "a")), Some((2, "b"))).toDF.show()
Seq((1, "a"), (2, "b")).toDF.show()should produce the same result since Seq(Some(1), Some(2)).toDF.show()
Seq(1, 2).toDF.show()produces the same results anyhow. Apparently this looks why it has been disallowed. |
commented
Dec 27, 2018 •
Thanks for @cloud-fan's explanation. So I think @HyukjinKwon you mean why we interpret For the following we can't produce the same result since top-level null row is not allowed in Spark. |
commented
Dec 27, 2018 •
Yea, then why did we allow the different result? I was thinking we're going to allow this only for aggregators. |
commented
Dec 27, 2018
@HyukjinKwon there was a comment #21732 (comment) for it. This was originally to make |
commented
Dec 27, 2018
Hm, for aggregators, I would consider this as non root level. Looks they use the same encoder but can't be the same. |
commented
Dec 28, 2018
@HyukjinKwon If we can go back, I'd say we should not have this optimization which flattens top-level Ideally It's too late to revert that optimization, I think we should accept this special case. |
commented
Dec 28, 2018
I didn't mean that we should revert .. was just checking the PRs in my queue and was just curious. I mean, I understood the limitation but failed to understand why it's been allowed. We exposed |
commented
Dec 28, 2018
Ah, but you're saying |
commented
Dec 28, 2018
Yes, top-level |
What changes were proposed in this pull request?
SparkSQL doesn't support to encode
Option[Product]as a top-level row now, because in SparkSQL entire top-level row can't be null.However for use cases like Aggregator, it is reasonable to use
Option[Product]as buffer and output column types. Due to above limitation, we don't do it for now.This patch proposes to encode
Option[Product]at top-level as single struct column. So we can work around the issue that entire top-level row can't be null.To summarize encoding of
ProductandOption[Product].For
Product, 1. at root level, the schema is all fields are flatten it into multiple columns. TheProductcan't be null, otherwise it throws an exception.Productis a struct type column.For
Option[Product], 1. it was not supported at root level. After this change, it is a struct type column.Option[Product]as buffer/output column type.The buffer and output type of
OptionBooleanIntAggregatoris bothOption[(Boolean, Int).How was this patch tested?
Added test.