collate-data-diff 0.11.2__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.
Files changed (54) hide show
  1. collate_data_diff-0.11.2.dist-info/LICENSE +18 -0
  2. collate_data_diff-0.11.2.dist-info/METADATA +77 -0
  3. collate_data_diff-0.11.2.dist-info/RECORD +54 -0
  4. collate_data_diff-0.11.2.dist-info/WHEEL +4 -0
  5. collate_data_diff-0.11.2.dist-info/entry_points.txt +3 -0
  6. data_diff/__init__.py +180 -0
  7. data_diff/__main__.py +618 -0
  8. data_diff/abcs/__init__.py +0 -0
  9. data_diff/abcs/compiler.py +13 -0
  10. data_diff/abcs/database_types.py +308 -0
  11. data_diff/cloud/__init__.py +2 -0
  12. data_diff/cloud/data_source.py +318 -0
  13. data_diff/cloud/datafold_api.py +304 -0
  14. data_diff/config.py +127 -0
  15. data_diff/databases/__init__.py +17 -0
  16. data_diff/databases/_connect.py +306 -0
  17. data_diff/databases/base.py +1291 -0
  18. data_diff/databases/bigquery.py +315 -0
  19. data_diff/databases/clickhouse.py +203 -0
  20. data_diff/databases/databricks.py +248 -0
  21. data_diff/databases/duckdb.py +192 -0
  22. data_diff/databases/mssql.py +229 -0
  23. data_diff/databases/mysql.py +159 -0
  24. data_diff/databases/oracle.py +195 -0
  25. data_diff/databases/postgresql.py +258 -0
  26. data_diff/databases/presto.py +197 -0
  27. data_diff/databases/redshift.py +217 -0
  28. data_diff/databases/snowflake.py +207 -0
  29. data_diff/databases/trino.py +50 -0
  30. data_diff/databases/vertica.py +160 -0
  31. data_diff/dbt.py +604 -0
  32. data_diff/dbt_config_validators.py +65 -0
  33. data_diff/dbt_parser.py +523 -0
  34. data_diff/diff_tables.py +416 -0
  35. data_diff/errors.py +74 -0
  36. data_diff/format.py +359 -0
  37. data_diff/hashdiff_tables.py +264 -0
  38. data_diff/info_tree.py +62 -0
  39. data_diff/joindiff_tables.py +399 -0
  40. data_diff/lexicographic_space.py +240 -0
  41. data_diff/parse_time.py +74 -0
  42. data_diff/py.typed +0 -0
  43. data_diff/queries/__init__.py +0 -0
  44. data_diff/queries/api.py +200 -0
  45. data_diff/queries/ast_classes.py +798 -0
  46. data_diff/queries/base.py +24 -0
  47. data_diff/queries/extras.py +29 -0
  48. data_diff/query_utils.py +56 -0
  49. data_diff/schema.py +52 -0
  50. data_diff/table_segment.py +286 -0
  51. data_diff/thread_utils.py +98 -0
  52. data_diff/tracking.py +237 -0
  53. data_diff/utils.py +625 -0
  54. data_diff/version.py +1 -0
@@ -0,0 +1,160 @@
1
+ from typing import Any, ClassVar, Dict, List, Type
2
+
3
+ import attrs
4
+
5
+ from data_diff.schema import RawColumnInfo
6
+ from data_diff.utils import match_regexps
7
+ from data_diff.databases.base import (
8
+ CHECKSUM_HEXDIGITS,
9
+ CHECKSUM_OFFSET,
10
+ MD5_HEXDIGITS,
11
+ TIMESTAMP_PRECISION_POS,
12
+ BaseDialect,
13
+ ConnectError,
14
+ DbPath,
15
+ ColType,
16
+ ThreadedDatabase,
17
+ import_helper,
18
+ )
19
+ from data_diff.abcs.database_types import (
20
+ Decimal,
21
+ Float,
22
+ FractionalType,
23
+ Integer,
24
+ TemporalType,
25
+ Text,
26
+ Timestamp,
27
+ TimestampTZ,
28
+ Boolean,
29
+ ColType_UUID,
30
+ )
31
+
32
+
33
+ @import_helper("vertica")
34
+ def import_vertica():
35
+ import vertica_python
36
+
37
+ return vertica_python
38
+
39
+
40
+ @attrs.define(frozen=False)
41
+ class Dialect(BaseDialect):
42
+ name = "Vertica"
43
+ ROUNDS_ON_PREC_LOSS = True
44
+
45
+ TYPE_CLASSES = {
46
+ # Timestamps
47
+ "timestamp": Timestamp,
48
+ "timestamptz": TimestampTZ,
49
+ # Numbers
50
+ "numeric": Decimal,
51
+ "int": Integer,
52
+ "float": Float,
53
+ # Text
54
+ "char": Text,
55
+ "varchar": Text,
56
+ # Boolean
57
+ "boolean": Boolean,
58
+ }
59
+
60
+ # https://www.vertica.com/docs/9.3.x/HTML/Content/Authoring/SQLReferenceManual/DataTypes/Numeric/NUMERIC.htm#Default
61
+ DEFAULT_NUMERIC_PRECISION = 15
62
+
63
+ def quote(self, s: str) -> str:
64
+ return f'"{s}"'
65
+
66
+ def concat(self, items: List[str]) -> str:
67
+ return " || ".join(items)
68
+
69
+ def to_string(self, s: str) -> str:
70
+ return f"CAST({s} AS VARCHAR)"
71
+
72
+ def is_distinct_from(self, a: str, b: str) -> str:
73
+ return f"not ({a} <=> {b})"
74
+
75
+ def parse_type(self, table_path: DbPath, info: RawColumnInfo) -> ColType:
76
+ timestamp_regexps = {
77
+ r"timestamp\(?(\d?)\)?": Timestamp,
78
+ r"timestamptz\(?(\d?)\)?": TimestampTZ,
79
+ }
80
+ for m, t_cls in match_regexps(timestamp_regexps, info.data_type):
81
+ precision = int(m.group(1)) if m.group(1) else 6
82
+ return t_cls(precision=precision, rounds=self.ROUNDS_ON_PREC_LOSS)
83
+
84
+ number_regexps = {
85
+ r"numeric\((\d+),(\d+)\)": Decimal,
86
+ }
87
+ for m, n_cls in match_regexps(number_regexps, info.data_type):
88
+ _prec, scale = map(int, m.groups())
89
+ return n_cls(scale)
90
+
91
+ string_regexps = {
92
+ r"varchar\((\d+)\)": Text,
93
+ r"char\((\d+)\)": Text,
94
+ }
95
+ for m, n_cls in match_regexps(string_regexps, info.data_type):
96
+ return n_cls()
97
+
98
+ return super().parse_type(table_path, info)
99
+
100
+ def set_timezone_to_utc(self) -> str:
101
+ return "SET TIME ZONE TO 'UTC'"
102
+
103
+ def current_timestamp(self) -> str:
104
+ return "current_timestamp(6)"
105
+
106
+ def md5_as_int(self, s: str) -> str:
107
+ return f"CAST(HEX_TO_INTEGER(SUBSTRING(MD5({s}), {1 + MD5_HEXDIGITS - CHECKSUM_HEXDIGITS})) AS NUMERIC(38, 0)) - {CHECKSUM_OFFSET}"
108
+
109
+ def md5_as_hex(self, s: str) -> str:
110
+ return f"MD5({s})"
111
+
112
+ def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
113
+ if coltype.rounds:
114
+ return f"TO_CHAR({value}::TIMESTAMP({coltype.precision}), 'YYYY-MM-DD HH24:MI:SS.US')"
115
+
116
+ timestamp6 = f"TO_CHAR({value}::TIMESTAMP(6), 'YYYY-MM-DD HH24:MI:SS.US')"
117
+ return (
118
+ f"RPAD(LEFT({timestamp6}, {TIMESTAMP_PRECISION_POS+coltype.precision}), {TIMESTAMP_PRECISION_POS+6}, '0')"
119
+ )
120
+
121
+ def normalize_number(self, value: str, coltype: FractionalType) -> str:
122
+ return self.to_string(f"CAST({value} AS NUMERIC(38, {coltype.precision}))")
123
+
124
+ def normalize_uuid(self, value: str, _coltype: ColType_UUID) -> str:
125
+ # Trim doesn't work on CHAR type
126
+ return f"TRIM(CAST({value} AS VARCHAR))"
127
+
128
+ def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
129
+ return self.to_string(f"cast ({value} as int)")
130
+
131
+
132
+ @attrs.define(frozen=False, init=False, kw_only=True)
133
+ class Vertica(ThreadedDatabase):
134
+ DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
135
+ CONNECT_URI_HELP = "vertica://<user>:<password>@<host>/<database>"
136
+ CONNECT_URI_PARAMS = ["database?"]
137
+
138
+ _args: Dict[str, Any]
139
+
140
+ def __init__(self, *, thread_count, **kw) -> None:
141
+ super().__init__(thread_count=thread_count)
142
+ self._args = kw
143
+ self._args["AUTOCOMMIT"] = False
144
+ self.default_schema = "public"
145
+
146
+ def create_connection(self):
147
+ vertica = import_vertica()
148
+ try:
149
+ return vertica.connect(**self._args)
150
+ except vertica.errors.ConnectionError as e:
151
+ raise ConnectError(*e.args) from e
152
+
153
+ def select_table_schema(self, path: DbPath) -> str:
154
+ schema, name = self._normalize_table_path(path)
155
+
156
+ return (
157
+ "SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale "
158
+ "FROM V_CATALOG.COLUMNS "
159
+ f"WHERE table_name = '{name}' AND table_schema = '{schema}'"
160
+ )