You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by gatorsmile <gi...@git.apache.org> on 2015/12/01 02:48:20 UTC

[GitHub] spark pull request: [SPARK-11905] [SQL] Support Persist/Cache and ...

Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9889#discussion_r46231420
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/CacheSuite.scala ---
    @@ -0,0 +1,89 @@
    +/*
    + * 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 CacheSuite 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))
    +
    +    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))
    +
    +    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.")
    +  }
    +
    +  ignore("persist and then map/filter with lambda functions") {
    --- End diff --
    
    Just opened a new JIRA https://issues.apache.org/jira/browse/SPARK-12061


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org