33from typing import Tuple , Union
44from datetime import datetime
55
6- from runtype import dataclass
6+ import attrs
77
88from data_diff .utils import ArithAlphanumeric , ArithUUID , Unknown
99
1313DbTime = datetime
1414
1515
16- @dataclass
16+ @attrs . define ( frozen = True )
1717class ColType :
18- supported = True
18+ @property
19+ def supported (self ) -> bool :
20+ return True
1921
2022
21- @dataclass
23+ @attrs . define ( frozen = True )
2224class PrecisionType (ColType ):
2325 precision : int
2426 rounds : Union [bool , Unknown ] = Unknown
2527
2628
29+ @attrs .define (frozen = True )
2730class Boolean (ColType ):
2831 precision = 0
2932
3033
34+ @attrs .define (frozen = True )
3135class TemporalType (PrecisionType ):
3236 pass
3337
3438
39+ @attrs .define (frozen = True )
3540class Timestamp (TemporalType ):
3641 pass
3742
3843
44+ @attrs .define (frozen = True )
3945class TimestampTZ (TemporalType ):
4046 pass
4147
4248
49+ @attrs .define (frozen = True )
4350class Datetime (TemporalType ):
4451 pass
4552
4653
54+ @attrs .define (frozen = True )
4755class Date (TemporalType ):
4856 pass
4957
5058
51- @dataclass
59+ @attrs . define ( frozen = True )
5260class NumericType (ColType ):
5361 # 'precision' signifies how many fractional digits (after the dot) we want to compare
5462 precision : int
5563
5664
65+ @attrs .define (frozen = True )
5766class FractionalType (NumericType ):
5867 pass
5968
6069
70+ @attrs .define (frozen = True )
6171class Float (FractionalType ):
6272 python_type = float
6373
6474
75+ @attrs .define (frozen = True )
6576class IKey (ABC ):
6677 "Interface for ColType, for using a column as a key in table."
6778
@@ -74,6 +85,7 @@ def make_value(self, value):
7485 return self .python_type (value )
7586
7687
88+ @attrs .define (frozen = True )
7789class Decimal (FractionalType , IKey ): # Snowflake may use Decimal as a key
7890 @property
7991 def python_type (self ) -> type :
@@ -82,27 +94,32 @@ def python_type(self) -> type:
8294 return decimal .Decimal
8395
8496
85- @dataclass
97+ @attrs . define ( frozen = True )
8698class StringType (ColType ):
8799 python_type = str
88100
89101
102+ @attrs .define (frozen = True )
90103class ColType_UUID (ColType , IKey ):
91104 python_type = ArithUUID
92105
93106
107+ @attrs .define (frozen = True )
94108class ColType_Alphanum (ColType , IKey ):
95109 python_type = ArithAlphanumeric
96110
97111
112+ @attrs .define (frozen = True )
98113class Native_UUID (ColType_UUID ):
99114 pass
100115
101116
117+ @attrs .define (frozen = True )
102118class String_UUID (ColType_UUID , StringType ):
103119 pass
104120
105121
122+ @attrs .define (frozen = True )
106123class String_Alphanum (ColType_Alphanum , StringType ):
107124 @staticmethod
108125 def test_value (value : str ) -> bool :
@@ -116,11 +133,12 @@ def make_value(self, value):
116133 return self .python_type (value )
117134
118135
136+ @attrs .define (frozen = True )
119137class String_VaryingAlphanum (String_Alphanum ):
120138 pass
121139
122140
123- @dataclass
141+ @attrs . define ( frozen = True )
124142class String_FixedAlphanum (String_Alphanum ):
125143 length : int
126144
@@ -130,18 +148,20 @@ def make_value(self, value):
130148 return self .python_type (value , max_len = self .length )
131149
132150
133- @dataclass
151+ @attrs . define ( frozen = True )
134152class Text (StringType ):
135- supported = False
153+ @property
154+ def supported (self ) -> bool :
155+ return False
136156
137157
138158# In majority of DBMSes, it is called JSON/JSONB. Only in Snowflake, it is OBJECT.
139- @dataclass
159+ @attrs . define ( frozen = True )
140160class JSON (ColType ):
141161 pass
142162
143163
144- @dataclass
164+ @attrs . define ( frozen = True )
145165class Array (ColType ):
146166 item_type : ColType
147167
@@ -151,22 +171,24 @@ class Array(ColType):
151171# For example, in BigQuery:
152172# - https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type
153173# - https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#struct_literals
154- @dataclass
174+ @attrs . define ( frozen = True )
155175class Struct (ColType ):
156176 pass
157177
158178
159- @dataclass
179+ @attrs . define ( frozen = True )
160180class Integer (NumericType , IKey ):
161181 precision : int = 0
162182 python_type : type = int
163183
164- def __post_init__ (self ):
184+ def __attrs_post_init__ (self ):
165185 assert self .precision == 0
166186
167187
168- @dataclass
188+ @attrs . define ( frozen = True )
169189class UnknownColType (ColType ):
170190 text : str
171191
172- supported = False
192+ @property
193+ def supported (self ) -> bool :
194+ return False
0 commit comments