mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
fix(sl): tighten source validation guards
This commit is contained in:
parent
aaa928e768
commit
7a86aa9ddc
4 changed files with 105 additions and 3 deletions
|
|
@ -210,8 +210,6 @@ class SemanticEngine:
|
|||
grain = grain_col.lower()
|
||||
if grain in source_columns:
|
||||
return True
|
||||
if any(col.endswith(f"_{grain}") for col in source_columns):
|
||||
return True
|
||||
if grain == "id":
|
||||
candidates = {
|
||||
f"{target_name}_id",
|
||||
|
|
@ -219,6 +217,9 @@ class SemanticEngine:
|
|||
}
|
||||
if source_columns.intersection(candidates):
|
||||
return True
|
||||
continue
|
||||
if any(col.endswith(f"_{grain}") for col in source_columns):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _check_sql_join_coverage(
|
||||
|
|
|
|||
|
|
@ -323,6 +323,34 @@ class TestJoinValidation:
|
|||
|
||||
assert report.errors == []
|
||||
|
||||
def test_sql_join_coverage_does_not_treat_unrelated_id_suffix_as_id_key(self):
|
||||
requesters = SourceDefinition(
|
||||
name="large_contract_requesters",
|
||||
sql="""
|
||||
select accounts.account_name, requests.user_id
|
||||
from orbit_raw.requests requests
|
||||
join public.accounts accounts
|
||||
on requests.account_id = accounts.id
|
||||
""",
|
||||
grain=["user_id"],
|
||||
columns=[
|
||||
SourceColumn(name="account_name", type="string"),
|
||||
SourceColumn(name="user_id", type="string"),
|
||||
],
|
||||
joins=[],
|
||||
)
|
||||
accounts = _src("accounts", columns=["id", "account_name"], grain=["id"])
|
||||
engine = SemanticEngine.from_sources(
|
||||
{
|
||||
"large_contract_requesters": requesters,
|
||||
"accounts": accounts,
|
||||
}
|
||||
)
|
||||
|
||||
report = engine.validate(recently_touched={"large_contract_requesters"})
|
||||
|
||||
assert report.errors == []
|
||||
|
||||
def test_sql_join_coverage_requires_join_when_projected_key_exists(self):
|
||||
requesters = SourceDefinition(
|
||||
name="large_contract_requesters",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue