Skip to content

[#86] feat(blob_storage): support recursive walk for path LIKE predicate#87

Merged
jerryshao merged 2 commits into
agenticdataprotocol:mainfrom
mchades:feat/path-like-recursive-walk
Apr 17, 2026
Merged

[#86] feat(blob_storage): support recursive walk for path LIKE predicate#87
jerryshao merged 2 commits into
agenticdataprotocol:mainfrom
mchades:feat/path-like-recursive-walk

Conversation

@mchades

@mchades mchades commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Added recursive directory traversal support to LocalFSBackend._execute_query when a path LIKE or path ILIKE predicate is present. Two new private methods were introduced:

  • _has_path_like_predicate(predicates): recursively checks whether any predicate targets path with a LIKE or ILIKE operator.
  • _iter_entries_recursive(root): uses os.walk(topdown=True) to enumerate all filesystem entries under a root directory, pruning ignored directories in-place before descending so that no unnecessary I/O occurs.

When no path LIKE predicate is present, the original single-level iterdir() path is used unchanged.

Why are the changes needed?

Previously, path LIKE 'docs/%' silently returned zero results because the listing only iterated one directory level, so entries like docs/guide.md never appeared. SQL LIKE semantics require % to match any character sequence including /, so the recursive walk is the correct behaviour.

Fix: #86

Does this PR introduce any user-facing change?

Yes — QUERY intents with a path LIKE or path ILIKE predicate now traverse the resource directory recursively, returning entries at arbitrary depth whose path matches the pattern. Queries without such a predicate are unaffected.

How was this patch tested?

Five new unit tests in TestLocalFSBackendPathLike:

  1. test_query_path_like_top_level_extension_filterpath LIKE '%.txt' still filters top-level files (regression).
  2. test_query_path_like_recursive_subdir_prefixpath LIKE 'docs/%' returns files inside docs/.
  3. test_query_path_like_deep_nestedpath LIKE 'a/b/%.csv' matches at arbitrary depth.
  4. test_query_path_ilike_case_insensitivepath ILIKE '%.TXT' works case-insensitively.
  5. test_query_path_like_respects_ignore_patterns — ignored directories are not traversed.

…or path LIKE predicate

When a path LIKE or path ILIKE predicate is present in a QUERY intent,
switch from single-level iterdir() to os.walk() so that patterns
crossing directory boundaries (e.g. 'docs/%.txt') can match entries at
arbitrary depth. Ignored directories are pruned via os.walk topdown mode
to avoid unnecessary I/O. Single-level listing is preserved when no
path LIKE predicate is used.

Add unit tests covering:
- Top-level extension filter (regression)
- Subdirectory prefix pattern (docs/%)
- Arbitrary-depth nested pattern (a/b/%.csv)
- Case-insensitive ILIKE matching
- Ignore-pattern directory pruning

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds recursive filesystem traversal to the local blob storage backend when a path LIKE / path ILIKE predicate is used, aligning query behavior with expected SQL LIKE semantics for patterns that can match across directory boundaries.

Changes:

  • Updated LocalFSBackend._execute_query to switch to recursive enumeration when path LIKE / ILIKE is present.
  • Added _has_path_like_predicate and _iter_entries_recursive helper methods to support conditional recursion with ignore-directory pruning.
  • Added a new unit-test suite covering recursive LIKE/ILIKE behavior and ignore-pattern pruning.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/backends/blob_storage/local.py Adds conditional recursive walk for path LIKE/ILIKE queries via new helper methods.
tests/unit/backends/test_blob_storage.py Adds unit tests validating recursive LIKE/ILIKE matching and ignore-pattern pruning behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/backends/blob_storage/local.py Outdated
Comment thread src/backends/blob_storage/local.py
Comment thread src/backends/blob_storage/local.py Outdated
@jerryshao

Copy link
Copy Markdown
Contributor

I have no comments on this PR, let AI to check if there's any logic problem.

…arden symlink handling

- Convert _iter_entries_recursive from returning list[Path] to
  Iterator[Path] (generator), so the can_early_stop limit
  optimization works correctly during recursive LIKE walks
- Use followlinks=False in os.walk unconditionally to prevent
  symlinked directories from escaping the source directory or
  causing infinite cycles (Option A: symlinked dirs appear as
  leaf entries but are never descended into)
- Unify per-level entry ordering: yield files and subdirectories
  mixed alphabetically by name, matching sorted(iterdir()) semantics
- Fix docstring: align Yields/Returns wording with generator type;
  replace misleading 'sorted order' with 'deterministic traversal order'
- Add two new tests: symlinked dir contents not traversed during
  recursive walk, self-referential symlink loop does not hang

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mchades
mchades force-pushed the feat/path-like-recursive-walk branch from 49d3494 to dc0e154 Compare April 17, 2026 06:57
@mchades
mchades requested a review from jerryshao April 17, 2026 07:00
@mchades

mchades commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

all comments resolved

@jerryshao
jerryshao merged commit a126281 into agenticdataprotocol:main Apr 17, 2026
6 checks passed
@mchades
mchades deleted the feat/path-like-recursive-walk branch April 17, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Support % wildcard in path LIKE predicate for local filesystem backend

3 participants