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

    https://github.com/apache/spark/pull/17330#discussion_r106795788
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala ---
    @@ -655,6 +663,148 @@ class CachedTableSuite extends QueryTest with 
SQLTestUtils with SharedSQLContext
         }
       }
     
    +  test("SPARK-19993 subquery caching") {
    +    withTempView("t1", "t2") {
    +      Seq(1).toDF("c1").createOrReplaceTempView("t1")
    +      Seq(1).toDF("c1").createOrReplaceTempView("t2")
    +
    +      val ds1 =
    +        sql(
    +          """
    +            |SELECT * FROM t1
    +            |WHERE
    +            |NOT EXISTS (SELECT * FROM t1)
    +          """.stripMargin)
    +      assert(getNumInMemoryRelations(ds1) == 0)
    +
    +      ds1.cache()
    +
    +      val cachedDs =
    +        sql(
    +          """
    +            |SELECT * FROM t1
    +            |WHERE
    +            |NOT EXISTS (SELECT * FROM t1)
    +          """.stripMargin)
    +      assert(getNumInMemoryRelations(cachedDs) == 1)
    +
    +      // Additional predicate in the subquery plan should cause a cache 
miss
    +      val cachedMissDs =
    +        sql(
    +          """
    +            |SELECT * FROM t1
    +            |WHERE
    +            |NOT EXISTS (SELECT * FROM t1 where c1 = 0)
    +          """.stripMargin)
    +      assert(getNumInMemoryRelations(cachedMissDs) == 0)
    +
    +      // Simple correlated predicate in subquery
    +      val ds2 =
    +        sql(
    +          """
    +            |SELECT * FROM t1
    +            |WHERE
    +            |t1.c1 in (SELECT t2.c1 FROM t2 where t1.c1 = t2.c1)
    +          """.stripMargin)
    +      assert(getNumInMemoryRelations(ds2) == 0)
    +
    +      ds2.cache()
    +
    +      val cachedDs2 =
    +        sql(
    +          """
    +            |SELECT * FROM t1
    +            |WHERE
    +            |t1.c1 in (SELECT t2.c1 FROM t2 where t1.c1 = t2.c1)
    +          """.stripMargin)
    +
    +      assert(getNumInMemoryRelations(cachedDs2) == 1)
    +
    +      spark.catalog.cacheTable("t1")
    +      ds1.unpersist()
    --- End diff --
    
    @gatorsmile Sure. will do.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to