Skip to content

Support * wildcards in filter_values (#119) - #206

Open
ChitrarupGuha wants to merge 1 commit into
mapillary:mainfrom
ChitrarupGuha:filter-values-wildcard
Open

ChitrarupGuha wants to merge 1 commit into
mapillary:mainfrom
ChitrarupGuha:filter-values-wildcard

Conversation

@ChitrarupGuha

Copy link
Copy Markdown

filter_values now accepts * as a wildcard in string values, matching any run of characters (e.g. object--support--*).

  • Values without * match exactly, as before.
  • Regex characters in values are escaped, so . stays a literal dot.
  • Non-string property values (None, numbers) never match a wildcard pattern.
  • Added 9 tests in tests/utils/test_filter.py.

Addresses #119.

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

meta-cla Bot commented Dec 4, 2026

Copy link
Copy Markdown

Hi @ChitrarupGuha!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 4, 2026
@meta-cla

meta-cla Bot commented Dec 4, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!


return [
feature for feature in data if feature["properties"].get(property) in values
exact = [v for v in values if not (isinstance(v, str) and "*" in v)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ChitrarupGuha -- slightly concerned about the performance concern with this regex that could add up slightly more on each call. Each * becomes a .*, so a pattern with k wildcards can backtrack in roughly O(nᵏ) time on near-miss input.

Can we try something like this and test in test_filter.py for an perf degradations? Matching each middle piece at its leftmost position is always correct, so there's no backtracking and str.find keeps the check linear.

Quick AI code of what I was thinking about,

def _compile_glob(pattern: str) -> tuple[str, list[str], str]:
    first, *rest = pattern.split("*")
    *mid, last = rest
    return first, mid, last


def _glob_match(glob: tuple[str, list[str], str], s: str) -> bool:
    first, mid, last = glob
    if len(s) < len(first) + len(last):
        return False
    if not (s.startswith(first) and s.endswith(last)):
        return False
    pos, end = len(first), len(s) - len(last)
    for piece in mid:
        i = s.find(piece, pos, end)
        if i < 0:
            return False
        pos = i + len(piece)
    return True

And then,

exact = {v for v in values if not (isinstance(v, str) and "*" in v)}
globs = [_compile_glob(v) for v in values if isinstance(v, str) and "*" in v]

def matches(candidate) -> bool:
    return if candidate in exact then True else isinstance(candidate, str) and any(_glob_match(g, candidate) for g in globs)

return [f for f in data if matches(f["properties"].get(property))]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants