diff --git a/tests/table/test_table_client.py b/tests/table/test_table_client.py index f4e121c8..ef0de906 100644 --- a/tests/table/test_table_client.py +++ b/tests/table/test_table_client.py @@ -86,3 +86,47 @@ def test_copy_table(self, driver_sync: ydb.Driver): copied_description = client.describe_table(table_name + "_copy") assert description.columns == copied_description.columns + + def test_describe_table_creation_time(self, driver_sync: ydb.Driver): + client = driver_sync.table_client + + table_name = "/local/testtableclient" + try: + client.drop_table(table_name) + except ydb.SchemeError: + pass + + description = ( + ydb.TableDescription() + .with_primary_keys("key1", "key2") + .with_columns( + ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)), + ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)), + ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)), + ) + ) + + client.create_table(table_name, description) + + desc_before = client.describe_table( + table_name, + ydb.DescribeTableSettings().with_include_table_stats(True), + ) + + assert desc_before.table_stats is not None + + client.alter_table( + table_name, + add_columns=[ + ydb.Column("value2", ydb.OptionalType(ydb.PrimitiveType.Uint64)), + ], + ) + + desc_after = client.describe_table( + table_name, + ydb.DescribeTableSettings().with_include_table_stats(True), + ) + + assert desc_after.table_stats is not None + + assert desc_before.table_stats.creation_time == desc_after.table_stats.creation_time diff --git a/ydb/table.py b/ydb/table.py index 945e9187..ac73902f 100644 --- a/ydb/table.py +++ b/ydb/table.py @@ -545,6 +545,9 @@ class TableStats(object): def __init__(self): self.partitions = None self.store_size = 0 + self.rows_estimate = 0 + self.creation_time = None + self.modification_time = None def with_store_size(self, store_size): self.store_size = store_size @@ -554,6 +557,18 @@ def with_partitions(self, partitions): self.partitions = partitions return self + def with_rows_estimate(self, rows_estimate): + self.rows_estimate = rows_estimate + return self + + def with_creation_time(self, creation_time): + self.creation_time = creation_time + return self + + def with_modification_time(self, modification_time): + self.modification_time = modification_time + return self + class ReadReplicasSettings(object): def __init__(self): @@ -1577,7 +1592,22 @@ def __init__( self.table_stats = None if table_stats is not None: + from ._grpc.grpcwrapper.common_utils import datetime_from_proto_timestamp + self.table_stats = TableStats() + if table_stats.creation_time: + self.table_stats = self.table_stats.with_creation_time( + datetime_from_proto_timestamp(table_stats.creation_time) + ) + + if table_stats.modification_time: + self.table_stats = self.table_stats.with_modification_time( + datetime_from_proto_timestamp(table_stats.modification_time) + ) + + if table_stats.rows_estimate != 0: + self.table_stats = self.table_stats.with_rows_estimate(table_stats.rows_estimate) + if table_stats.partitions != 0: self.table_stats = self.table_stats.with_partitions(table_stats.partitions)