11# -*- coding: utf-8 -*-
2+ from __future__ import annotations
3+
24import abc
35import enum
46import json
2325_EPOCH = datetime (1970 , 1 , 1 )
2426
2527
26- def _from_date (
27- x : ydb_value_pb2 .Value ,
28- table_client_settings : table .TableClientSettings
29- ) -> typing .Union [date , int ]:
28+ def _from_date (x : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings ) -> typing .Union [date , int ]:
3029 if table_client_settings is not None and table_client_settings ._native_date_in_result_sets :
3130 return _EPOCH .date () + timedelta (days = x .uint32_value )
3231 return x .uint32_value
@@ -40,27 +39,20 @@ def _to_date(pb: ydb_value_pb2.Value, value: typing.Union[date, int]) -> None:
4039
4140
4241def _from_datetime_number (
43- x : typing .Union [float , datetime ],
44- table_client_settings : table .TableClientSettings
42+ x : typing .Union [float , datetime ], table_client_settings : table .TableClientSettings
4543) -> datetime :
4644 if table_client_settings is not None and table_client_settings ._native_datetime_in_result_sets :
4745 return datetime .utcfromtimestamp (x )
4846 return x
4947
5048
51- def _from_json (
52- x : typing .Union [str , bytearray , bytes ],
53- table_client_settings : table .TableClientSettings
54- ):
49+ def _from_json (x : typing .Union [str , bytearray , bytes ], table_client_settings : table .TableClientSettings ):
5550 if table_client_settings is not None and table_client_settings ._native_json_in_result_sets :
5651 return json .loads (x )
5752 return x
5853
5954
60- def _to_uuid (
61- value_pb : ydb_value_pb2 .Value ,
62- table_client_settings : table .TableClientSettings
63- ) -> uuid .UUID :
55+ def _to_uuid (value_pb : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings ) -> uuid .UUID :
6456 return uuid .UUID (bytes_le = struct .pack ("QQ" , value_pb .low_128 , value_pb .high_128 ))
6557
6658
@@ -70,8 +62,7 @@ def _from_uuid(pb: ydb_value_pb2.Value, value: uuid.UUID):
7062
7163
7264def _from_interval (
73- value_pb : ydb_value_pb2 .Value ,
74- table_client_settings : table .TableClientSettings
65+ value_pb : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings
7566) -> typing .Union [timedelta , int ]:
7667 if table_client_settings is not None and table_client_settings ._native_interval_in_result_sets :
7768 return timedelta (microseconds = value_pb .int64_value )
@@ -82,26 +73,22 @@ def _timedelta_to_microseconds(value: timedelta) -> int:
8273 return (value .days * _SECONDS_IN_DAY + value .seconds ) * 1000000 + value .microseconds
8374
8475
85- def _to_interval (pb : ydb_value_pb2 .Value , value : typing .Union [timedelta , int ]) -> int :
76+ def _to_interval (pb : ydb_value_pb2 .Value , value : typing .Union [timedelta , int ]):
8677 if isinstance (value , timedelta ):
8778 pb .int64_value = _timedelta_to_microseconds (value )
8879 else :
8980 pb .int64_value = value
9081
9182
9283def _from_timestamp (
93- value_pb : ydb_value_pb2 .Value ,
94- table_client_settings : table .TableClientSettings
84+ value_pb : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings
9585) -> typing .Union [datetime , int ]:
9686 if table_client_settings is not None and table_client_settings ._native_timestamp_in_result_sets :
9787 return _EPOCH + timedelta (microseconds = value_pb .uint64_value )
9888 return value_pb .uint64_value
9989
10090
101- def _to_timestamp (
102- pb : ydb_value_pb2 .Value ,
103- value : typing .Union [datetime , int ]
104- ) -> int :
91+ def _to_timestamp (pb : ydb_value_pb2 .Value , value : typing .Union [datetime , int ]):
10592 if isinstance (value , datetime ):
10693 pb .uint64_value = _timedelta_to_microseconds (value - _EPOCH )
10794 else :
@@ -161,22 +148,14 @@ class PrimitiveType(enum.Enum):
161148 DyNumber = _apis .primitive_types .DYNUMBER , "text_value"
162149
163150 def __init__ (
164- self ,
165- idn : ydb_value_pb2 .Type .PrimitiveTypeId ,
166- proto_field : typing .Optional [str ],
167- to_obj = None ,
168- from_obj = None
151+ self , idn : ydb_value_pb2 .Type .PrimitiveTypeId , proto_field : typing .Optional [str ], to_obj = None , from_obj = None
169152 ):
170153 self ._idn_ = idn
171154 self ._to_obj = to_obj
172155 self ._from_obj = from_obj
173156 self ._proto_field = proto_field
174157
175- def get_value (
176- self ,
177- value_pb : ydb_value_pb2 .Value ,
178- table_client_settings : table .TableClientSettings
179- ):
158+ def get_value (self , value_pb : ydb_value_pb2 .Value , table_client_settings : table .TableClientSettings ):
180159 """
181160 Extracts value from protocol buffer
182161 :param value_pb: A protocol buffer
@@ -218,10 +197,7 @@ class DataQuery(object):
218197 __slots__ = ("yql_text" , "parameters_types" , "name" )
219198
220199 def __init__ (
221- self ,
222- query_id : str ,
223- parameters_types : "dict[str, ydb_value_pb2.Type]" ,
224- name : typing .Optional [str ] = None
200+ self , query_id : str , parameters_types : "dict[str, ydb_value_pb2.Type]" , name : typing .Optional [str ] = None
225201 ):
226202 self .yql_text = query_id
227203 self .parameters_types = parameters_types
@@ -305,10 +281,7 @@ def __str__(self):
305281class OptionalType (AbstractTypeBuilder ):
306282 __slots__ = ("_repr" , "_proto" , "_item" )
307283
308- def __init__ (
309- self ,
310- optional_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]
311- ):
284+ def __init__ (self , optional_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]):
312285 """
313286 Represents optional type that wraps inner type
314287 :param optional_type: An instance of an inner type
@@ -340,10 +313,7 @@ def __str__(self):
340313class ListType (AbstractTypeBuilder ):
341314 __slots__ = ("_repr" , "_proto" )
342315
343- def __init__ (
344- self ,
345- list_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]
346- ):
316+ def __init__ (self , list_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]):
347317 """
348318 :param list_type: List item type builder
349319 """
@@ -366,9 +336,9 @@ class DictType(AbstractTypeBuilder):
366336 __slots__ = ("__repr" , "__proto" )
367337
368338 def __init__ (
369- self ,
370- key_type : typing .Union [AbstractTypeBuilder , PrimitiveType ],
371- payload_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]
339+ self ,
340+ key_type : typing .Union [AbstractTypeBuilder , PrimitiveType ],
341+ payload_type : typing .Union [AbstractTypeBuilder , PrimitiveType ],
372342 ):
373343 """
374344 :param key_type: Key type builder
@@ -397,10 +367,7 @@ def __init__(self):
397367 self .__elements_repr = []
398368 self .__proto = _apis .ydb_value .Type (tuple_type = _apis .ydb_value .TupleType ())
399369
400- def add_element (
401- self ,
402- element_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]
403- ):
370+ def add_element (self , element_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]):
404371 """
405372 :param element_type: Adds additional element of tuple
406373 :return: self
@@ -425,11 +392,7 @@ def __init__(self):
425392 self .__members_repr = []
426393 self .__proto = _apis .ydb_value .Type (struct_type = _apis .ydb_value .StructType ())
427394
428- def add_member (
429- self ,
430- name : str ,
431- member_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]
432- ):
395+ def add_member (self , name : str , member_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]):
433396 """
434397 :param name:
435398 :param member_type:
@@ -456,11 +419,7 @@ def __init__(self):
456419 self .__columns_repr = []
457420 self .__proto = _apis .ydb_value .Type (struct_type = _apis .ydb_value .StructType ())
458421
459- def add_column (
460- self ,
461- name : str ,
462- column_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]
463- ):
422+ def add_column (self , name : str , column_type : typing .Union [AbstractTypeBuilder , PrimitiveType ]):
464423 """
465424 :param name: A column name
466425 :param column_type: A column type
0 commit comments