Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sc-29500] Exclude should work if it ends in /* #1015

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions metaphor/s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ All other file types are automatically ignored. If not specified, all of the abo

You can optionally specify the URI patterns to exclude using the `excludes` config. It supports wildcards but not `{table}` & `{partition}` labels.

To exclude an entire directory, use `s3://bucket/directory` instead of `s3://bucket/directory/*`.

## Optional Configurations

### TLS Verification
Expand Down
2 changes: 2 additions & 0 deletions metaphor/s3/path_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def allow_path(self, path: str) -> bool:
path.rsplit("/", slash_to_remove)[0]
if exclude[-1] == "/":
exclude_pat = exclude[:-1]
elif exclude[-2:] == "/*":
exclude_pat = exclude[:-2]
else:
exclude_pat = exclude
if fnmatch(path.rsplit("/", slash_to_remove)[0], exclude_pat):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.14.132"
version = "0.14.133"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <[email protected]>"]
Expand Down
26 changes: 26 additions & 0 deletions tests/s3/test_path_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from metaphor.s3.path_spec import PathSpec


def test_exclude_all_files_in_directory() -> None:
path_spec = PathSpec(
uri="s3://bucket/v1/app/*/{table}/v4/*/{partition[0]}/{partition[1]}/{partition[2]}/*.*",
file_types={
"parquet",
},
excludes=["s3://bucket/v1/app/global/*"],
)
assert not path_spec.allow_path("s3://bucket/v1/app/global/foo/v4")


@pytest.mark.skip
def test_exclude_table_wildcard() -> None:
path_spec = PathSpec(
uri="s3://bucket/v1/services/data/{table}/v1/*/{partition[0]}/{partition[1]}/{partition[2]}/*.*",
file_types={
"parquet",
},
excludes=["s3://bucket/v1/services/data/skipped_*"],
)
assert not path_spec.allow_path("s3://bucket/v1/services/data/skipped_0/")
Loading