[GH-3131] Align glob and directory-glob path handling in the raster metadata data sources#3142
Merged
Merged
Conversation
…ster metadata data sources geotiff.metadata and netcdf.metadata rewrote a single file-glob path such as /dir/a*.nc into path=/dir plus pathGlobFilter=a*.nc. Because pathGlobFilter matches leaf file names at any depth, combining the glob with an explicit recursiveFileLookup=true widened the match into nested files — unlike the native Spark glob, which matches direct children only. Directory globs such as /data/region* got neither of the directory-scan defaults: the getFileStatus probe fails on a glob string, so the expanded directories were listed non-recursively and unfiltered, inconsistent with loading the same directories by explicit path. The rewrite is removed: file paths and file globs now reach Spark untouched and keep native listing semantics in every option combination (the explicit-pathGlobFilter case already took this path). As in every other Spark file source, a file glob that matches nothing is now a PATH_NOT_FOUND error rather than a silently empty result. Directory detection goes through FileSystem.globStatus, which resolves plain paths and glob patterns alike, so directory globs receive the same recursive-scan and extension-filter defaults as explicit directory paths. Both sources stay aligned; docs updated and six regression tests added (three per source).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns path/glob handling between geotiff.metadata and netcdf.metadata by removing the internal “glob-to-pathGlobFilter rewrite” and switching directory-root detection to Hadoop FileSystem.globStatus, so both data sources preserve native Spark glob semantics while still applying directory-scan defaults (recursive lookup + extension filtering) when the load roots resolve to directories.
Changes:
- Stop rewriting file globs (e.g.,
/dir/a*.nc,/dir/a*.tif) into(dir, pathGlobFilter)and pass file paths/globs through to Spark unchanged. - Make directory-root detection glob-aware via
FileSystem.globStatus, so “directory globs” receive the same defaults as explicit directory paths. - Add regression tests (3 per data source) and update both docs pages to document the native glob semantics and directory-glob defaults.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/io/netcdfmetadata/NetCdfMetadataDataSource.scala | Removes glob-rewrite logic and uses glob-aware directory-root detection to apply directory defaults consistently. |
| spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/io/geotiffmetadata/GeoTiffMetadataDataSource.scala | Mirrors the NetCDF changes to keep GeoTIFF metadata source behavior aligned. |
| spark/common/src/test/scala/org/apache/sedona/sql/netcdfMetadataTest.scala | Adds regression coverage for file-glob recursion semantics, directory-glob defaults, and empty-glob error behavior. |
| spark/common/src/test/scala/org/apache/sedona/sql/geotiffMetadataTest.scala | Adds the same regression coverage for the GeoTIFF metadata data source. |
| docs/tutorial/files/netcdfmetadata-sedona-spark.md | Documents native Spark glob semantics and clarifies that directory globs receive directory-scan defaults. |
| docs/tutorial/files/geotiffmetadata-sedona-spark.md | Documents native Spark glob semantics and clarifies that directory globs receive directory-scan defaults. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Two review findings on the globStatus-based directory probe: - Entries Spark's own listing discards (_SUCCESS, dotfiles, *._COPYING_) no longer sway the classification: /data/* matching directories plus a _SUCCESS marker still stands for directories, so the recursive-scan and extension-filter defaults apply. The hidden-name rule (HadoopFSUtils.shouldFilterOutPathName) is applied only to glob-expanded matches — Spark exempts explicitly given roots from it, so a literal underscore directory keeps its defaults, pinned by a regression test. - Paths are probed literally with getFileStatus when __globPaths__ disables expansion (mirroring FileTable.globPaths) or when the path contains no wildcard from SparkHadoopUtil.isGlobPath's set, so a directory named with glob metacharacters keeps the directory-scan defaults under __globPaths__=false. Six mirrored regression tests (three per data source); both suites at 92/92.
Re-review: filtering hidden names before the nonEmpty check conflated an unmatched glob with a glob whose matches were all filtered, and over-applied the hidden-name rule to directories. Spark's listing drops hidden-named FILE matches (listStatus returns the file itself, whose name is checked) but traverses a directory root regardless of its name — only children are name-checked. The probe now mirrors that: the raw match count decides unmatched-glob detection, hidden files are treated as invisible (so a glob matching only a _SUCCESS marker cannot veto another root's defaults), and hidden-named directories count normally (so /root/_* matching _staging/ keeps the directory defaults). Four mirrored regression tests; both suites at 96/96.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes Align glob and directory-glob path handling in the raster metadata data sources #3131What changes were proposed in this PR?
geotiff.metadataandnetcdf.metadatarewrote a single file-glob path such as/dir/a*.ncinto path/dirpluspathGlobFilter="a*.nc". BecausepathGlobFiltermatches leaf file names at any depth, combining the glob with an explicitrecursiveFileLookup=truewidened the match into nested files such as/dir/sub/a1.nc— unlike the native Spark glob, which matches direct children only. Directory globs such as/data/region*got neither of the directory-scan defaults: thegetFileStatusprobe fails on a glob string, so the expanded directories were listed non-recursively and unfiltered, inconsistent with loading the same directories by explicit path.This PR takes the second direction proposed in #3131:
pathGlobFiltercase has taken this path since [GH-3128] Fix geotiff.metadata partition values, scan identity, and option handling #3129 and passes CI across the Spark matrix, so the rewrite no longer earned its divergence. As in every other Spark file source, a file glob that matches nothing is now aPATH_NOT_FOUNDerror rather than a silently empty result.FileSystem.globStatus, which resolves plain paths and glob patterns alike: a path stands for directories when it matches at least one status and all matches are directories. Directory globs therefore receive the same recursive-scan and extension-filter defaults as explicit directory paths. The defaults still apply only when every root resolves to directories, preserving the mixed-load safeguard from [GH-3128] Fix geotiff.metadata partition values, scan identity, and option handling #3129.Both data sources are changed identically and stay aligned.
How was this patch tested?
Six new regression tests, three per data source, mirrored across
geotiffMetadataTestandnetcdfMetadataTest:recursiveFileLookup=truematches direct children only (nesteda2.nc/a2.tiffis not pulled in),AnalysisException(PATH_NOT_FOUND).Full suites pass: 86/86 across both (
-Dspark=3.5 -Dscala=2.12), including the pre-existing glob, directory, multi-directory, partition-discovery, and option-precedence tests.Did this PR include necessary documentation updates?