William1104 commented on a change in pull request #24221: [SPARK-27248][SQL]
refresh table should recreate cache with same cache name and storage level
URL: https://github.com/apache/spark/pull/24221#discussion_r281239659
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
##########
@@ -205,6 +206,20 @@ abstract class QueryTest extends PlanTest {
planWithCaching)
}
+ /**
+ * Asserts that a given [[Dataset]] will be executed using the given named
cache.
+ */
+ def assertCached(query: Dataset[_], cachedName: String, storageLevel:
StorageLevel): Unit = {
+ val planWithCaching = query.queryExecution.withCachedData
+ val matched = planWithCaching.collectFirst { case cached: InMemoryRelation
=>
+ val cacheBuilder = cached.asInstanceOf[InMemoryRelation].cacheBuilder
+ cacheBuilder.tableName.get == cachedName && cacheBuilder.storageLevel ==
storageLevel
+ }.nonEmpty
Review comment:
At the very beginning it was `planWithCaching.collect {...` . I missed to
change `nonEmpty` to `getOrElse(false)` after changing to use `collectFirst`
method.
Just updated. Thanks for pointing out my bug.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]