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

    https://github.com/apache/spark/pull/16493#discussion_r95051546
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala ---
    @@ -565,4 +567,82 @@ class CachedTableSuite extends QueryTest with 
SQLTestUtils with SharedSQLContext
             case i: InMemoryRelation => i
           }.size == 1)
       }
    +
    +  test("SPARK-19093 Caching in side subquery") {
    +    withTempView("t1") {
    +      Seq(1).toDF("c1").createOrReplaceTempView("t1")
    +      spark.catalog.cacheTable("t1")
    +      val cachedPlan =
    +        sql(
    +          """
    +            |SELECT * FROM t1
    +            |WHERE
    +            |NOT EXISTS (SELECT * FROM t1)
    +          """.stripMargin).queryExecution.optimizedPlan
    +      assert(
    +        cachedPlan.collect {
    +          case i: InMemoryRelation => i
    +        }.size == 2)
    +      spark.catalog.uncacheTable("t1")
    +    }
    +  }
    +
    +  test("SPARK-19093 scalar and nested predicate query") {
    +    def getCachedPlans(plan: LogicalPlan): Seq[LogicalPlan] = {
    +      plan collect {
    +        case i: InMemoryRelation => i
    +      }
    +    }
    +    withTempView("t1", "t2", "t3", "t4") {
    +      Seq(1).toDF("c1").createOrReplaceTempView("t1")
    +      Seq(2).toDF("c1").createOrReplaceTempView("t2")
    +      Seq(1).toDF("c1").createOrReplaceTempView("t3")
    +      Seq(1).toDF("c1").createOrReplaceTempView("t4")
    +      spark.catalog.cacheTable("t1")
    +      spark.catalog.cacheTable("t2")
    +      spark.catalog.cacheTable("t3")
    +      spark.catalog.cacheTable("t4")
    +
    +      // Nested predicate subquery
    +      val cachedPlan =
    +        sql(
    +        """
    +          |SELECT * FROM t1
    +          |WHERE
    +          |c1 IN (SELECT c1 FROM t2 WHERE c1 IN (SELECT c1 FROM t3 WHERE 
c1 = 1))
    +        """.stripMargin).queryExecution.optimizedPlan
    +
    +      assert(
    +        cachedPlan.collect {
    +          case i: InMemoryRelation => i
    +        }.size == 3)
    +
    +      // Scalar subquery and predicate subquery
    +      val cachedPlan2 =
    +        sql(
    +          """
    +            |SELECT * FROM (SELECT max(c1) FROM t1 GROUP BY c1)
    +            |WHERE
    +            |c1 = (SELECT max(c1) FROM t2 GROUP BY c1)
    +            |OR
    +            |EXISTS (SELECT c1 FROM t3)
    +            |OR
    +            |c1 IN (SELECT c1 FROM t4)
    +          """.stripMargin).queryExecution.optimizedPlan
    +
    +
    +      val cachedRelations = 
scala.collection.mutable.MutableList.empty[Seq[LogicalPlan]]
    +      cachedRelations += getCachedPlans(cachedPlan2)
    +      cachedPlan2 transformAllExpressions {
    +        case e: SubqueryExpression => cachedRelations += 
getCachedPlans(e.plan)
    +          e
    +      }
    +      assert(cachedRelations.flatten.size == 4)
    +
    +      spark.catalog.uncacheTable("t1")
    +      spark.catalog.uncacheTable("t2")
    +      spark.catalog.uncacheTable("t3")
    +      spark.catalog.uncacheTable("t4")
    --- End diff --
    
    How about this? @dilipbiswal 


---
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