Skip to content
Open
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
47 changes: 47 additions & 0 deletions docs/how/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,53 @@ the one you are on and the one you are moving to, not just the target.

## Next

### BigQuery: `dataset_pattern` entries listing several datasets with `|` ([#21430](https://github.com/datahub-project/datahub/pull/21430))

**Affected config:** a BigQuery recipe with `match_fully_qualified_names: true` (the default) and a
`dataset_pattern` allow or deny entry that has no `.` and uses `|`:

```yaml
dataset_pattern:
deny:
- "staging|tmp"
```

**Before:** only the first alternative got the project prefix: `.*\.staging|tmp`. The `tmp` alternative
was compared against `<project_id>.<dataset_name>` and matched only when the project ID itself started
with `tmp`. So `tmp` datasets were not denied (in `allow`, they were not ingested), while every dataset
in a project whose ID starts with `tmp` was.

**Now:** the entry becomes `.*\.(?:staging|tmp)`, so in every project, datasets whose names start with
`staging` or `tmp` are denied (or, in `allow`, ingested). Review such entries: datasets they used to miss
are now filtered or ingested.

**Unchanged:** an entry that contains a `.` is still matched as written against
Comment thread
cclaude-datahub-project[bot] marked this conversation as resolved.
Resolved
`<project_id>.<dataset_name>`. `^staging_.*` still matches nothing; write `.*\.staging_.*` instead.
This includes an entry with `|` where any alternative has a `.`, such as `a|proj\.b`: it is kept
as written, so its `a` alternative is still matched against the start of
`<project_id>.<dataset_name>`, that is, against project IDs. Write each alternative in full
(`.*\.a|proj\.b`) or split the entry into one per dataset.

### Snowflake: schemas whose names end in `INFORMATION_SCHEMA` ([#21430](https://github.com/datahub-project/datahub/pull/21430))

**Affected config:** any Snowflake recipe for an account with a schema whose name ends in
`INFORMATION_SCHEMA` but is not `INFORMATION_SCHEMA` itself, such as `MY_INFORMATION_SCHEMA`.

**Before:** every recipe got the deny rule `.*INFORMATION_SCHEMA$`, which is matched case-insensitively
against the schema name (or `<database>.<schema>` with `match_fully_qualified_names: true`). It also
matched `MY_INFORMATION_SCHEMA`, so that schema was skipped silently.

**Now:** the rule is `^(.*\.)?INFORMATION_SCHEMA$`. It skips only `INFORMATION_SCHEMA` itself, and
schemas such as `MY_INFORMATION_SCHEMA` are ingested. A recipe that already lists `.*INFORMATION_SCHEMA$`
in `schema_pattern.deny` keeps that entry and still skips them. To keep skipping such a schema, add
it to the deny list, in either matching mode:

```yaml
schema_pattern:
deny:
- ".*MY_INFORMATION_SCHEMA$"
```

### `tags_to_term` transformer matches full tag names and maps column tags to columns

The `tags_to_term` ingestion transformer has changed in four ways ([PR #21479](https://github.com/datahub-project/datahub/pull/21479)):
Expand Down
16 changes: 11 additions & 5 deletions metadata-ingestion/src/datahub/configuration/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,22 @@ def is_allow_all(self) -> bool:

def with_deny(self, *rules: str) -> Self:
"""A new pattern with `rules` added to the deny list, each listed once:
duplicates already in the deny list are collapsed too. Rebuilt rather
than mutated or model_copy'd: the copy would carry this instance's
compiled-regex caches.
duplicates already in the deny list are collapsed too."""
return self.with_fields(deny=deduplicate_list([*self.deny, *rules]))

def with_fields(self, **overrides: Union[List[str], bool]) -> Self:
"""A fresh pattern with this one's fields, `overrides` replacing some.

Use this to derive a pattern; never edit `allow`/`deny` in place,
and never `model_copy` (or `copy.deepcopy`). The compiled regexes are
cached on first `allowed()`/`denied()` call, and those keep `__dict__`,
so the result would go on matching the old lists.

The rebuild round-trips through `model_dump()`, so a subclass is only
preserved faithfully if its fields survive that: no excluded or
aliased fields.
"""
deny = deduplicate_list([*self.deny, *rules])
return type(self).model_validate({**self.model_dump(), "deny": deny})
return type(self).model_validate({**self.model_dump(), **overrides})

def allowed(self, string: str) -> bool:
if self.denied(string):
Expand Down
11 changes: 5 additions & 6 deletions metadata-ingestion/src/datahub/ingestion/agent/filter_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ def _trial_pattern(
"""The recipe's pattern with each --try-* flag replacing only its own
half, every other field (`ignoreCase`) kept.

Rebuilt rather than model_copy'd: the copy carries the compiled regexes
the recipe's pattern cached on first use, and would match those.
Built with `AllowDenyPattern.with_fields`, not model_copy'd.
"""
# Compiled here, before any hook runs: AllowDenyPattern compiles lazily,
# so a malformed regex would otherwise surface inside a connector's hook
Expand All @@ -335,12 +334,12 @@ def _trial_pattern(
raise ProbeArgumentError(
f"{flag} {regex!r} is not a valid regular expression ({exc.msg})"
) from None
fields = recipe_pattern.model_dump()
overrides: Dict[str, List[str]] = {}
if try_allow:
fields["allow"] = list(try_allow)
overrides["allow"] = list(try_allow)
if try_deny:
fields["deny"] = list(try_deny)
return type(recipe_pattern).model_validate(fields)
overrides["deny"] = list(try_deny)
return recipe_pattern.with_fields(**overrides)


def _with_trial_pattern(
Expand Down
15 changes: 8 additions & 7 deletions metadata-ingestion/src/datahub/ingestion/agent/verdicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ def _listing_command_for(config: object, container_kind: str) -> Optional[str]:
return listing_command_for_kind(config, provider_cls, container_kind)


# An entry of the form `^?.*<literal>$`, where the literal carries no dot or
# regex syntax, matches `<container>.<name>` exactly when it matches `<name>`:
# the suffix cannot reach back across the dot. So the question is not whether a
# pattern filters -- a deny list filters and is still blind to the container --
# but whether the container could change what it says.
_CONTAINER_BLIND = re.compile(r"\^?\.\*[A-Za-z0-9_\-]*\$")
# An entry of the form `^?.*<literal>$` or `^(.*\.)?<literal>$`, where the
# literal carries no dot or regex syntax, matches `<container>.<name>` exactly
# when it matches `<name>`: the suffix cannot reach back across the dot. So the
# question is not whether a pattern filters -- a deny list filters and is still
# blind to the container -- but whether the container could change what it
# says.
_CONTAINER_BLIND = re.compile(r"(?:\^?\.\*|\^\(\.\*\\\.\)\?)[A-Za-z0-9_\-]*\$")

# Allow entries that admit every name, so the container cannot change them.
_MATCHES_ANYTHING = frozenset({".*", "^.*", ".*$", "^.*$", ".+", "^.+", ".+$", "^.+$"})
Expand All @@ -176,7 +177,7 @@ def container_blind(pattern: Optional[AllowDenyPattern]) -> bool:
False keeps the verdict unasked; True lets it stand on the bare name.
Testing "filters nothing" instead refused recipes whose verdict no
container could alter -- every Snowflake recipe, because
`validate_legacy_schema_pattern` always appends a `.*INFORMATION_SCHEMA$`
`validate_legacy_schema_pattern` always appends an INFORMATION_SCHEMA
deny, and a `dataset_pattern` denying `.*_staging$` for the same reason.
"""
if pattern is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from typing import Iterable, Optional

from datahub.configuration.common import AllowDenyPattern
from datahub.ingestion.api.common import PipelineContext
from datahub.ingestion.api.decorators import (
SupportStatus,
Expand Down Expand Up @@ -284,7 +283,7 @@ def _warn_deprecated_configs(self):
self.config.match_fully_qualified_names is not None
and not self.config.match_fully_qualified_names
and self.config.schema_pattern is not None
and self.config.schema_pattern != AllowDenyPattern.allow_all()
and not self.config.schema_pattern.is_allow_all()
):
self.report.warning(
message="Please update `schema_pattern` to match against fully qualified schema name `<database_name>.<schema_name>` and set config `match_fully_qualified_names : True`."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ class GcsDatasetLineageProviderConfigBase(ConfigModel):
)


def _qualify_dataset_regex(regex: str) -> str:
r"""A `dataset_pattern` entry with no `.` names the dataset alone, so it is
made to match `<project_id>.<dataset_name>`: `a` becomes `.*\.a`. An entry
with a `|` is also wrapped in a group, `a|b` becomes `.*\.(?:a|b)`, so every
alternative stays behind the prefix. An entry with a `.` is taken to name
the project already and is kept as written, including a dataset-name regex
such as `staging_.*`: write `.*\.staging_.*` instead.
"""
if "." in regex:
return regex
anchor, body = ("^", regex[1:]) if regex.startswith("^") else ("", regex)
if "|" in body:
body = "(?:" + body + ")"
return anchor + r".*\." + body


class BigQueryFilterConfig(SQLFilterConfig):
project_ids: Annotated[List[str], Qualifier()] = Field(
default_factory=list,
Expand Down Expand Up @@ -416,33 +432,32 @@ class BigQueryFilterConfig(SQLFilterConfig):

@model_validator(mode="after")
def backward_compatibility_configs_set(self) -> Any:
dataset_pattern = self.dataset_pattern
schema_pattern = self.schema_pattern

# Patterns are replaced, never edited in place: a pattern that was
# already used caches its compiled regexes, and would keep matching
# the old entries. See AllowDenyPattern.with_fields.
if (
dataset_pattern == AllowDenyPattern.allow_all()
and schema_pattern != AllowDenyPattern.allow_all()
self.dataset_pattern.is_allow_all()
and not self.schema_pattern.is_allow_all()
):
logging.warning(
"dataset_pattern is not set but schema_pattern is set, using schema_pattern as dataset_pattern. "
"schema_pattern will be deprecated, please use dataset_pattern instead."
)
self.dataset_pattern = schema_pattern
dataset_pattern = schema_pattern
self.dataset_pattern = self.schema_pattern.with_fields()
elif (
dataset_pattern != AllowDenyPattern.allow_all()
and schema_pattern != AllowDenyPattern.allow_all()
not self.dataset_pattern.is_allow_all()
and not self.schema_pattern.is_allow_all()
):
logging.warning(
"schema_pattern will be ignored in favour of dataset_pattern. schema_pattern will be deprecated,"
" please use dataset_pattern only."
)

dataset_pattern = self.dataset_pattern
match_fully_qualified_names = self.match_fully_qualified_names

if (
dataset_pattern is not None
and dataset_pattern != AllowDenyPattern.allow_all()
not dataset_pattern.is_allow_all()
and match_fully_qualified_names is not None
and not match_fully_qualified_names
):
Expand All @@ -452,17 +467,13 @@ def backward_compatibility_configs_set(self) -> Any:
"The config option `match_fully_qualified_names` is deprecated and will be "
"removed in a future release."
)
elif match_fully_qualified_names and dataset_pattern is not None:
adjusted = False
for lst in [dataset_pattern.allow, dataset_pattern.deny]:
for i, pattern in enumerate(lst):
if "." not in pattern:
if pattern.startswith("^"):
lst[i] = r"^.*\." + pattern[1:]
else:
lst[i] = r".*\." + pattern
adjusted = True
if adjusted:
elif match_fully_qualified_names:
allow = [_qualify_dataset_regex(p) for p in dataset_pattern.allow]
deny = [_qualify_dataset_regex(p) for p in dataset_pattern.deny]
if allow != dataset_pattern.allow or deny != dataset_pattern.deny:
self.dataset_pattern = dataset_pattern.with_fields(
allow=allow, deny=deny
)
logger.warning(
"`dataset_pattern` was adjusted to match against fully qualified schema names,"
" of the form `<project_id>.<dataset_name>`."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def validate_path_spec_comprehensive(self):
raise ValueError(
"path_spec.file_types is not applicable when emit_folders_only is set"
)
if self.tables_filter_pattern != AllowDenyPattern.allow_all():
if not self.tables_filter_pattern.is_allow_all():
raise ValueError(
"path_spec.tables_filter_pattern is not applicable when "
"emit_folders_only is set; use exclude to skip folders"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ def _validate_project_labels_format(cls, v: List[str]) -> List[str]:
@model_validator(mode="after")
def validate_project_ids(self) -> "DataplexConfig":
"""Ensure at least one means of selecting projects is configured."""
# Deliberately structural, not `not is_allow_all()`: a recipe whose only
# selector is an allow-all spelled differently (`ignoreCase: false`,
# `allow: [".*", "x"]`) is accepted today, and is_allow_all() would
# start rejecting it.
has_non_default_pattern = (
self.project_id_pattern != AllowDenyPattern.allow_all()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ def validate_workspace_apis_mode(self) -> "PowerBiDashboardSourceConfig":
("extract_endorsements_to_tags", self.extract_endorsements_to_tags),
(
"filter_dataset_endorsements",
self.filter_dataset_endorsements != AllowDenyPattern.allow_all(),
not self.filter_dataset_endorsements.is_allow_all(),
),
)
if enabled
Expand Down Expand Up @@ -1151,21 +1151,15 @@ def map_data_platform(cls, value):

@model_validator(mode="after")
def workspace_id_backward_compatibility(self) -> "PowerBiDashboardSourceConfig":
if (
self.workspace_id_pattern == AllowDenyPattern.allow_all()
and self.workspace_id
):
if self.workspace_id_pattern.is_allow_all() and self.workspace_id:
logger.warning(
"workspace_id_pattern is not set but workspace_id is set, setting workspace_id as "
"workspace_id_pattern. workspace_id will be deprecated, please use workspace_id_pattern instead."
)
self.workspace_id_pattern = AllowDenyPattern(
allow=[f"^{self.workspace_id}$"]
)
elif (
self.workspace_id_pattern != AllowDenyPattern.allow_all()
and self.workspace_id
):
elif not self.workspace_id_pattern.is_allow_all() and self.workspace_id:
logger.warning(
"workspace_id will be ignored in favour of workspace_id_pattern. workspace_id will be deprecated, "
"please use workspace_id_pattern only."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pydantic.fields import Field

from datahub.configuration.common import (
AllowDenyPattern,
HiddenFromDocs,
Qualifier,
)
Expand Down Expand Up @@ -261,7 +260,7 @@ def default_schemas(cls) -> FrozenSet[str]:
def backward_compatibility_configs_set(self) -> "RedshiftConfig":
if (
self.schema_pattern is not None
and self.schema_pattern != AllowDenyPattern.allow_all()
and not self.schema_pattern.is_allow_all()
and self.match_fully_qualified_names is not None
and not self.match_fully_qualified_names
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# These imports verify that the dependencies are available.
import redshift_connector

from datahub.configuration.common import AllowDenyPattern
from datahub.configuration.pattern_utils import is_schema_allowed
from datahub.configuration.time_window_config import BaseTimeWindowConfig
from datahub.emitter.mce_builder import (
Expand Down Expand Up @@ -364,7 +363,7 @@ def _warn_deprecated_configs(self):
self.config.match_fully_qualified_names is not None
and not self.config.match_fully_qualified_names
and self.config.schema_pattern is not None
and self.config.schema_pattern != AllowDenyPattern.allow_all()
and not self.config.schema_pattern.is_allow_all()
):
self.report.warning(
message="Please update `schema_pattern` to match against fully qualified schema name `<database_name>.<schema_name>` and set config `match_fully_qualified_names : True`."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@

logger = logging.Logger(__name__)

# Denied in every recipe. Matches the schema both bare and qualified
# (`DB.INFORMATION_SCHEMA`) but not a schema that merely ends in the name
# (`DB.MY_INFORMATION_SCHEMA`). `agent.verdicts.container_blind` recognises
# this shape; keep the two in step.
SNOWFLAKE_INFORMATION_SCHEMA_DENY = r"^(.*\.)?INFORMATION_SCHEMA$"

# FIVETRAN creates temporary tables in schema named FIVETRAN_xxx_STAGING.
# Ref - https://support.fivetran.com/hc/en-us/articles/1500003507122-Why-Is-There-an-Empty-Schema-Named-Fivetran-staging-in-the-Destination-
#
Expand Down Expand Up @@ -291,7 +297,7 @@ class SnowflakeFilterConfig(SQLFilterConfig):
@model_validator(mode="after")
def validate_legacy_schema_pattern(self) -> "SnowflakeFilterConfig":
if (
self.schema_pattern != AllowDenyPattern.allow_all()
not self.schema_pattern.is_allow_all()
and not self.match_fully_qualified_names
):
logger.warning(
Expand All @@ -301,7 +307,9 @@ def validate_legacy_schema_pattern(self) -> "SnowflakeFilterConfig":
)

# Always exclude reporting metadata for INFORMATION_SCHEMA schema
self.schema_pattern = self.schema_pattern.with_deny(r".*INFORMATION_SCHEMA$")
self.schema_pattern = self.schema_pattern.with_deny(
SNOWFLAKE_INFORMATION_SCHEMA_DENY
)

return self

Expand Down
Loading
Loading