@@ -40,6 +40,19 @@ def _to_date(pb: ydb_value_pb2.Value, value: typing.Union[date, int]) -> None:
40
40
pb .uint32_value = value
41
41
42
42
43
+ def _from_date32 (x : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings ) -> typing .Union [date , int ]:
44
+ if table_client_settings is not None and table_client_settings ._native_date_in_result_sets :
45
+ return _EPOCH .date () + timedelta (days = x .int32_value )
46
+ return x .int32_value
47
+
48
+
49
+ def _to_date32 (pb : ydb_value_pb2 .Value , value : typing .Union [date , int ]) -> None :
50
+ if isinstance (value , date ):
51
+ pb .int32_value = (value - _EPOCH .date ()).days
52
+ else :
53
+ pb .int32_value = value
54
+
55
+
43
56
def _from_datetime_number (
44
57
x : typing .Union [float , datetime ], table_client_settings : table .TableClientSettings
45
58
) -> datetime :
@@ -63,6 +76,10 @@ def _from_uuid(pb: ydb_value_pb2.Value, value: uuid.UUID):
63
76
pb .high_128 = struct .unpack ("Q" , value .bytes_le [8 :16 ])[0 ]
64
77
65
78
79
+ def _timedelta_to_microseconds (value : timedelta ) -> int :
80
+ return (value .days * _SECONDS_IN_DAY + value .seconds ) * 1000000 + value .microseconds
81
+
82
+
66
83
def _from_interval (
67
84
value_pb : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings
68
85
) -> typing .Union [timedelta , int ]:
@@ -71,10 +88,6 @@ def _from_interval(
71
88
return value_pb .int64_value
72
89
73
90
74
- def _timedelta_to_microseconds (value : timedelta ) -> int :
75
- return (value .days * _SECONDS_IN_DAY + value .seconds ) * 1000000 + value .microseconds
76
-
77
-
78
91
def _to_interval (pb : ydb_value_pb2 .Value , value : typing .Union [timedelta , int ]):
79
92
if isinstance (value , timedelta ):
80
93
pb .int64_value = _timedelta_to_microseconds (value )
@@ -101,6 +114,25 @@ def _to_timestamp(pb: ydb_value_pb2.Value, value: typing.Union[datetime, int]):
101
114
pb .uint64_value = value
102
115
103
116
117
+ def _from_timestamp64 (
118
+ value_pb : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings
119
+ ) -> typing .Union [datetime , int ]:
120
+ if table_client_settings is not None and table_client_settings ._native_timestamp_in_result_sets :
121
+ return _EPOCH + timedelta (microseconds = value_pb .int64_value )
122
+ return value_pb .int64_value
123
+
124
+
125
+ def _to_timestamp64 (pb : ydb_value_pb2 .Value , value : typing .Union [datetime , int ]):
126
+ if isinstance (value , datetime ):
127
+ if value .tzinfo :
128
+ epoch = _EPOCH_UTC
129
+ else :
130
+ epoch = _EPOCH
131
+ pb .int64_value = _timedelta_to_microseconds (value - epoch )
132
+ else :
133
+ pb .int64_value = value
134
+
135
+
104
136
@enum .unique
105
137
class PrimitiveType (enum .Enum ):
106
138
"""
@@ -133,23 +165,46 @@ class PrimitiveType(enum.Enum):
133
165
_from_date ,
134
166
_to_date ,
135
167
)
168
+ Date32 = (
169
+ _apis .primitive_types .DATE32 ,
170
+ None ,
171
+ _from_date32 ,
172
+ _to_date32 ,
173
+ )
136
174
Datetime = (
137
175
_apis .primitive_types .DATETIME ,
138
176
"uint32_value" ,
139
177
_from_datetime_number ,
140
178
)
179
+ Datetime64 = (
180
+ _apis .primitive_types .DATETIME64 ,
181
+ "int32_value" ,
182
+ _from_datetime_number ,
183
+ )
141
184
Timestamp = (
142
185
_apis .primitive_types .TIMESTAMP ,
143
186
None ,
144
187
_from_timestamp ,
145
188
_to_timestamp ,
146
189
)
190
+ Timestamp64 = (
191
+ _apis .primitive_types .TIMESTAMP64 ,
192
+ None ,
193
+ _from_timestamp ,
194
+ _to_timestamp ,
195
+ )
147
196
Interval = (
148
197
_apis .primitive_types .INTERVAL ,
149
198
None ,
150
199
_from_interval ,
151
200
_to_interval ,
152
201
)
202
+ Interval64 = (
203
+ _apis .primitive_types .INTERVAL64 ,
204
+ None ,
205
+ _from_interval ,
206
+ _to_interval ,
207
+ )
153
208
154
209
DyNumber = _apis .primitive_types .DYNUMBER , "text_value"
155
210
0 commit comments