dcs-sdk 1.6.5__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.
- data_diff/__init__.py +221 -0
- data_diff/__main__.py +517 -0
- data_diff/abcs/__init__.py +13 -0
- data_diff/abcs/compiler.py +27 -0
- data_diff/abcs/database_types.py +402 -0
- data_diff/config.py +141 -0
- data_diff/databases/__init__.py +38 -0
- data_diff/databases/_connect.py +323 -0
- data_diff/databases/base.py +1417 -0
- data_diff/databases/bigquery.py +376 -0
- data_diff/databases/clickhouse.py +217 -0
- data_diff/databases/databricks.py +262 -0
- data_diff/databases/duckdb.py +207 -0
- data_diff/databases/mssql.py +343 -0
- data_diff/databases/mysql.py +189 -0
- data_diff/databases/oracle.py +238 -0
- data_diff/databases/postgresql.py +293 -0
- data_diff/databases/presto.py +222 -0
- data_diff/databases/redis.py +93 -0
- data_diff/databases/redshift.py +233 -0
- data_diff/databases/snowflake.py +222 -0
- data_diff/databases/sybase.py +720 -0
- data_diff/databases/trino.py +73 -0
- data_diff/databases/vertica.py +174 -0
- data_diff/diff_tables.py +489 -0
- data_diff/errors.py +17 -0
- data_diff/format.py +369 -0
- data_diff/hashdiff_tables.py +1026 -0
- data_diff/info_tree.py +76 -0
- data_diff/joindiff_tables.py +434 -0
- data_diff/lexicographic_space.py +253 -0
- data_diff/parse_time.py +88 -0
- data_diff/py.typed +0 -0
- data_diff/queries/__init__.py +13 -0
- data_diff/queries/api.py +213 -0
- data_diff/queries/ast_classes.py +811 -0
- data_diff/queries/base.py +38 -0
- data_diff/queries/extras.py +43 -0
- data_diff/query_utils.py +70 -0
- data_diff/schema.py +67 -0
- data_diff/table_segment.py +583 -0
- data_diff/thread_utils.py +112 -0
- data_diff/utils.py +1022 -0
- data_diff/version.py +15 -0
- dcs_core/__init__.py +13 -0
- dcs_core/__main__.py +17 -0
- dcs_core/__version__.py +15 -0
- dcs_core/cli/__init__.py +13 -0
- dcs_core/cli/cli.py +165 -0
- dcs_core/core/__init__.py +19 -0
- dcs_core/core/common/__init__.py +13 -0
- dcs_core/core/common/errors.py +50 -0
- dcs_core/core/common/models/__init__.py +13 -0
- dcs_core/core/common/models/configuration.py +284 -0
- dcs_core/core/common/models/dashboard.py +24 -0
- dcs_core/core/common/models/data_source_resource.py +75 -0
- dcs_core/core/common/models/metric.py +160 -0
- dcs_core/core/common/models/profile.py +75 -0
- dcs_core/core/common/models/validation.py +216 -0
- dcs_core/core/common/models/widget.py +44 -0
- dcs_core/core/configuration/__init__.py +13 -0
- dcs_core/core/configuration/config_loader.py +139 -0
- dcs_core/core/configuration/configuration_parser.py +262 -0
- dcs_core/core/configuration/configuration_parser_arc.py +328 -0
- dcs_core/core/datasource/__init__.py +13 -0
- dcs_core/core/datasource/base.py +62 -0
- dcs_core/core/datasource/manager.py +112 -0
- dcs_core/core/datasource/search_datasource.py +421 -0
- dcs_core/core/datasource/sql_datasource.py +1094 -0
- dcs_core/core/inspect.py +163 -0
- dcs_core/core/logger/__init__.py +13 -0
- dcs_core/core/logger/base.py +32 -0
- dcs_core/core/logger/default_logger.py +94 -0
- dcs_core/core/metric/__init__.py +13 -0
- dcs_core/core/metric/base.py +220 -0
- dcs_core/core/metric/combined_metric.py +98 -0
- dcs_core/core/metric/custom_metric.py +34 -0
- dcs_core/core/metric/manager.py +137 -0
- dcs_core/core/metric/numeric_metric.py +403 -0
- dcs_core/core/metric/reliability_metric.py +90 -0
- dcs_core/core/profiling/__init__.py +13 -0
- dcs_core/core/profiling/datasource_profiling.py +136 -0
- dcs_core/core/profiling/numeric_field_profiling.py +72 -0
- dcs_core/core/profiling/text_field_profiling.py +67 -0
- dcs_core/core/repository/__init__.py +13 -0
- dcs_core/core/repository/metric_repository.py +77 -0
- dcs_core/core/utils/__init__.py +13 -0
- dcs_core/core/utils/log.py +29 -0
- dcs_core/core/utils/tracking.py +105 -0
- dcs_core/core/utils/utils.py +44 -0
- dcs_core/core/validation/__init__.py +13 -0
- dcs_core/core/validation/base.py +230 -0
- dcs_core/core/validation/completeness_validation.py +153 -0
- dcs_core/core/validation/custom_query_validation.py +24 -0
- dcs_core/core/validation/manager.py +282 -0
- dcs_core/core/validation/numeric_validation.py +276 -0
- dcs_core/core/validation/reliability_validation.py +91 -0
- dcs_core/core/validation/uniqueness_validation.py +61 -0
- dcs_core/core/validation/validity_validation.py +738 -0
- dcs_core/integrations/__init__.py +13 -0
- dcs_core/integrations/databases/__init__.py +13 -0
- dcs_core/integrations/databases/bigquery.py +187 -0
- dcs_core/integrations/databases/databricks.py +51 -0
- dcs_core/integrations/databases/db2.py +652 -0
- dcs_core/integrations/databases/elasticsearch.py +61 -0
- dcs_core/integrations/databases/mssql.py +829 -0
- dcs_core/integrations/databases/mysql.py +409 -0
- dcs_core/integrations/databases/opensearch.py +64 -0
- dcs_core/integrations/databases/oracle.py +719 -0
- dcs_core/integrations/databases/postgres.py +482 -0
- dcs_core/integrations/databases/redshift.py +53 -0
- dcs_core/integrations/databases/snowflake.py +48 -0
- dcs_core/integrations/databases/spark_df.py +111 -0
- dcs_core/integrations/databases/sybase.py +1069 -0
- dcs_core/integrations/storage/__init__.py +13 -0
- dcs_core/integrations/storage/local_file.py +149 -0
- dcs_core/integrations/utils/__init__.py +13 -0
- dcs_core/integrations/utils/utils.py +36 -0
- dcs_core/report/__init__.py +13 -0
- dcs_core/report/dashboard.py +211 -0
- dcs_core/report/models.py +88 -0
- dcs_core/report/static/assets/fonts/DMSans-Bold.ttf +0 -0
- dcs_core/report/static/assets/fonts/DMSans-Medium.ttf +0 -0
- dcs_core/report/static/assets/fonts/DMSans-Regular.ttf +0 -0
- dcs_core/report/static/assets/fonts/DMSans-SemiBold.ttf +0 -0
- dcs_core/report/static/assets/images/docs.svg +6 -0
- dcs_core/report/static/assets/images/github.svg +4 -0
- dcs_core/report/static/assets/images/logo.svg +7 -0
- dcs_core/report/static/assets/images/slack.svg +13 -0
- dcs_core/report/static/index.js +2 -0
- dcs_core/report/static/index.js.LICENSE.txt +3971 -0
- dcs_sdk/__init__.py +13 -0
- dcs_sdk/__main__.py +18 -0
- dcs_sdk/__version__.py +15 -0
- dcs_sdk/cli/__init__.py +13 -0
- dcs_sdk/cli/cli.py +163 -0
- dcs_sdk/sdk/__init__.py +58 -0
- dcs_sdk/sdk/config/__init__.py +13 -0
- dcs_sdk/sdk/config/config_loader.py +491 -0
- dcs_sdk/sdk/data_diff/__init__.py +13 -0
- dcs_sdk/sdk/data_diff/data_differ.py +821 -0
- dcs_sdk/sdk/rules/__init__.py +15 -0
- dcs_sdk/sdk/rules/rules_mappping.py +31 -0
- dcs_sdk/sdk/rules/rules_repository.py +214 -0
- dcs_sdk/sdk/rules/schema_rules.py +65 -0
- dcs_sdk/sdk/utils/__init__.py +13 -0
- dcs_sdk/sdk/utils/serializer.py +25 -0
- dcs_sdk/sdk/utils/similarity_score/__init__.py +13 -0
- dcs_sdk/sdk/utils/similarity_score/base_provider.py +153 -0
- dcs_sdk/sdk/utils/similarity_score/cosine_similarity_provider.py +39 -0
- dcs_sdk/sdk/utils/similarity_score/jaccard_provider.py +24 -0
- dcs_sdk/sdk/utils/similarity_score/levenshtein_distance_provider.py +31 -0
- dcs_sdk/sdk/utils/table.py +475 -0
- dcs_sdk/sdk/utils/themes.py +40 -0
- dcs_sdk/sdk/utils/utils.py +349 -0
- dcs_sdk-1.6.5.dist-info/METADATA +150 -0
- dcs_sdk-1.6.5.dist-info/RECORD +159 -0
- dcs_sdk-1.6.5.dist-info/WHEEL +4 -0
- dcs_sdk-1.6.5.dist-info/entry_points.txt +4 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Copyright 2022-present, the Waterdip Labs Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import uuid
|
|
16
|
+
from typing import Any, ClassVar, Type
|
|
17
|
+
|
|
18
|
+
import attrs
|
|
19
|
+
|
|
20
|
+
from data_diff.abcs.database_types import ColType_UUID, String_UUID, TemporalType
|
|
21
|
+
from data_diff.databases import presto
|
|
22
|
+
from data_diff.databases.base import TIMESTAMP_PRECISION_POS, BaseDialect, import_helper
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@import_helper("trino")
|
|
26
|
+
def import_trino():
|
|
27
|
+
import trino
|
|
28
|
+
|
|
29
|
+
return trino
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Dialect(presto.Dialect):
|
|
33
|
+
name = "Trino"
|
|
34
|
+
|
|
35
|
+
def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
|
|
36
|
+
if coltype.rounds:
|
|
37
|
+
s = f"date_format(cast({value} as timestamp({coltype.precision})), '%Y-%m-%d %H:%i:%S.%f')"
|
|
38
|
+
else:
|
|
39
|
+
s = f"date_format(cast({value} as timestamp(6)), '%Y-%m-%d %H:%i:%S.%f')"
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
f"RPAD(RPAD({s}, {TIMESTAMP_PRECISION_POS + coltype.precision}, '.'), {TIMESTAMP_PRECISION_POS + 6}, '0')"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def normalize_uuid(self, value: str, coltype: ColType_UUID) -> str:
|
|
46
|
+
if isinstance(coltype, String_UUID):
|
|
47
|
+
return f"TRIM({value})"
|
|
48
|
+
return f"CAST({value} AS VARCHAR)"
|
|
49
|
+
|
|
50
|
+
def set_timezone_to_utc(self) -> str:
|
|
51
|
+
return "SET TIME ZONE '+00:00'"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@attrs.define(frozen=False, init=False, kw_only=True)
|
|
55
|
+
class Trino(presto.Presto):
|
|
56
|
+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
|
|
57
|
+
CONNECT_URI_HELP = "trino://<user>@<host>/<catalog>/<schema>"
|
|
58
|
+
CONNECT_URI_PARAMS = ["catalog", "schema"]
|
|
59
|
+
|
|
60
|
+
_conn: Any
|
|
61
|
+
|
|
62
|
+
def __init__(self, **kw) -> None:
|
|
63
|
+
super().__init__(**kw)
|
|
64
|
+
trino = import_trino()
|
|
65
|
+
|
|
66
|
+
if kw.get("schema"):
|
|
67
|
+
self.default_schema = kw.get("schema")
|
|
68
|
+
|
|
69
|
+
self._conn = trino.dbapi.connect(**kw)
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def is_autocommit(self) -> bool:
|
|
73
|
+
return True
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Copyright 2022-present, the Waterdip Labs Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from typing import Any, ClassVar, Dict, List, Type
|
|
16
|
+
|
|
17
|
+
import attrs
|
|
18
|
+
|
|
19
|
+
from data_diff.abcs.database_types import (
|
|
20
|
+
Boolean,
|
|
21
|
+
ColType_UUID,
|
|
22
|
+
Decimal,
|
|
23
|
+
Float,
|
|
24
|
+
FractionalType,
|
|
25
|
+
Integer,
|
|
26
|
+
TemporalType,
|
|
27
|
+
Text,
|
|
28
|
+
Timestamp,
|
|
29
|
+
TimestampTZ,
|
|
30
|
+
)
|
|
31
|
+
from data_diff.databases.base import (
|
|
32
|
+
CHECKSUM_HEXDIGITS,
|
|
33
|
+
CHECKSUM_OFFSET,
|
|
34
|
+
MD5_HEXDIGITS,
|
|
35
|
+
TIMESTAMP_PRECISION_POS,
|
|
36
|
+
BaseDialect,
|
|
37
|
+
ColType,
|
|
38
|
+
ConnectError,
|
|
39
|
+
DbPath,
|
|
40
|
+
ThreadedDatabase,
|
|
41
|
+
import_helper,
|
|
42
|
+
)
|
|
43
|
+
from data_diff.schema import RawColumnInfo
|
|
44
|
+
from data_diff.utils import match_regexps
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@import_helper("vertica")
|
|
48
|
+
def import_vertica():
|
|
49
|
+
import vertica_python
|
|
50
|
+
|
|
51
|
+
return vertica_python
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@attrs.define(frozen=False)
|
|
55
|
+
class Dialect(BaseDialect):
|
|
56
|
+
name = "Vertica"
|
|
57
|
+
ROUNDS_ON_PREC_LOSS = True
|
|
58
|
+
|
|
59
|
+
TYPE_CLASSES = {
|
|
60
|
+
# Timestamps
|
|
61
|
+
"timestamp": Timestamp,
|
|
62
|
+
"timestamptz": TimestampTZ,
|
|
63
|
+
# Numbers
|
|
64
|
+
"numeric": Decimal,
|
|
65
|
+
"int": Integer,
|
|
66
|
+
"float": Float,
|
|
67
|
+
# Text
|
|
68
|
+
"char": Text,
|
|
69
|
+
"varchar": Text,
|
|
70
|
+
# Boolean
|
|
71
|
+
"boolean": Boolean,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# https://www.vertica.com/docs/9.3.x/HTML/Content/Authoring/SQLReferenceManual/DataTypes/Numeric/NUMERIC.htm#Default
|
|
75
|
+
DEFAULT_NUMERIC_PRECISION = 15
|
|
76
|
+
|
|
77
|
+
def quote(self, s: str, is_table: bool = False) -> str:
|
|
78
|
+
return f'"{s}"'
|
|
79
|
+
|
|
80
|
+
def concat(self, items: List[str]) -> str:
|
|
81
|
+
return " || ".join(items)
|
|
82
|
+
|
|
83
|
+
def to_string(self, s: str) -> str:
|
|
84
|
+
return f"CAST({s} AS VARCHAR)"
|
|
85
|
+
|
|
86
|
+
def is_distinct_from(self, a: str, b: str) -> str:
|
|
87
|
+
return f"not ({a} <=> {b})"
|
|
88
|
+
|
|
89
|
+
def parse_type(self, table_path: DbPath, info: RawColumnInfo) -> ColType:
|
|
90
|
+
timestamp_regexps = {
|
|
91
|
+
r"timestamp\(?(\d?)\)?": Timestamp,
|
|
92
|
+
r"timestamptz\(?(\d?)\)?": TimestampTZ,
|
|
93
|
+
}
|
|
94
|
+
for m, t_cls in match_regexps(timestamp_regexps, info.data_type):
|
|
95
|
+
precision = int(m.group(1)) if m.group(1) else 6
|
|
96
|
+
return t_cls(precision=precision, rounds=self.ROUNDS_ON_PREC_LOSS)
|
|
97
|
+
|
|
98
|
+
number_regexps = {
|
|
99
|
+
r"numeric\((\d+),(\d+)\)": Decimal,
|
|
100
|
+
}
|
|
101
|
+
for m, n_cls in match_regexps(number_regexps, info.data_type):
|
|
102
|
+
_prec, scale = map(int, m.groups())
|
|
103
|
+
return n_cls(scale)
|
|
104
|
+
|
|
105
|
+
string_regexps = {
|
|
106
|
+
r"varchar\((\d+)\)": Text,
|
|
107
|
+
r"char\((\d+)\)": Text,
|
|
108
|
+
}
|
|
109
|
+
for m, n_cls in match_regexps(string_regexps, info.data_type):
|
|
110
|
+
return n_cls()
|
|
111
|
+
|
|
112
|
+
return super().parse_type(table_path, info)
|
|
113
|
+
|
|
114
|
+
def set_timezone_to_utc(self) -> str:
|
|
115
|
+
return "SET TIME ZONE TO 'UTC'"
|
|
116
|
+
|
|
117
|
+
def current_timestamp(self) -> str:
|
|
118
|
+
return "current_timestamp(6)"
|
|
119
|
+
|
|
120
|
+
def md5_as_int(self, s: str) -> str:
|
|
121
|
+
return f"CAST(HEX_TO_INTEGER(SUBSTRING(MD5({s}), {1 + MD5_HEXDIGITS - CHECKSUM_HEXDIGITS})) AS NUMERIC(38, 0)) - {CHECKSUM_OFFSET}"
|
|
122
|
+
|
|
123
|
+
def md5_as_hex(self, s: str) -> str:
|
|
124
|
+
return f"MD5({s})"
|
|
125
|
+
|
|
126
|
+
def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
|
|
127
|
+
if coltype.rounds:
|
|
128
|
+
return f"TO_CHAR({value}::TIMESTAMP({coltype.precision}), 'YYYY-MM-DD HH24:MI:SS.US')"
|
|
129
|
+
|
|
130
|
+
timestamp6 = f"TO_CHAR({value}::TIMESTAMP(6), 'YYYY-MM-DD HH24:MI:SS.US')"
|
|
131
|
+
return (
|
|
132
|
+
f"RPAD(LEFT({timestamp6}, {TIMESTAMP_PRECISION_POS+coltype.precision}), {TIMESTAMP_PRECISION_POS+6}, '0')"
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
def normalize_number(self, value: str, coltype: FractionalType) -> str:
|
|
136
|
+
return self.to_string(f"CAST({value} AS NUMERIC(38, {coltype.precision}))")
|
|
137
|
+
|
|
138
|
+
def normalize_uuid(self, value: str, _coltype: ColType_UUID) -> str:
|
|
139
|
+
# Trim doesn't work on CHAR type
|
|
140
|
+
return f"TRIM(CAST({value} AS VARCHAR))"
|
|
141
|
+
|
|
142
|
+
def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
|
|
143
|
+
return self.to_string(f"cast ({value} as int)")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@attrs.define(frozen=False, init=False, kw_only=True)
|
|
147
|
+
class Vertica(ThreadedDatabase):
|
|
148
|
+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
|
|
149
|
+
CONNECT_URI_HELP = "vertica://<user>:<password>@<host>/<database>"
|
|
150
|
+
CONNECT_URI_PARAMS = ["database?"]
|
|
151
|
+
|
|
152
|
+
_args: Dict[str, Any]
|
|
153
|
+
|
|
154
|
+
def __init__(self, *, thread_count, **kw) -> None:
|
|
155
|
+
super().__init__(thread_count=thread_count)
|
|
156
|
+
self._args = kw
|
|
157
|
+
self._args["AUTOCOMMIT"] = False
|
|
158
|
+
self.default_schema = "public"
|
|
159
|
+
|
|
160
|
+
def create_connection(self):
|
|
161
|
+
vertica = import_vertica()
|
|
162
|
+
try:
|
|
163
|
+
return vertica.connect(**self._args)
|
|
164
|
+
except vertica.errors.ConnectionError as e:
|
|
165
|
+
raise ConnectError(*e.args) from e
|
|
166
|
+
|
|
167
|
+
def select_table_schema(self, path: DbPath) -> str:
|
|
168
|
+
schema, name = self._normalize_table_path(path)
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
"SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale "
|
|
172
|
+
"FROM V_CATALOG.COLUMNS "
|
|
173
|
+
f"WHERE table_name = '{name}' AND table_schema = '{schema}'"
|
|
174
|
+
)
|