diff options
| author | robot-piglet <[email protected]> | 2025-04-29 11:48:43 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-04-29 12:08:26 +0300 |
| commit | c2a8d56d31f9da03d2050c751b96e377ec42969f (patch) | |
| tree | 8db54455c9cdf1db30da5290045948cfcd23599d | |
| parent | 713adc6a88be8af8a342a9a72a055b7ef6514563 (diff) | |
Intermediate changes
commit_hash:6ed396efc31982c8ce5cc34f1f933d195ad1439f
| -rw-r--r-- | contrib/python/ydb/py3/.dist-info/METADATA | 2 | ||||
| -rw-r--r-- | contrib/python/ydb/py3/ya.make | 2 | ||||
| -rw-r--r-- | contrib/python/ydb/py3/ydb/types.py | 89 | ||||
| -rw-r--r-- | contrib/python/ydb/py3/ydb/ydb_version.py | 2 |
4 files changed, 88 insertions, 7 deletions
diff --git a/contrib/python/ydb/py3/.dist-info/METADATA b/contrib/python/ydb/py3/.dist-info/METADATA index 8a15b64dc4b..aa485a3f4c0 100644 --- a/contrib/python/ydb/py3/.dist-info/METADATA +++ b/contrib/python/ydb/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: ydb -Version: 3.21.0 +Version: 3.21.1 Summary: YDB Python SDK Home-page: http://github.com/ydb-platform/ydb-python-sdk Author: Yandex LLC diff --git a/contrib/python/ydb/py3/ya.make b/contrib/python/ydb/py3/ya.make index b938db3247b..5f37e78726e 100644 --- a/contrib/python/ydb/py3/ya.make +++ b/contrib/python/ydb/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(3.21.0) +VERSION(3.21.1) LICENSE(Apache-2.0) diff --git a/contrib/python/ydb/py3/ydb/types.py b/contrib/python/ydb/py3/ydb/types.py index a48548640c0..47c9c48c2e2 100644 --- a/contrib/python/ydb/py3/ydb/types.py +++ b/contrib/python/ydb/py3/ydb/types.py @@ -39,6 +39,19 @@ def _to_date(pb: ydb_value_pb2.Value, value: typing.Union[date, int]) -> None: pb.uint32_value = value +def _from_date32(x: ydb_value_pb2.Value, table_client_settings: table.TableClientSettings) -> typing.Union[date, int]: + if table_client_settings is not None and table_client_settings._native_date_in_result_sets: + return _EPOCH.date() + timedelta(days=x.int32_value) + return x.int32_value + + +def _to_date32(pb: ydb_value_pb2.Value, value: typing.Union[date, int]) -> None: + if isinstance(value, date): + pb.int32_value = (value - _EPOCH.date()).days + else: + pb.int32_value = value + + def _from_datetime_number( x: typing.Union[float, datetime], table_client_settings: table.TableClientSettings ) -> datetime: @@ -62,6 +75,10 @@ def _from_uuid(pb: ydb_value_pb2.Value, value: uuid.UUID): pb.high_128 = struct.unpack("Q", value.bytes_le[8:16])[0] +def _timedelta_to_microseconds(value: timedelta) -> int: + return (value.days * _SECONDS_IN_DAY + value.seconds) * 1000000 + value.microseconds + + def _from_interval( value_pb: ydb_value_pb2.Value, table_client_settings: table.TableClientSettings ) -> typing.Union[timedelta, int]: @@ -70,10 +87,6 @@ def _from_interval( return value_pb.int64_value -def _timedelta_to_microseconds(value: timedelta) -> int: - return (value.days * _SECONDS_IN_DAY + value.seconds) * 1000000 + value.microseconds - - def _to_interval(pb: ydb_value_pb2.Value, value: typing.Union[timedelta, int]): if isinstance(value, timedelta): pb.int64_value = _timedelta_to_microseconds(value) @@ -100,6 +113,25 @@ def _to_timestamp(pb: ydb_value_pb2.Value, value: typing.Union[datetime, int]): pb.uint64_value = value +def _from_timestamp64( + value_pb: ydb_value_pb2.Value, table_client_settings: table.TableClientSettings +) -> typing.Union[datetime, int]: + if table_client_settings is not None and table_client_settings._native_timestamp_in_result_sets: + return _EPOCH + timedelta(microseconds=value_pb.int64_value) + return value_pb.int64_value + + +def _to_timestamp64(pb: ydb_value_pb2.Value, value: typing.Union[datetime, int]): + if isinstance(value, datetime): + if value.tzinfo: + epoch = _EPOCH_UTC + else: + epoch = _EPOCH + pb.int64_value = _timedelta_to_microseconds(value - epoch) + else: + pb.int64_value = value + + @enum.unique class PrimitiveType(enum.Enum): """ @@ -132,23 +164,46 @@ class PrimitiveType(enum.Enum): _from_date, _to_date, ) + Date32 = ( + _apis.primitive_types.DATE32, + None, + _from_date32, + _to_date32, + ) Datetime = ( _apis.primitive_types.DATETIME, "uint32_value", _from_datetime_number, ) + Datetime64 = ( + _apis.primitive_types.DATETIME64, + "int64_value", + _from_datetime_number, + ) Timestamp = ( _apis.primitive_types.TIMESTAMP, None, _from_timestamp, _to_timestamp, ) + Timestamp64 = ( + _apis.primitive_types.TIMESTAMP64, + None, + _from_timestamp64, + _to_timestamp64, + ) Interval = ( _apis.primitive_types.INTERVAL, None, _from_interval, _to_interval, ) + Interval64 = ( + _apis.primitive_types.INTERVAL64, + None, + _from_interval, + _to_interval, + ) DyNumber = _apis.primitive_types.DYNUMBER, "text_value" @@ -365,6 +420,32 @@ class DictType(AbstractTypeBuilder): return self._repr +class SetType(AbstractTypeBuilder): + __slots__ = ("__repr", "__proto") + + def __init__( + self, + key_type: typing.Union[AbstractTypeBuilder, PrimitiveType], + ): + """ + :param key_type: Key type builder + """ + self._repr = "Set<%s>" % (str(key_type)) + self._proto = _apis.ydb_value.Type( + dict_type=_apis.ydb_value.DictType( + key=key_type.proto, + payload=_apis.ydb_value.Type(void_type=struct_pb2.NULL_VALUE), + ) + ) + + @property + def proto(self): + return self._proto + + def __str__(self): + return self._repr + + class TupleType(AbstractTypeBuilder): __slots__ = ("__elements_repr", "__proto") diff --git a/contrib/python/ydb/py3/ydb/ydb_version.py b/contrib/python/ydb/py3/ydb/ydb_version.py index 6b71007009d..3c62627bc85 100644 --- a/contrib/python/ydb/py3/ydb/ydb_version.py +++ b/contrib/python/ydb/py3/ydb/ydb_version.py @@ -1 +1 @@ -VERSION = "3.21.0" +VERSION = "3.21.1" |
