Skip to content

Commit 4943aec

Browse files
authored
Merge pull request #575 from ydb-platform/update_describe_table_structure
Add missing fields to tablestats
2 parents f184eaa + f876a90 commit 4943aec

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

tests/table/test_table_client.py

+44
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,47 @@ def test_copy_table(self, driver_sync: ydb.Driver):
8686
copied_description = client.describe_table(table_name + "_copy")
8787

8888
assert description.columns == copied_description.columns
89+
90+
def test_describe_table_creation_time(self, driver_sync: ydb.Driver):
91+
client = driver_sync.table_client
92+
93+
table_name = "/local/testtableclient"
94+
try:
95+
client.drop_table(table_name)
96+
except ydb.SchemeError:
97+
pass
98+
99+
description = (
100+
ydb.TableDescription()
101+
.with_primary_keys("key1", "key2")
102+
.with_columns(
103+
ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
104+
ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
105+
ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)),
106+
)
107+
)
108+
109+
client.create_table(table_name, description)
110+
111+
desc_before = client.describe_table(
112+
table_name,
113+
ydb.DescribeTableSettings().with_include_table_stats(True),
114+
)
115+
116+
assert desc_before.table_stats is not None
117+
118+
client.alter_table(
119+
table_name,
120+
add_columns=[
121+
ydb.Column("value2", ydb.OptionalType(ydb.PrimitiveType.Uint64)),
122+
],
123+
)
124+
125+
desc_after = client.describe_table(
126+
table_name,
127+
ydb.DescribeTableSettings().with_include_table_stats(True),
128+
)
129+
130+
assert desc_after.table_stats is not None
131+
132+
assert desc_before.table_stats.creation_time == desc_after.table_stats.creation_time

ydb/table.py

+30
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ class TableStats(object):
545545
def __init__(self):
546546
self.partitions = None
547547
self.store_size = 0
548+
self.rows_estimate = 0
549+
self.creation_time = None
550+
self.modification_time = None
548551

549552
def with_store_size(self, store_size):
550553
self.store_size = store_size
@@ -554,6 +557,18 @@ def with_partitions(self, partitions):
554557
self.partitions = partitions
555558
return self
556559

560+
def with_rows_estimate(self, rows_estimate):
561+
self.rows_estimate = rows_estimate
562+
return self
563+
564+
def with_creation_time(self, creation_time):
565+
self.creation_time = creation_time
566+
return self
567+
568+
def with_modification_time(self, modification_time):
569+
self.modification_time = modification_time
570+
return self
571+
557572

558573
class ReadReplicasSettings(object):
559574
def __init__(self):
@@ -1577,7 +1592,22 @@ def __init__(
15771592

15781593
self.table_stats = None
15791594
if table_stats is not None:
1595+
from ._grpc.grpcwrapper.common_utils import datetime_from_proto_timestamp
1596+
15801597
self.table_stats = TableStats()
1598+
if table_stats.creation_time:
1599+
self.table_stats = self.table_stats.with_creation_time(
1600+
datetime_from_proto_timestamp(table_stats.creation_time)
1601+
)
1602+
1603+
if table_stats.modification_time:
1604+
self.table_stats = self.table_stats.with_modification_time(
1605+
datetime_from_proto_timestamp(table_stats.modification_time)
1606+
)
1607+
1608+
if table_stats.rows_estimate != 0:
1609+
self.table_stats = self.table_stats.with_rows_estimate(table_stats.rows_estimate)
1610+
15811611
if table_stats.partitions != 0:
15821612
self.table_stats = self.table_stats.with_partitions(table_stats.partitions)
15831613

0 commit comments

Comments
 (0)