You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "CalvQ (via GitHub)" <gi...@apache.org> on 2026/06/08 20:19:09 UTC

[PR] [SPARK-XXXXX][SQL] Add listHiddenFiles data source option [spark]

CalvQ opened a new pull request, #56374:
URL: https://github.com/apache/spark/pull/56374

   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   Add a `listHiddenFiles` data source option plus a
   `spark.sql.files.listHiddenFiles` session configuration (default false) for file-based sources. When enabled, files and directories whose names start with `_` or `.` participate in file listing, partition discovery, and reads instead of being skipped. The per-read option overrides the session configuration. Both batch and Structured Streaming reads are covered.
   
   The flag is threaded through the listing path (HadoopFSUtils.listFiles / parallelListLeafFiles / listLeafFiles), the SQL file index (InMemoryFileIndex.bulkListLeafFiles and PathFilterWrapper), partition discovery (PartitioningAwareFileIndex.isDataPath), and file streaming options (FileStreamOptions). When true, the hidden-file filter is bypassed entirely; users can narrow results with `pathGlobFilter`.
   
   Note that spark-specific files can also be listed with this option, like `.COPYING` files. 
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   Hidden files listing is being requested as a feature. We want to enable a user-facing option for this. 
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
   
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   Yes. With the new flag `listHiddenFiles = true`, hidden files will now show up inside all file listing operations. 
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   New UT in `HadoopFSUtilsSuite.scala`
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   
   Generated-by: Claude Opus 4.8
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438685074


##########
core/src/main/scala/org/apache/spark/util/HadoopFSUtils.scala:
##########
@@ -342,8 +356,12 @@ private[spark] object HadoopFSUtils extends Logging {
   }
   // scalastyle:on argcount
 
-  /** Checks if we should filter out this path name. */
-  def shouldFilterOutPathName(pathName: String): Boolean = {
+  /**
+   * Checks if we should filter out this path name. When `listHiddenFiles` is true, nothing is
+   * considered hidden and this always returns false.
+   */
+  def shouldFilterOutPathName(pathName: String, listHiddenFiles: Boolean = false): Boolean = {

Review Comment:
   Now threading regex to both options



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438872335


##########
docs/sql-data-sources-generic-options.md:
##########
@@ -97,6 +97,46 @@ you can use:
 </div>
 </div>
 
+### Ignored Path Segment Regex
+
+Spark allows you to use the configuration `spark.sql.files.ignoredPathSegmentRegex` or the data source option `ignoredPathSegmentRegex` to control which files are treated as
+hidden during file listing. The value is a Java regular expression that is matched (with find semantics, i.e. `java.util.regex.Matcher.find`) against each individual
+directory and file name below the path being read; names in which the regex finds a match are skipped from file listing, partition discovery, and reads, and a matching
+directory name excludes its whole subtree. The default value is `^[._]`, which skips files and directories whose names start with `_` or `.`. The data source option
+takes precedence over the configuration when both are set.
+
+Regardless of the regex, three rules always apply: names starting with `_metadata` or `_common_metadata` (Parquet summary files) are always listed, names ending in
+`._COPYING_` (in-flight copies) are always skipped, and `_`-prefixed names containing `=` (partition directories) are always kept.
+
+A regex that never matches, such as `(?!)`, disables the generic hidden-file filtering and surfaces hidden files, including Spark-internal marker files such as

Review Comment:
   Explained https://github.com/apache/spark/pull/56374#discussion_r3438860093, but the empty pattern string `""` actually matches every string, meaning we would filter out everything. 
   
   Currently special-casing it to match nothing (disabling filtering), but lmk if you don't think the edge case is necessary



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add ignoredPathSegmentRegex data source option and config [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on PR #56374:
URL: https://github.com/apache/spark/pull/56374#issuecomment-4746268472

   > Empty string should allow everything not filter it out. Otherwise how do you allow ingesting everything?
   
   Agreed that `""` makes intuitive sense to surface everything, so it is now special-cased. Originally the empty pattern would match every string, so using `""` would filter everything out. Previously I used `(?!)` as an example, which matches nothing and disables filtering. 
   
   I've now special cased `""` to the match-nothing pattern, so both options disable filtering and ingest all files
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add ignoredPathSegmentRegex data source option and config [spark]

Posted by "brkyvz (via GitHub)" <gi...@apache.org>.
brkyvz commented on PR #56374:
URL: https://github.com/apache/spark/pull/56374#issuecomment-4746189449

   Empty string should allow everything not filter it out. Otherwise how do
   you allow ingesting everything?
   
   On Thu, Jun 18, 2026, 11:02 PM Calvin Qin ***@***.***> wrote:
   
   > ***@***.**** commented on this pull request.
   > ------------------------------
   >
   > In docs/sql-data-sources-generic-options.md
   > <https://github.com/apache/spark/pull/56374#discussion_r3438872335>:
   >
   > > @@ -97,6 +97,46 @@ you can use:
   >  </div>
   >  </div>
   >
   > +### Ignored Path Segment Regex
   > +
   > +Spark allows you to use the configuration `spark.sql.files.ignoredPathSegmentRegex` or the data source option `ignoredPathSegmentRegex` to control which files are treated as
   > +hidden during file listing. The value is a Java regular expression that is matched (with find semantics, i.e. `java.util.regex.Matcher.find`) against each individual
   > +directory and file name below the path being read; names in which the regex finds a match are skipped from file listing, partition discovery, and reads, and a matching
   > +directory name excludes its whole subtree. The default value is `^[._]`, which skips files and directories whose names start with `_` or `.`. The data source option
   > +takes precedence over the configuration when both are set.
   > +
   > +Regardless of the regex, three rules always apply: names starting with `_metadata` or `_common_metadata` (Parquet summary files) are always listed, names ending in
   > +`._COPYING_` (in-flight copies) are always skipped, and `_`-prefixed names containing `=` (partition directories) are always kept.
   > +
   > +A regex that never matches, such as `(?!)`, disables the generic hidden-file filtering and surfaces hidden files, including Spark-internal marker files such as
   >
   > Explained #56374 (comment)
   > <https://github.com/apache/spark/pull/56374#discussion_r3438860093>, but
   > the empty pattern string "" actually matches every string, meaning we
   > would filter out everything.
   >
   > —
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/spark/pull/56374?email_source=notifications&email_token=ABIAE66Z2STBAV44ACNJ5OD5ARKH7A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINJSHA2DSNRWHEZ2M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#discussion_r3438872335>,
   > or unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/ABIAE64K37KX6RIVDBPSSK35ARKH7AVCNFSNUABEKJSXA33TNF2G64TZHMYTOMJWGU3DKOB3JFZXG5LFHM2DMMJWGMZDQMRVGKQXMAQ>
   > .
   > Triage notifications, keep track of coding agent tasks and review pull
   > requests on the go with GitHub Mobile for iOS
   > <https://github.com/notifications/mobile/ios/ABIAE63KQ4QL24EJO34MEJT5ARKH7A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINJSHA2DSNRWHEZ2M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJKTGN5XXIZLSL5UW64Y>
   > and Android
   > <https://github.com/notifications/mobile/android/ABIAE6ZNZWV7YFWHSD6H7U35ARKH7A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINJSHA2DSNRWHEZ2M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
   > Download it today!
   > You are receiving this because you commented.Message ID:
   > ***@***.***>
   >
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add ignoredPathSegmentRegex data source option and config [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3455704227


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala:
##########
@@ -154,8 +154,9 @@ object InMemoryFileIndex extends Logging {
       parameters: Map[String, String] = Map.empty): Seq[(Path, Seq[FileStatus])] = {
     val fileSystemList =
       sparkSession.sessionState.conf.useListFilesFileSystemList.split(",").map(_.trim)
-    val ignoreMissingFiles =
-      new FileSourceOptions(CaseInsensitiveMap(parameters)).ignoreMissingFiles
+    val fileSourceOptions = new FileSourceOptions(CaseInsensitiveMap(parameters))
+    val ignoreMissingFiles = fileSourceOptions.ignoreMissingFiles
+    val listHiddenFiles = fileSourceOptions.listHiddenFiles

Review Comment:
   Do you mean removing the SQLConf entirely? Existing patterns such as `ignoreCorruptFiles` and `ignoreMissingFiles` keep both a session conf and a per-read option. Removing the conf would be cache safe, but to match existing patterns I think it would make sense to keep both the conf and per-read option -- this would require the caching bypass 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438860093


##########
examples/src/main/python/sql/datasource.py:
##########
@@ -67,6 +67,14 @@ def generic_file_source_options_example(spark: SparkSession) -> None:
     # |file2.parquet|
     # +-------------+
     # $example off:recursive_file_lookup$
+
+    # $example on:ignored_path_segment_regex$
+    # "(?!)" surfaces files that are hidden by default (e.g. names starting with "_" or ".")
+    surfaced_df = spark.read.format("parquet")\
+        .option("ignoredPathSegmentRegex", "(?!)")\

Review Comment:
   Empty string using the .find pattern actually matches *all* strings, which would mean we filter everything. 
   
   I agree that the `""` pattern intuitively means allow everything, so I've added a specific edge-case for this, and swapped all examples to this 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438860093


##########
examples/src/main/python/sql/datasource.py:
##########
@@ -67,6 +67,14 @@ def generic_file_source_options_example(spark: SparkSession) -> None:
     # |file2.parquet|
     # +-------------+
     # $example off:recursive_file_lookup$
+
+    # $example on:ignored_path_segment_regex$
+    # "(?!)" surfaces files that are hidden by default (e.g. names starting with "_" or ".")
+    surfaced_df = spark.read.format("parquet")\
+        .option("ignoredPathSegmentRegex", "(?!)")\

Review Comment:
   Empty string using the .find pattern actually matches *all* strings, which would mean we filter everything. 
   
   I agree that the `""` pattern intuitively means allow everything, so I've added a specific edge-case for this, and swapped all examples to this 
   
   PTAL if the edge case is better or you want to instead just explain the `""` pattern behavior 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3416534424


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   Makes sense -- what do you think about `ignoredPathSegmentRegex`? This would represent the path segments that a user wants ignored during listing, and would default to the normal hidden filters for `_/.` This option also did not have demand for listing spark-specific hidden files, so I want to keep those files hardcoded unless there's demand for that capability. 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438872335


##########
docs/sql-data-sources-generic-options.md:
##########
@@ -97,6 +97,46 @@ you can use:
 </div>
 </div>
 
+### Ignored Path Segment Regex
+
+Spark allows you to use the configuration `spark.sql.files.ignoredPathSegmentRegex` or the data source option `ignoredPathSegmentRegex` to control which files are treated as
+hidden during file listing. The value is a Java regular expression that is matched (with find semantics, i.e. `java.util.regex.Matcher.find`) against each individual
+directory and file name below the path being read; names in which the regex finds a match are skipped from file listing, partition discovery, and reads, and a matching
+directory name excludes its whole subtree. The default value is `^[._]`, which skips files and directories whose names start with `_` or `.`. The data source option
+takes precedence over the configuration when both are set.
+
+Regardless of the regex, three rules always apply: names starting with `_metadata` or `_common_metadata` (Parquet summary files) are always listed, names ending in
+`._COPYING_` (in-flight copies) are always skipped, and `_`-prefixed names containing `=` (partition directories) are always kept.
+
+A regex that never matches, such as `(?!)`, disables the generic hidden-file filtering and surfaces hidden files, including Spark-internal marker files such as

Review Comment:
   Explained https://github.com/apache/spark/pull/56374#discussion_r3438860093, but the empty pattern string `""` actually matches every string, meaning we would filter out everything. 
   
   Currently edge-casing it to match nothing, but lmk if you don't think the edge case is necessary



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438872335


##########
docs/sql-data-sources-generic-options.md:
##########
@@ -97,6 +97,46 @@ you can use:
 </div>
 </div>
 
+### Ignored Path Segment Regex
+
+Spark allows you to use the configuration `spark.sql.files.ignoredPathSegmentRegex` or the data source option `ignoredPathSegmentRegex` to control which files are treated as
+hidden during file listing. The value is a Java regular expression that is matched (with find semantics, i.e. `java.util.regex.Matcher.find`) against each individual
+directory and file name below the path being read; names in which the regex finds a match are skipped from file listing, partition discovery, and reads, and a matching
+directory name excludes its whole subtree. The default value is `^[._]`, which skips files and directories whose names start with `_` or `.`. The data source option
+takes precedence over the configuration when both are set.
+
+Regardless of the regex, three rules always apply: names starting with `_metadata` or `_common_metadata` (Parquet summary files) are always listed, names ending in
+`._COPYING_` (in-flight copies) are always skipped, and `_`-prefixed names containing `=` (partition directories) are always kept.
+
+A regex that never matches, such as `(?!)`, disables the generic hidden-file filtering and surfaces hidden files, including Spark-internal marker files such as

Review Comment:
   Explained https://github.com/apache/spark/pull/56374#discussion_r3438860093, but the empty pattern string `""` actually matches every string, meaning we would filter out everything. 
   
   Currently edge-casing it to match nothing



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438872335


##########
docs/sql-data-sources-generic-options.md:
##########
@@ -97,6 +97,46 @@ you can use:
 </div>
 </div>
 
+### Ignored Path Segment Regex
+
+Spark allows you to use the configuration `spark.sql.files.ignoredPathSegmentRegex` or the data source option `ignoredPathSegmentRegex` to control which files are treated as
+hidden during file listing. The value is a Java regular expression that is matched (with find semantics, i.e. `java.util.regex.Matcher.find`) against each individual
+directory and file name below the path being read; names in which the regex finds a match are skipped from file listing, partition discovery, and reads, and a matching
+directory name excludes its whole subtree. The default value is `^[._]`, which skips files and directories whose names start with `_` or `.`. The data source option
+takes precedence over the configuration when both are set.
+
+Regardless of the regex, three rules always apply: names starting with `_metadata` or `_common_metadata` (Parquet summary files) are always listed, names ending in
+`._COPYING_` (in-flight copies) are always skipped, and `_`-prefixed names containing `=` (partition directories) are always kept.
+
+A regex that never matches, such as `(?!)`, disables the generic hidden-file filtering and surfaces hidden files, including Spark-internal marker files such as

Review Comment:
   Explained https://github.com/apache/spark/pull/56374#discussion_r3438860093, but the empty pattern string `""` actually matches every string, meaning we would filter out everything. 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "sandip-db (via GitHub)" <gi...@apache.org>.
sandip-db commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3391048966


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   I prefer this option name. Open to other suggestions. cc: @cloud-fan 
   ```suggestion
     val IGNORE_METADATA_FILES = "ignoreMetadataFiles"
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3438898828


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,15 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val ignoredPathSegmentRegex: String =
+    parameters.getOrElse(IGNORED_PATH_SEGMENT_REGEX, SQLConf.get.ignoredPathSegmentRegex)

Review Comment:
   Implemented via the shared `lazy val`



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3408233754


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   I think we should make the user intention clear here. The hidden file definition is from the file system, and it's a fact. Reading hidden file or not is the user intention. I'm fine with a regex option but let's make sure the option name reflects the user intention. 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3405013563


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   I'm thinking to apply the regex after the hardcoded edge cases: we always keep `_metadata/_common_metadata`, always drop `*._COPYING_`, and always keep `_x=y` names. The regex only replaces the generic `_/.` rule, so we can keep our default as `^[._]`, and a user-supplied regex cannot change the special rules we hardcode. WDYT? @cloud-fan 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add ignoredPathSegmentRegex data source option and config [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #56374: [SPARK-57354][SQL] Add ignoredPathSegmentRegex data source option and config
URL: https://github.com/apache/spark/pull/56374


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3399757994


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala:
##########
@@ -154,8 +154,9 @@ object InMemoryFileIndex extends Logging {
       parameters: Map[String, String] = Map.empty): Seq[(Path, Seq[FileStatus])] = {
     val fileSystemList =
       sparkSession.sessionState.conf.useListFilesFileSystemList.split(",").map(_.trim)
-    val ignoreMissingFiles =
-      new FileSourceOptions(CaseInsensitiveMap(parameters)).ignoreMissingFiles
+    val fileSourceOptions = new FileSourceOptions(CaseInsensitiveMap(parameters))
+    val ignoreMissingFiles = fileSourceOptions.ignoreMissingFiles
+    val listHiddenFiles = fileSourceOptions.listHiddenFiles

Review Comment:
   This interacts badly with `FileStatusCache`: cache entries are keyed by path only, but the listing they hold now depends on `listHiddenFiles`. Path-based reads are safe (each read gets a fresh cache client), but `CatalogFileIndex` keeps one cache client for the table's lifetime and resolves the flag from the session conf at listing time — so toggling `spark.sql.files.listHiddenFiles` between queries on a catalog table silently returns the listing cached under the old value (in both directions) until `REFRESH TABLE` or eviction.
   
   I'd bypass the cache (skip both `getLeafFiles` and `putLeafFiles` in `listLeafFiles`) when `listHiddenFiles` is true, so cached entries always hold the canonical hidden-filtered listing. That's simpler than widening the cache key, and re-listing on an opt-in flag is an acceptable cost.



##########
core/src/main/scala/org/apache/spark/util/HadoopFSUtils.scala:
##########
@@ -342,8 +356,12 @@ private[spark] object HadoopFSUtils extends Logging {
   }
   // scalastyle:on argcount
 
-  /** Checks if we should filter out this path name. */
-  def shouldFilterOutPathName(pathName: String): Boolean = {
+  /**
+   * Checks if we should filter out this path name. When `listHiddenFiles` is true, nothing is
+   * considered hidden and this always returns false.
+   */
+  def shouldFilterOutPathName(pathName: String, listHiddenFiles: Boolean = false): Boolean = {

Review Comment:
   Two production callers still rely on the default `false`:
   
   - `ArchiveReader.shouldSkipEntry` (ArchiveReader.scala:159) — its Scaladoc promises parity between archive-entry filtering and loose-file listing, but with the option on, hidden entries inside a tar are still skipped while the same files read loose are surfaced.
   - `DataSource.checkAndGlobPathIfNecessary` (DataSource.scala:847) — logs "All paths were ignored" for explicitly-passed hidden paths even when the option surfaces them.
   
   Worth threading the flag to both, or at least scoping the ArchiveReader Scaladoc claim to default listing.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetUtils.scala:
##########
@@ -143,7 +143,10 @@ object ParquetUtils extends Logging {
     val leaves = allFiles.toArray.sortBy(_.getPath.toString)
 
     FileTypes(
-      data = leaves.filterNot(f => isSummaryFile(f.getPath)).toImmutableArraySeq,
+      // Zero-length files (e.g. `_SUCCESS` markers surfaced by the `listHiddenFiles` option)
+      // cannot contain a Parquet footer, so exclude them from schema inference candidates.
+      data = leaves.filter(_.getLen > 0).filterNot(f => isSummaryFile(f.getPath))

Review Comment:
   Since this changes behavior on the default path too (a 0-byte parquet file used to fail schema inference with a footer error and is now silently skipped), it deserves an entry in `docs/sql-migration-guide.md`.



##########
sql/core/src/test/scala/org/apache/spark/sql/FileBasedDataSourceSuite.scala:
##########
@@ -1394,6 +1394,89 @@ class FileBasedDataSourceSuite extends SharedSparkSession
       }
     }
   }
+
+  // Asserts the listHiddenFiles contract for `format`: default hides the '_'-prefixed file; the
+  // per-read option and the session conf each surface it; the option overrides the conf.
+  private def checkListHiddenFilesContract(format: String, basePath: String): Unit = {
+    // Default: the hidden file is filtered out.
+    checkAnswer(spark.read.format(format).load(basePath), Seq(Row("visible")))
+
+    // Per-read option surfaces the hidden data.
+    checkAnswer(
+      spark.read.option("listHiddenFiles", "true").format(format).load(basePath),
+      Seq(Row("visible"), Row("hidden")))
+
+    // Session conf surfaces the hidden data too.
+    withSQLConf(SQLConf.LIST_HIDDEN_FILES.key -> "true") {
+      checkAnswer(
+        spark.read.format(format).load(basePath),
+        Seq(Row("visible"), Row("hidden")))
+    }
+
+    // Precedence: the per-read option overrides the session conf in both directions.
+    withSQLConf(SQLConf.LIST_HIDDEN_FILES.key -> "false") {
+      checkAnswer(
+        spark.read.option("listHiddenFiles", "true").format(format).load(basePath),
+        Seq(Row("visible"), Row("hidden")))
+    }
+    withSQLConf(SQLConf.LIST_HIDDEN_FILES.key -> "true") {
+      checkAnswer(
+        spark.read.option("listHiddenFiles", "false").format(format).load(basePath),
+        Seq(Row("visible")))
+    }
+  }
+
+  test("Option listHiddenFiles: surfaces hidden files only when enabled - json") {
+    withTempDir { dir =>
+      val basePath = dir.getCanonicalPath
+      // Write JSON files directly: a visible record and a '_'-prefixed hidden record.
+      Files.write(new File(dir, "visible.json").toPath, """{"a":"visible"}""".getBytes)
+      Files.write(new File(dir, "_hidden.json").toPath, """{"a":"hidden"}""".getBytes)
+
+      checkListHiddenFilesContract("json", basePath)
+    }
+  }
+
+  test("Option listHiddenFiles: surfaces hidden files only when enabled - parquet") {
+    withTempDir { dir =>
+      // Copy only the part-*.parquet from a scratch write into basePath -- this drops Spark's own
+      // _SUCCESS / _temporary marker files, so listHiddenFiles surfaces only the intended hidden
+      // file. Flat layout (files directly under basePath) mirrors the JSON test.
+      val basePath = dir.getCanonicalPath
+
+      def copyPartFile(value: String, destName: String): Unit = {
+        withTempDir { scratch =>
+          // withTempDir pre-creates the directory, so overwrite to avoid PATH_ALREADY_EXISTS.
+          Seq(value).toDF("a").write.format("parquet").mode("overwrite")
+            .save(scratch.getCanonicalPath)
+          val partFile = scratch.listFiles()
+            .find(f => f.isFile && f.getName.startsWith("part-") && f.getName.endsWith(".parquet"))
+            .getOrElse(fail(s"no part file produced under ${scratch.getCanonicalPath}"))
+          Files.copy(partFile.toPath, new File(dir, destName).toPath)
+        }
+      }
+      copyPartFile("visible", "visible.parquet")
+      copyPartFile("hidden", "_hidden.parquet")
+
+      checkListHiddenFilesContract("parquet", basePath)
+    }
+  }
+
+  test("Option listHiddenFiles: reading an unmodified Spark-written parquet directory works") {

Review Comment:
   Consider also covering the partitioned layout (`_SUCCESS` at the table root next to `part=` dirs) — the most common Spark-written shape. I traced that it works (`parsePartition` stops at the base path, so the root `_SUCCESS` doesn't create a conflicting base path), but that's exactly the behavior this feature most needs to lock in with a test.



##########
docs/sql-data-sources-generic-options.md:
##########
@@ -97,6 +97,16 @@ you can use:
 </div>
 </div>
 
+### List Hidden Files

Review Comment:
   The sibling sections (Ignore Corrupt Files, Path Glob Filter, Recursive File Lookup) all carry runnable code-tab examples; consider adding one here for consistency.



##########
docs/sql-data-sources-generic-options.md:
##########
@@ -97,6 +97,16 @@ you can use:
 </div>
 </div>
 
+### List Hidden Files
+
+Spark allows you to use the configuration `spark.sql.files.listHiddenFiles` or the data source option `listHiddenFiles` to include hidden files while reading data
+from files. Its default value is `false`, which means files and directories whose names start with `_` or `.` are skipped during
+file listing. When set to true, such hidden files and directories participate in file listing, partition discovery, and reads.
+The data source option takes precedence over the configuration when both are set.
+
+Note that enabling this option also surfaces Spark-internal marker files, such as `_SUCCESS`, `._COPYING_`, and files under

Review Comment:
   `._COPYING_` files come from Hadoop FS shell copies (`hadoop fs -put`/`-cp`), not Spark:
   ```suggestion
   Note that enabling this option also surfaces internal marker and temporary files, such as `_SUCCESS`, Hadoop's `._COPYING_` in-progress copy files, and files under
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3397636095


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   This is possible with minor logic changes: there's a full-path filter and a path segment filter. To keep behavior consistent we would need to walk the full-path to check our regex against each segment for filtering. 
   
   



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3431777676


##########
docs/sql-migration-guide.md:
##########
@@ -22,6 +22,10 @@ license: |
 * Table of contents
 {:toc}
 
+## Upgrading from Spark SQL 4.2 to 5.0

Review Comment:
   Same version issue as the config: this should target 4.3.0, not 5.0. Rather than a new `## Upgrading from Spark SQL 4.2 to 5.0` section, move this bullet into the existing `## Upgrading from Spark SQL 4.2 to 4.3` section just below, and change "Since Spark 5.0" to "Since Spark 4.3".



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -2776,6 +2777,27 @@ object SQLConf {
     .booleanConf
     .createWithDefault(false)
 
+  val IGNORED_PATH_SEGMENT_REGEX = buildConf("spark.sql.files.ignoredPathSegmentRegex")
+    .doc("Java regular expression matched (with find semantics) against each directory and " +
+      "file name during file listing; matching names are skipped from listing, partition " +
+      "discovery, and reads. The default '^[._]' skips names starting with '_' or '.' (hidden " +
+      "files). Regardless of the regex, names starting with '_metadata' or '_common_metadata' " +
+      "are always listed, names ending in '._COPYING_' are always skipped, and '_'-prefixed " +
+      "names containing '=' (partition directories) are always kept. This configuration is " +
+      "effective only when using file-based sources such as Parquet, JSON and ORC. It can be " +
+      "overridden per read by the 'ignoredPathSegmentRegex' data source option. A regex that never " +
+      "matches (e.g. '(?!)') disables generic hidden-file filtering; note that directories it " +
+      "surfaces also participate in partition discovery, so a hidden directory next to " +
+      "partition directories causes a conflicting directory structures error unless " +
+      "'spark.sql.files.ignoreInvalidPartitionPaths' is enabled.")
+    .version("5.0.0")

Review Comment:
   This should be `4.3.0`, not `5.0.0`. This is a normally-backported new feature (not a breaking change or dependency upgrade), so it ships first in the next open feature release — `branch-4.x`, currently `4.3.0-SNAPSHOT` — rather than master's `5.0.0-SNAPSHOT`. (On current master, 11 configs use `.version("4.3.0")` vs 1 at `5.0.0`.)
   ```suggestion
       .version("4.3.0")
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,15 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val ignoredPathSegmentRegex: String =
+    parameters.getOrElse(IGNORED_PATH_SEGMENT_REGEX, SQLConf.get.ignoredPathSegmentRegex)

Review Comment:
   Reinforcing @sandip-db's thread on `CSVDataSource.scala`: this resolved regex String is re-`Pattern.compile`d at ~5 call sites (`InMemoryFileIndex.bulkListLeafFiles`, `PartitioningAwareFileIndex`, `FileTable`, `DataSource`, `CSVFileFormat`) and the `require(nonEmpty)` is duplicated here and in `PartitioningAwareFileIndex`. Exposing a single lazy compiled `Pattern` here (and validating it with `Try(Pattern.compile(...))` like the SQL conf's `checkValue` does) would remove all of that — and as a bonus give the per-read option the same clear validation error the conf already produces, instead of the raw `PatternSyntaxException` an invalid option currently throws deep in listing. Non-blocking.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "brkyvz (via GitHub)" <gi...@apache.org>.
brkyvz commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3391407714


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   I prefer having a `hiddenFileRegex` instead that by default is `^[\.\_]`. That would give the users flexibility to keep files that start with `.` as a hidden file but keep `_` as readable, etc. 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "xiaonanyang-db (via GitHub)" <gi...@apache.org>.
xiaonanyang-db commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3391588401


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala:
##########
@@ -182,8 +185,11 @@ object InMemoryFileIndex extends Logging {
 
 }
 
-private class PathFilterWrapper(val filter: PathFilter) extends PathFilter with Serializable {
+private class PathFilterWrapper(
+    val filter: PathFilter,
+    val listHiddenFiles: Boolean) extends PathFilter with Serializable {
   override def accept(path: Path): Boolean = {
-    (filter == null || filter.accept(path)) && !HadoopFSUtils.shouldFilterOutPathName(path.getName)
+    (filter == null || filter.accept(path)) &&
+      (listHiddenFiles || !HadoopFSUtils.shouldFilterOutPathName(path.getName))

Review Comment:
   can we just pass `listHiddenFiles` into `HadoopFSUtils.shouldFilterOutPathName`?



##########
core/src/test/scala/org/apache/spark/util/HadoopFSUtilsSuite.scala:
##########
@@ -17,9 +17,43 @@
 
 package org.apache.spark.util
 
-import org.apache.spark.SparkFunSuite
+import java.io.File
+import java.nio.file.Files
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.{FileStatus, Path, PathFilter}
+
+import org.apache.spark.{SparkContext, SparkFunSuite}
+import org.apache.spark.LocalSparkContext.withSpark
 
 class HadoopFSUtilsSuite extends SparkFunSuite {
+
+  // Accept everything; hidden-file filtering is exercised via the listHiddenFiles flag.
+  private val acceptAllFilter: PathFilter = AcceptAllPathFilter
+
+  // Builds a tree with one regular file, hidden entries ('_'-, '.'-, '._COPYING_'-named) and a
+  // hidden subdir with its own file. Returns (rootPath, regularFileName).
+  private def createHiddenFileTree(root: File): (Path, String) = {

Review Comment:
   nit: add Scala doc to explain the returned values



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "sandip-db (via GitHub)" <gi...@apache.org>.
sandip-db commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3425795477


##########
docs/sql-data-sources-generic-options.md:
##########
@@ -97,6 +97,46 @@ you can use:
 </div>
 </div>
 
+### Ignored Path Segment Regex
+
+Spark allows you to use the configuration `spark.sql.files.ignoredPathSegmentRegex` or the data source option `ignoredPathSegmentRegex` to control which files are treated as
+hidden during file listing. The value is a Java regular expression that is matched (with find semantics, i.e. `java.util.regex.Matcher.find`) against each individual
+directory and file name below the path being read; names in which the regex finds a match are skipped from file listing, partition discovery, and reads, and a matching
+directory name excludes its whole subtree. The default value is `^[._]`, which skips files and directories whose names start with `_` or `.`. The data source option
+takes precedence over the configuration when both are set.
+
+Regardless of the regex, three rules always apply: names starting with `_metadata` or `_common_metadata` (Parquet summary files) are always listed, names ending in
+`._COPYING_` (in-flight copies) are always skipped, and `_`-prefixed names containing `=` (partition directories) are always kept.
+
+A regex that never matches, such as `(?!)`, disables the generic hidden-file filtering and surfaces hidden files, including Spark-internal marker files such as

Review Comment:
   An issue with empty pattern string ""?



##########
examples/src/main/python/sql/datasource.py:
##########
@@ -67,6 +67,14 @@ def generic_file_source_options_example(spark: SparkSession) -> None:
     # |file2.parquet|
     # +-------------+
     # $example off:recursive_file_lookup$
+
+    # $example on:ignored_path_segment_regex$
+    # "(?!)" surfaces files that are hidden by default (e.g. names starting with "_" or ".")
+    surfaced_df = spark.read.format("parquet")\
+        .option("ignoredPathSegmentRegex", "(?!)")\

Review Comment:
   Wouldn't empty string value be simpler?



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala:
##########
@@ -154,8 +154,9 @@ object InMemoryFileIndex extends Logging {
       parameters: Map[String, String] = Map.empty): Seq[(Path, Seq[FileStatus])] = {
     val fileSystemList =
       sparkSession.sessionState.conf.useListFilesFileSystemList.split(",").map(_.trim)
-    val ignoreMissingFiles =
-      new FileSourceOptions(CaseInsensitiveMap(parameters)).ignoreMissingFiles
+    val fileSourceOptions = new FileSourceOptions(CaseInsensitiveMap(parameters))
+    val ignoreMissingFiles = fileSourceOptions.ignoreMissingFiles
+    val listHiddenFiles = fileSourceOptions.listHiddenFiles

Review Comment:
   We don't need a SQL conf if `FileSourceOptions` is used. And `CatalogFileIndex` will ignore `FileSourceOptions`. So we should be ok with enabling caching.



##########
docs/sql-migration-guide.md:
##########
@@ -22,6 +22,10 @@ license: |
 * Table of contents
 {:toc}
 
+## Upgrading from Spark SQL 4.2 to 5.0
+
+- Since Spark 5.0, zero-length files are skipped during Parquet schema inference instead of failing with a `FAILED_READ_FILE.CANNOT_READ_FILE_FOOTER` error.

Review Comment:
   This is unrelated to this PR



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVDataSource.scala:
##########
@@ -100,13 +101,16 @@ abstract class CSVDataSource extends Serializable {
    *
    * @param getParser builds a fresh [[UnivocityParser]].
    * @param getHeaderChecker builds a fresh [[CSVHeaderChecker]] for `(isStartOfFile, source)`.
+   * @param ignoredPathSegmentRegex the compiled effective `ignoredPathSegmentRegex` option, so hidden
+   *                           entries are skipped exactly like Spark's file listing would.
    */
   def readArchive(
       conf: Configuration,
       file: PartitionedFile,
       getParser: () => UnivocityParser,
       getHeaderChecker: (Boolean, String) => CSVHeaderChecker,
-      requiredSchema: StructType): Iterator[InternalRow]
+      requiredSchema: StructType,
+      ignoredPathSegmentRegex: Pattern): Iterator[InternalRow]

Review Comment:
   `ignoredPathSegmentRegex` is already available in `FileSourceOptions`. Why is there a need to thread it again via these arguments. Any issue with having a lazy val in `FileSourceOptions` to compute the `Pattern`?



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala:
##########
@@ -182,8 +194,11 @@ object InMemoryFileIndex extends Logging {
 
 }
 
-private class PathFilterWrapper(val filter: PathFilter) extends PathFilter with Serializable {
+private class PathFilterWrapper(
+    val filter: PathFilter,
+    val ignoredPathSegmentRegex: Pattern) extends PathFilter with Serializable {
   override def accept(path: Path): Boolean = {
-    (filter == null || filter.accept(path)) && !HadoopFSUtils.shouldFilterOutPathName(path.getName)
+    (filter == null || filter.accept(path)) &&
+      !HadoopFSUtils.shouldFilterOutPathName(path.getName, ignoredPathSegmentRegex)

Review Comment:
   Wouldn't `listFiles` above already have evaluated the `ignoredPathSegmentRegex` against the path name?



##########
docs/sql-migration-guide.md:
##########
@@ -22,6 +22,10 @@ license: |
 * Table of contents
 {:toc}
 
+## Upgrading from Spark SQL 4.2 to 5.0
+
+- Since Spark 5.0, zero-length files are skipped during Parquet schema inference instead of failing with a `FAILED_READ_FILE.CANNOT_READ_FILE_FOOTER` error.

Review Comment:
   This is unrelated to this PR



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3424478107


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   `ignoredPathSegmentRegex` SGTM!



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add ignoredPathSegmentRegex data source option and config [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #56374:
URL: https://github.com/apache/spark/pull/56374#issuecomment-4783179406

   thanks, merging to master/4.x


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "brkyvz (via GitHub)" <gi...@apache.org>.
brkyvz commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3399893139


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   no, the regex would apply on every directory and file name independently. So you would walk up the directory path if you got a full list, or if you're performing a recursive list, you would just filter out by path.getName. the regex doesn't apply on the full path, it applies on the directory/file names



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3399756168


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/FileSourceOptions.scala:
##########
@@ -53,9 +53,13 @@ class FileSourceOptions(
    * executors. Only the CSV data source currently honors this.
    */
   val archiveFormatEnabled: Boolean = SQLConf.get.getConf(SQLConf.ARCHIVE_FORMAT_READER_ENABLED)
+
+  val listHiddenFiles: Boolean = parameters.get(LIST_HIDDEN_FILES).map(_.toBoolean)
+    .getOrElse(SQLConf.get.listHiddenFiles)
 }
 
 object FileSourceOptions {
   val IGNORE_CORRUPT_FILES = "ignoreCorruptFiles"
   val IGNORE_MISSING_FILES = "ignoreMissingFiles"
+  val LIST_HIDDEN_FILES = "listHiddenFiles"

Review Comment:
   I'd keep the boolean `listHiddenFiles`.
   
   Re `hiddenFileRegex`: the current filter isn't actually expressible as a name-prefix regex, which makes a regex option more misleading than flexible. Today's rule also drops `*._COPYING_` by suffix, exempts `_metadata`/`_common_metadata` (Parquet summary files), and special-cases `_x=y` names (`startsWith("_") && !contains("=")`). So `^[\.\_]` as the "behavior-preserving default" is already subtly wrong, and exposing the rule as a user-supplied regex either loses these special cases or forces users to understand them. The flexibility use case (e.g. surface `_` files but keep `.` files hidden) is already covered by combining this option with `pathGlobFilter`. If a real need shows up later, a regex option can still be added alongside the boolean without breaking anything.
   
   Re `ignoreMetadataFiles`: the filtered set is broader than metadata files (a `.foo.json` sidecar isn't metadata), and the default would be `true`, giving users a double negative. "Hidden files" is the established Hadoop convention (`FileInputFormat.hiddenFileFilter` is exactly the `_`/`.` prefix rule), so `listHiddenFiles` describes what the mechanism does.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-57354][SQL] Add listHiddenFiles data source option [spark]

Posted by "CalvQ (via GitHub)" <gi...@apache.org>.
CalvQ commented on code in PR #56374:
URL: https://github.com/apache/spark/pull/56374#discussion_r3392086787


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/InMemoryFileIndex.scala:
##########
@@ -182,8 +185,11 @@ object InMemoryFileIndex extends Logging {
 
 }
 
-private class PathFilterWrapper(val filter: PathFilter) extends PathFilter with Serializable {
+private class PathFilterWrapper(
+    val filter: PathFilter,
+    val listHiddenFiles: Boolean) extends PathFilter with Serializable {
   override def accept(path: Path): Boolean = {
-    (filter == null || filter.accept(path)) && !HadoopFSUtils.shouldFilterOutPathName(path.getName)
+    (filter == null || filter.accept(path)) &&
+      (listHiddenFiles || !HadoopFSUtils.shouldFilterOutPathName(path.getName))

Review Comment:
   implemented 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org