cloud-fan commented on code in PR #41749:
URL: https://github.com/apache/spark/pull/41749#discussion_r1244352135
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala:
##########
@@ -366,14 +366,25 @@ class CacheManager extends Logging with
AdaptiveSparkPlanHelper {
fileIndex: FileIndex,
fs: FileSystem,
qualifiedPath: Path): Boolean = {
- val prefixToInvalidate = qualifiedPath.toString
val needToRefresh = fileIndex.rootPaths
- .map(_.makeQualified(fs.getUri, fs.getWorkingDirectory).toString)
- .exists(_.startsWith(prefixToInvalidate))
+ .map(_.makeQualified(fs.getUri, fs.getWorkingDirectory))
+ .exists(isSubDir(qualifiedPath, _))
if (needToRefresh) fileIndex.refresh()
needToRefresh
}
+ /**
+ * Checks if the given child path is a sub-directory of the given parent
path.
+ * @param qualifiedPathChild: Fully qualified child path
+ * @param qualifiedPathParent: Fully qualified parent path.
+ * @return True if the child path is a sub-directory of the given parent
path. Otherwise, false.
+ */
+ def isSubDir(qualifiedPathParent: Path, qualifiedPathChild: Path): Boolean =
{
+ Iterator.iterate(qualifiedPathChild)(_.getParent)
+ .takeWhile(_ != null)
+ .exists(_.toString.equals(qualifiedPathParent.toString))
Review Comment:
can't we rely on `Path.equals`?
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala:
##########
@@ -366,14 +366,25 @@ class CacheManager extends Logging with
AdaptiveSparkPlanHelper {
fileIndex: FileIndex,
fs: FileSystem,
qualifiedPath: Path): Boolean = {
- val prefixToInvalidate = qualifiedPath.toString
val needToRefresh = fileIndex.rootPaths
- .map(_.makeQualified(fs.getUri, fs.getWorkingDirectory).toString)
- .exists(_.startsWith(prefixToInvalidate))
+ .map(_.makeQualified(fs.getUri, fs.getWorkingDirectory))
+ .exists(isSubDir(qualifiedPath, _))
if (needToRefresh) fileIndex.refresh()
needToRefresh
}
+ /**
+ * Checks if the given child path is a sub-directory of the given parent
path.
+ * @param qualifiedPathChild: Fully qualified child path
+ * @param qualifiedPathParent: Fully qualified parent path.
+ * @return True if the child path is a sub-directory of the given parent
path. Otherwise, false.
+ */
+ def isSubDir(qualifiedPathParent: Path, qualifiedPathChild: Path): Boolean =
{
+ Iterator.iterate(qualifiedPathChild)(_.getParent)
+ .takeWhile(_ != null)
+ .exists(_.toString.equals(qualifiedPathParent.toString))
Review Comment:
can't we rely on `Path#equals`?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]