Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/13566#discussion_r66540666
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala ---
@@ -157,4 +161,49 @@ private[sql] class CacheManager extends Logging {
case _ =>
}
}
+
+ /**
+ * Invalidates the cache of any data that contains `resourcePath` in one
or more
+ * `HadoopFsRelation` node(s) as part of its logical plan.
+ */
+ private[sql] def invalidateCachedPath(
+ sparkSession: SparkSession, resourcePath: String): Unit = writeLock {
+ val (fs, qualifiedPath) = {
+ val path = new Path(resourcePath)
+ val fs =
path.getFileSystem(sparkSession.sessionState.newHadoopConf())
+ (fs, path.makeQualified(fs.getUri, fs.getWorkingDirectory))
+ }
+
+ cachedData.foreach {
+ case data if data.plan.find(lookupAndRefresh(_, fs,
qualifiedPath)).isDefined =>
+ val dataIndex = cachedData.indexWhere(cd =>
data.plan.sameResult(cd.plan))
+ if (dataIndex >= 0) {
+
cachedData(dataIndex).cachedRepresentation.cachedColumnBuffers.unpersist(blocking
= true)
+ cachedData.remove(dataIndex)
+ }
+
sparkSession.sharedState.cacheManager.cacheQuery(Dataset.ofRows(sparkSession,
data.plan))
+ case _ => // Do Nothing
+ }
+ }
+
+ /**
+ * Traverses a given `plan` and searches for the occurrences of
`qualifiedPath` in the
+ * [[org.apache.spark.sql.execution.datasources.FileCatalog]] of any
[[HadoopFsRelation]] node
+ * in the plan. If found, we refresh the metadata and return true.
Otherwise, this method returns
+ * false.
+ */
+ private def lookupAndRefresh(plan: LogicalPlan, fs: FileSystem,
qualifiedPath: Path): Boolean = {
+ plan match {
+ case lr: LogicalRelation => lr.relation match {
--- End diff --
nvm, we are using `plan.find` in invalidateCachedPath
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]