-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-11905] [SQL] Support Persist/Cache and Unpersist in Dataset APIs #9889
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
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
01e4cdf
Merge remote-tracking branch 'upstream/master'
gatorsmile 6835704
Merge remote-tracking branch 'upstream/master'
gatorsmile 9180687
Merge remote-tracking branch 'upstream/master'
gatorsmile b38a21e
SPARK-11633
gatorsmile d2b84af
Merge remote-tracking branch 'upstream/master' into joinMakeCopy
gatorsmile fda8025
Merge remote-tracking branch 'upstream/master'
gatorspark ac0dccd
Merge branch 'master' of https://github.com/gatorsmile/spark
gatorspark 6e0018b
Merge remote-tracking branch 'upstream/master'
0546772
converge
gatorsmile b37a64f
converge
gatorsmile f061671
Support Persist/Cache and Unpersist in DataSet APIs
gatorsmile 88d5e9d
Merge remote-tracking branch 'upstream/master' into top
gatorsmile c135e1f
update the @since
gatorsmile 661260b
Merge remote-tracking branch 'upstream/master'
gatorsmile 2517777
adding more test cases
gatorsmile aa5dc52
Merge remote-tracking branch 'upstream/master' into top
gatorsmile 2dfa0fd
Merge remote-tracking branch 'upstream/master'
gatorsmile c4489ed
Merge remote-tracking branch 'upstream/master' into top
gatorsmile 683fa6f
resolved all the comments
gatorsmile 1c82396
Merge remote-tracking branch 'upstream/master' into top
gatorsmile d929d9b
Merge remote-tracking branch 'upstream/master'
gatorsmile 92ede39
Merge branch 'top' into persistDSmerge
gatorsmile 8071d30
Merge remote-tracking branch 'upstream/master' into persistDSmerge
gatorsmile b9518ee
updated the codes based on the review comments from Michale Armbrust.
gatorsmile b8d287a
Changed the name from CacheSuite.scala to DatasetCacheSuite.scala
gatorsmile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
sql/core/src/test/scala/org/apache/spark/sql/DatasetCacheSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql | ||
|
|
||
| import scala.language.postfixOps | ||
|
|
||
| import org.apache.spark.sql.functions._ | ||
| import org.apache.spark.sql.test.SharedSQLContext | ||
|
|
||
|
|
||
| class DatasetCacheSuite extends QueryTest with SharedSQLContext { | ||
| import testImplicits._ | ||
|
|
||
| test("persist and unpersist") { | ||
| val ds = Seq(("a", 1) , ("b", 2), ("c", 3)).toDS().select(expr("_2 + 1").as[Int]) | ||
| val cached = ds.cache() | ||
| // count triggers the caching action. It should not throw. | ||
| cached.count() | ||
| // Make sure, the Dataset is indeed cached. | ||
| assertCached(cached) | ||
| // Check result. | ||
| checkAnswer( | ||
| cached, | ||
| 2, 3, 4) | ||
| // Drop the cache. | ||
| cached.unpersist() | ||
| assert(!sqlContext.isCached(cached), "The Dataset should not be cached.") | ||
| } | ||
|
|
||
| test("persist and then rebind right encoder when join 2 datasets") { | ||
| val ds1 = Seq("1", "2").toDS().as("a") | ||
| val ds2 = Seq(2, 3).toDS().as("b") | ||
|
|
||
| ds1.persist() | ||
| assertCached(ds1) | ||
| ds2.persist() | ||
| assertCached(ds2) | ||
|
|
||
| val joined = ds1.joinWith(ds2, $"a.value" === $"b.value") | ||
| checkAnswer(joined, ("2", 2)) | ||
| assertCached(joined, 2) | ||
|
|
||
| ds1.unpersist() | ||
| assert(!sqlContext.isCached(ds1), "The Dataset ds1 should not be cached.") | ||
| ds2.unpersist() | ||
| assert(!sqlContext.isCached(ds2), "The Dataset ds2 should not be cached.") | ||
| } | ||
|
|
||
| test("persist and then groupBy columns asKey, map") { | ||
| val ds = Seq(("a", 10), ("a", 20), ("b", 1), ("b", 2), ("c", 1)).toDS() | ||
| val grouped = ds.groupBy($"_1").keyAs[String] | ||
| val agged = grouped.mapGroups { case (g, iter) => (g, iter.map(_._2).sum) } | ||
| agged.persist() | ||
|
|
||
| checkAnswer( | ||
| agged.filter(_._1 == "b"), | ||
| ("b", 3)) | ||
| assertCached(agged.filter(_._1 == "b")) | ||
|
|
||
| ds.unpersist() | ||
| assert(!sqlContext.isCached(ds), "The Dataset ds should not be cached.") | ||
| agged.unpersist() | ||
| assert(!sqlContext.isCached(agged), "The Dataset agged should not be cached.") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 comment style here is off and we should actually have a description. Could we just move the functions/docs from DataFrame to Queryable?
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.
So far, we are unable to move the functions to
Queryablebecause the types of the returned values are different. I just added the descriptions in bothDataFrameandDataset. Hopefully, it resolves your concern. Thanks!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.
@marmbrus moving functions into Queryable actually breaks both scaladoc and javadoc.
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.
@rxin I think thats only because we explicitly exclude execution from scaladoc. Maybe we should move queryable? or don't exclude that class. I don't want to duplicate a ton of docs.