Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix typo
  • Loading branch information
cloud-fan committed Jul 7, 2017
commit 479e53c20303d55a04fd5e98440275332ebb3e5e
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with Logging {
*/
override def visitAliasedQuery(ctx: AliasedQueryContext): LogicalPlan = withOrigin(ctx) {
val alias = if (ctx.strictIdentifier == null) {
// For un-aliased subqueries, ues a default alias name that is not likely to conflict with
// For un-aliased subqueries, use a default alias name that is not likely to conflict with
// normal subquery names, so that parent operators can only access the columns in subquery by
// unqualified names. Users can still use this special qualifier to access columns if they
// know it, but that's not recommended.
Expand Down
72 changes: 21 additions & 51 deletions sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,15 @@ class CachedTableSuite extends QueryTest with SQLTestUtils with SharedSQLContext
Seq(1).toDF("c1").createOrReplaceTempView("t1")
Seq(2).toDF("c1").createOrReplaceTempView("t2")

sql(
val sql1 =
"""
|SELECT * FROM t1
|WHERE
|NOT EXISTS (SELECT * FROM t2)
""".stripMargin).cache()
""".stripMargin
sql(sql1).cache()

val cachedDs =
sql(
"""
|SELECT * FROM t1
|WHERE
|NOT EXISTS (SELECT * FROM t2)
""".stripMargin)
val cachedDs = sql(sql1)
assert(getNumInMemoryRelations(cachedDs) == 1)

// Additional predicate in the subquery plan should cause a cache miss
Expand All @@ -717,20 +712,15 @@ class CachedTableSuite extends QueryTest with SQLTestUtils with SharedSQLContext
Seq(1).toDF("c1").createOrReplaceTempView("t2")

// Simple correlated predicate in subquery
sql(
val sqlText =
"""
|SELECT * FROM t1
|WHERE
|t1.c1 in (SELECT t2.c1 FROM t2 where t1.c1 = t2.c1)
""".stripMargin).cache()
""".stripMargin
sql(sqlText).cache()

val cachedDs =
sql(
"""
|SELECT * FROM t1
|WHERE
|t1.c1 in (SELECT t2.c1 FROM t2 where t1.c1 = t2.c1)
""".stripMargin)
val cachedDs = sql(sqlText)
assert(getNumInMemoryRelations(cachedDs) == 1)
}
}
Expand All @@ -741,22 +731,16 @@ class CachedTableSuite extends QueryTest with SQLTestUtils with SharedSQLContext
spark.catalog.cacheTable("t1")

// underlying table t1 is cached as well as the query that refers to it.
val ds =
sql(
val sqlText =
"""
|SELECT * FROM t1
|WHERE
|NOT EXISTS (SELECT * FROM t1)
""".stripMargin)
""".stripMargin
val ds = sql(sqlText)
assert(getNumInMemoryRelations(ds) == 2)

val cachedDs =
sql(
"""
|SELECT * FROM t1
|WHERE
|NOT EXISTS (SELECT * FROM t1)
""".stripMargin).cache()
val cachedDs = sql(sqlText).cache()
assert(getNumInMemoryTablesRecursively(cachedDs.queryExecution.sparkPlan) == 3)
}
}
Expand All @@ -769,45 +753,31 @@ class CachedTableSuite extends QueryTest with SQLTestUtils with SharedSQLContext
Seq(1).toDF("c1").createOrReplaceTempView("t4")

// Nested predicate subquery
sql(
val sql1 =
"""
|SELECT * FROM t1
|WHERE
|c1 IN (SELECT c1 FROM t2 WHERE c1 IN (SELECT c1 FROM t3 WHERE c1 = 1))
""".stripMargin).cache()
""".stripMargin
sql(sql1).cache()

val cachedDs =
sql(
"""
|SELECT * FROM t1
|WHERE
|c1 IN (SELECT c1 FROM t2 WHERE c1 IN (SELECT c1 FROM t3 WHERE c1 = 1))
""".stripMargin)
val cachedDs = sql(sql1)
assert(getNumInMemoryRelations(cachedDs) == 1)

// Scalar subquery and predicate subquery
sql(
val sql2 =
"""
|SELECT * FROM (SELECT c1, max(c1) as c1 FROM t1 GROUP BY c1)
|SELECT * FROM (SELECT c1, 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).cache()
""".stripMargin
sql(sql2).cache()

val cachedDs2 =
sql(
"""
|SELECT * FROM (SELECT c1, max(c1) as 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)
val cachedDs2 = sql(sql2)
assert(getNumInMemoryRelations(cachedDs2) == 1)
}
}
Expand Down