Skip to content

Add missing fields to tablestats #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/table/test_table_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions ydb/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
Loading