dongjoon-hyun commented on code in PR #43283:
URL: https://github.com/apache/spark/pull/43283#discussion_r1349820345


##########
core/src/main/scala/org/apache/spark/util/HadoopFSUtils.scala:
##########
@@ -342,13 +345,24 @@ private[spark] object HadoopFSUtils extends Logging {
     exclude && !include
   }
 
+  private val underscore: Regex = "/_[^=/]*/".r
+  private val underscoreEnd: Regex = "/_[^/]*$".r
+
   /** Checks if we should filter out this path. */
   def shouldFilterOutPath(path: String): Boolean = {
-    val exclude = (path.contains("/_") && !path.contains("=")) || 
path.contains("/.")
-    val include = path.contains("/_common_metadata/") ||
-      path.endsWith("/_common_metadata") ||
-      path.contains("/_metadata/") ||
-      path.endsWith("/_metadata")
-    (exclude && !include) || shouldFilterOutPathName(path)
+    if (path.contains("/.") || path.endsWith("._COPYING_")) return true
+    underscoreEnd.findFirstIn(path) match {
+      case Some(dir) if dir.equals("/_metadata") || 
dir.equals("/_common_metadata") => false
+      case Some(_) => true
+      case None =>
+        underscore.findFirstIn(path) match {
+          case Some(dir) if dir.equals("/_metadata/") =>
+            shouldFilterOutPath(path.replaceFirst("/_metadata", ""))
+          case Some(dir) if dir.equals("/_common_metadata/") =>
+            shouldFilterOutPath(path.replaceFirst("/_common_metadata", ""))
+          case Some(_) => true
+          case None => false

Review Comment:
   Now, we don't depend on `shouldFilterOutPathName` and in the caller part. I 
removed the root directory to simplify this method's role.
   
   ```scala
   - }.filterNot(status => shouldFilterOutPath(status.getPath.toString))
   + }.filterNot(status => 
shouldFilterOutPath(status.getPath.toString.substring(prefixLength)))
   ```



##########
core/src/main/scala/org/apache/spark/util/HadoopFSUtils.scala:
##########
@@ -30,6 +31,7 @@ import org.apache.spark._
 import org.apache.spark.internal.Logging
 import org.apache.spark.metrics.source.HiveCatalogMetrics
 
+

Review Comment:
   Thank you!



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

Reply via email to