sqlassert 0.1.2__py3-none-any.whl → 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlassert/__init__.py +34 -9
- sqlassert/__main__.py +9 -0
- sqlassert/check.py +451 -0
- sqlassert/diagnostics.py +70 -0
- sqlassert/dialects.py +258 -0
- sqlassert/discovery/__init__.py +30 -0
- sqlassert/discovery/bigquery.py +71 -0
- sqlassert/discovery/databricks.py +18 -0
- sqlassert/discovery/duckdb.py +159 -0
- sqlassert/discovery/fetcher.py +418 -0
- sqlassert/discovery/information_schema.py +327 -0
- sqlassert/discovery/mysql.py +70 -0
- sqlassert/discovery/postgres.py +142 -0
- sqlassert/discovery/redshift.py +36 -0
- sqlassert/discovery/snowflake.py +63 -0
- sqlassert/discovery/trino.py +37 -0
- sqlassert/edits.py +240 -0
- sqlassert/hazards.py +574 -0
- sqlassert/ir/__init__.py +58 -0
- sqlassert/ir/convert.py +3509 -0
- sqlassert/ir/model.py +779 -0
- sqlassert/main.py +51 -0
- sqlassert/properties.py +121 -0
- sqlassert/provenance.py +73 -0
- sqlassert/python_engine.py +356 -0
- sqlassert/reporting.py +105 -0
- sqlassert/rewrites.py +1541 -0
- sqlassert/rules/STYLEGUIDE.md +19 -0
- sqlassert/rules/__init__.py +11 -0
- sqlassert/rules/column_set.py +34 -0
- sqlassert/rules/domain.py +472 -0
- sqlassert/rules/equality.py +442 -0
- sqlassert/rules/exactly_one.py +114 -0
- sqlassert/rules/foreign_key.py +319 -0
- sqlassert/rules/join_cardinality.py +116 -0
- sqlassert/rules/nullability.py +627 -0
- sqlassert/rules/uniqueness.py +904 -0
- sqlassert/sql_parse.py +1081 -0
- sqlassert/suggest.py +418 -0
- sqlassert-0.3.3.dist-info/METADATA +807 -0
- sqlassert-0.3.3.dist-info/RECORD +46 -0
- {sqlassert-0.1.2.dist-info → sqlassert-0.3.3.dist-info}/WHEEL +1 -1
- sqlassert-0.3.3.dist-info/entry_points.txt +2 -0
- sqlassert-0.3.3.dist-info/licenses/LICENSE +21 -0
- sqlassert-0.3.3.dist-info/top_level.txt +2 -0
- sqlassert_cli.py +130 -0
- sqlassert/unique.py +0 -605
- sqlassert-0.1.2.dist-info/METADATA +0 -173
- sqlassert-0.1.2.dist-info/RECORD +0 -6
- sqlassert-0.1.2.dist-info/top_level.txt +0 -1
sqlassert/reporting.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""The durable Report an analysis returns: assertion outcomes, diagnostics, and relation facts.
|
|
2
|
+
|
|
3
|
+
The Report holds plain values only, plus each assertion's evidence. It never prints.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Sequence
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from enum import Enum
|
|
11
|
+
from typing import TYPE_CHECKING
|
|
12
|
+
|
|
13
|
+
from sqlassert import properties as props
|
|
14
|
+
from sqlassert.diagnostics import Diagnostic
|
|
15
|
+
from sqlassert.provenance import Origin
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from sqlassert.python_engine import Result
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Outcome(Enum):
|
|
22
|
+
"""PROVED or UNKNOWN. UNKNOWN fails an assertion but is not a Disproof."""
|
|
23
|
+
|
|
24
|
+
PROVED = "proved"
|
|
25
|
+
UNKNOWN = "unknown"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class AssertionReport:
|
|
30
|
+
"""One assertion's outcome. `kind` is the marker that states it
|
|
31
|
+
(`ASSERTED_KINDS`), so a failure names what was not proved."""
|
|
32
|
+
|
|
33
|
+
assertion_id: str
|
|
34
|
+
outcome: Outcome
|
|
35
|
+
origin: Origin
|
|
36
|
+
kind: str
|
|
37
|
+
evidence: Result[bool] | None = field(default=None, compare=False)
|
|
38
|
+
# For an UNKNOWN assertion whose proof reaches a construct sqlassert does
|
|
39
|
+
# not support yet: what that construct is.
|
|
40
|
+
unsupported: str | None = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# The marker each assertable Property is written as, in the words of its `/**ASSERT ...**/`.
|
|
44
|
+
ASSERTED_KINDS: dict[type[props.Property], str] = {
|
|
45
|
+
props.NonNullColumns: "not-null",
|
|
46
|
+
props.NonNullElements: "not-null-elements",
|
|
47
|
+
props.UniqueSet: "unique",
|
|
48
|
+
props.NonNullUniqueSet: "not-null-unique", # also written PRIMARY KEY
|
|
49
|
+
props.FunctionalDependency: "determines",
|
|
50
|
+
props.EnumeratedDomain: "enum",
|
|
51
|
+
props.ReferentialCoverage: "foreign-key",
|
|
52
|
+
props.ForeignKey: "foreign-key",
|
|
53
|
+
props.ExhaustiveCase: "exhaustive",
|
|
54
|
+
props.UniqueJoin: "unique-join",
|
|
55
|
+
props.ManyToOneJoin: "many-to-one-join",
|
|
56
|
+
props.OneToManyJoin: "one-to-many-join",
|
|
57
|
+
props.OneToOneJoin: "one-to-one-join",
|
|
58
|
+
props.ExactlyOneJoin: "exactly-one-join",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class RelationFacts:
|
|
64
|
+
"""What was proved about every Named Relation in one analysis.
|
|
65
|
+
|
|
66
|
+
Tables and views use their declared name; CTEs use a ``CTE_``-prefixed
|
|
67
|
+
report label. Anonymous Relation Expressions are omitted: ask about the
|
|
68
|
+
assertion they feed into instead.
|
|
69
|
+
|
|
70
|
+
Holds only Unique Sets for now; further properties join it as typed
|
|
71
|
+
methods, the same way, rather than as a generic ask-anything query.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
_unique_sets: dict[str, tuple[tuple[str, ...], ...]] = field(default_factory=dict)
|
|
75
|
+
|
|
76
|
+
def unique_sets(self, relation: str) -> tuple[tuple[str, ...], ...]:
|
|
77
|
+
"""The minimal Unique Sets proved for `relation`, smallest first.
|
|
78
|
+
|
|
79
|
+
Every minimal set of up to three columns; when none is that small,
|
|
80
|
+
one minimal set. A superset of any of them is unique too."""
|
|
81
|
+
return self._unique_sets.get(relation.lower(), ())
|
|
82
|
+
|
|
83
|
+
def is_unique(self, relation: str, columns: Sequence[str]) -> bool:
|
|
84
|
+
"""Whether `columns` is guaranteed unique on `relation`: some proved
|
|
85
|
+
Unique Set's members are all among `columns`."""
|
|
86
|
+
candidate = {column.lower() for column in columns}
|
|
87
|
+
return any(set(unique_set) <= candidate for unique_set in self.unique_sets(relation))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@dataclass(frozen=True)
|
|
91
|
+
class Report:
|
|
92
|
+
assertions: tuple[AssertionReport, ...] = ()
|
|
93
|
+
diagnostics: tuple[Diagnostic, ...] = ()
|
|
94
|
+
facts: RelationFacts = field(default_factory=RelationFacts)
|
|
95
|
+
warnings: tuple[Diagnostic, ...] = ()
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def proved(self) -> bool:
|
|
99
|
+
"""Every assertion proved, and nothing about the program was unsupported.
|
|
100
|
+
|
|
101
|
+
Warnings do not count: they explain UNKNOWN outcomes, never cause them."""
|
|
102
|
+
return not self.diagnostics and all(
|
|
103
|
+
assertion.outcome is Outcome.PROVED for assertion in self.assertions
|
|
104
|
+
)
|
|
105
|
+
|