Github user liancheng commented on a diff in the pull request: https://github.com/apache/spark/pull/2576#discussion_r18766608 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala --- @@ -504,19 +505,41 @@ private[parquet] object FileSystemHelper { fs.listStatus(path).map(_.getPath) } - /** - * Finds the maximum taskid in the output file names at the given path. - */ - def findMaxTaskId(pathStr: String, conf: Configuration): Int = { + /** + * List files with special extension + */ + def listFiles(origPath: Path, conf: Configuration, extension: String): Seq[Path] = { + val fs = origPath.getFileSystem(conf) + if (fs == null) { + throw new IllegalArgumentException( + s"OrcTableOperations: Path $origPath is incorrectly formatted") + } + val path = origPath.makeQualified(fs) + if (fs.exists(path) && fs.getFileStatus(path).isDir) { + fs.listStatus(path).map(_.getPath).filter(p => p.getName.endsWith(extension)) + } else { + Seq.empty + } + } + + /** + * Finds the maximum taskid in the output file names at the given path. + */ + def findMaxTaskId(pathStr: String, conf: Configuration, extension: String): Int = { val files = FileSystemHelper.listFiles(pathStr, conf) - // filename pattern is part-r-<int>.parquet - val nameP = new scala.util.matching.Regex("""part-r-(\d{1,}).parquet""", "taskid") + // filename pattern is part-r-<int>.$extension + val nameP = extension match { + case "parquet" => new scala.util.matching.Regex( """part-r-(\d{1,}).parquet""", "taskid") + case "orc" => new scala.util.matching.Regex( """part-r-(\d{1,}).orc""", "taskid") + case _ => + sys.error(s"ERROR: unsupported extension: $extension") + } --- End diff -- Move this `match` expression to the beginning of this function since `.listFiles` can be expensive. Also this expression can be simplified to: ```scala require(Seq("orc", "parquet").contains(extension), s"Unsupported extension: $extension") val nameP = new Regex(s"""part-r-(\d{1,}).$extension""", "taskid") ```
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org