diff options
author | robot-kikimr-dev <robot-kikimr-dev@yandex-team.ru> | 2022-05-23 12:23:35 +0300 |
---|---|---|
committer | robot-kikimr-dev <robot-kikimr-dev@yandex-team.ru> | 2022-05-23 12:23:35 +0300 |
commit | 996ea27086264b82f898b615acda697847a07777 (patch) | |
tree | 2e5834a0237c57a8e7bc152102d13b997b6055c3 | |
parent | 66e2e2aa51a133882a1f82eb3696551a46d7a698 (diff) | |
download | ydb-996ea27086264b82f898b615acda697847a07777.tar.gz |
Sync YDB SDK from github
Release YDB recipe binaries
ref:c59178524c8aa1e89fd9464cf252501f105f57ee
-rw-r--r-- | ydb/public/sdk/python/CHANGELOG.md | 4 | ||||
-rw-r--r-- | ydb/public/sdk/python/README.md | 3 | ||||
-rw-r--r-- | ydb/public/sdk/python/setup.py | 7 | ||||
-rw-r--r-- | ydb/public/sdk/python/tests/aio/test_async_iter_stream.py | 46 | ||||
-rw-r--r-- | ydb/public/sdk/python/ydb/table.py | 24 | ||||
-rw-r--r-- | ydb/public/sdk/python/ydb/ydb_version.py | 2 | ||||
-rw-r--r-- | ydb/public/sdk/python/ydb_version.py | 1 |
7 files changed, 78 insertions, 9 deletions
diff --git a/ydb/public/sdk/python/CHANGELOG.md b/ydb/public/sdk/python/CHANGELOG.md index e39d0ae2f7..ff06ef3d79 100644 --- a/ydb/public/sdk/python/CHANGELOG.md +++ b/ydb/public/sdk/python/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.4.0 ## + +* support query stats in scan query + ## 2.2.0 ## * allow to refer endpoints by node id diff --git a/ydb/public/sdk/python/README.md b/ydb/public/sdk/python/README.md index f69cd4ac0f..fa3d11a384 100644 --- a/ydb/public/sdk/python/README.md +++ b/ydb/public/sdk/python/README.md @@ -1,3 +1,4 @@ -Python SDK for Yandex Database (YDB) +YDB Python SDK --- + Officially supported Python client for YDB. diff --git a/ydb/public/sdk/python/setup.py b/ydb/public/sdk/python/setup.py index 672d7b7866..473cd03096 100644 --- a/ydb/public/sdk/python/setup.py +++ b/ydb/public/sdk/python/setup.py @@ -1,15 +1,10 @@ # -*- coding: utf-8 -*- import setuptools -try: - from ydb_version import VERSION -except ImportError: - VERSION = "0.0.1-dev" - setuptools.setup( name="ydb", - version=VERSION, + version="2.4.0", description="YDB Python library", author="Yandex LLC", author_email="ydb@yandex-team.ru", diff --git a/ydb/public/sdk/python/tests/aio/test_async_iter_stream.py b/ydb/public/sdk/python/tests/aio/test_async_iter_stream.py index c88104991f..02562a362c 100644 --- a/ydb/public/sdk/python/tests/aio/test_async_iter_stream.py +++ b/ydb/public/sdk/python/tests/aio/test_async_iter_stream.py @@ -33,6 +33,52 @@ async def test_read_table(driver, database): @pytest.mark.asyncio +async def test_scan_query_with_query_stats(driver, database): + description = ( + ydb.TableDescription() + .with_primary_keys("key1") + .with_columns( + ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)), + ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)), + ) + ) + + session = await driver.table_client.session().create() + await session.create_table( + database + "/test_scan_query_with_query_stats", description + ) + await session.transaction(ydb.SerializableReadWrite()).execute( + """INSERT INTO `test_scan_query_with_query_stats` (`key1`, `value`) VALUES (1, "hello_world"), (2, "2")""", + commit_tx=True, + ) + + expected_res = [{"key1": 1, "value": "hello_world"}, {"key1": 2, "value": "2"}] + i = 0 + async for resp in await driver.table_client.scan_query( + "select * from `test_scan_query_with_query_stats` order by key1" + ): + for row in resp.result_set.rows: + assert row == expected_res[i] + i += 1 + + i = 0 + settings = ydb.ScanQuerySettings().with_collect_stats( + ydb.QueryStatsCollectionMode.FULL + ) + last_response = None + async for resp in await driver.table_client.scan_query( + "select * from `test_scan_query_with_query_stats` order by key1", + settings=settings, + ): + last_response = resp + for row in resp.result_set.rows: + assert row == expected_res[i] + i += 1 + + assert len(last_response.query_stats.query_phases) > 0 + + +@pytest.mark.asyncio async def test_read_shard_table(driver, database): session: ydb.ISession = await driver.table_client.session().create() test_name = "read_shard_table" diff --git a/ydb/public/sdk/python/ydb/table.py b/ydb/public/sdk/python/ydb/table.py index 97b1fba85f..c3c083d312 100644 --- a/ydb/public/sdk/python/ydb/table.py +++ b/ydb/public/sdk/python/ydb/table.py @@ -1027,11 +1027,29 @@ class TableClientSettings(object): class ScanQueryResult(object): def __init__(self, result, table_client_settings): self._result = result + self.query_stats = result.query_stats self.result_set = convert.ResultSet.from_message( self._result.result_set, table_client_settings ) +@enum.unique +class QueryStatsCollectionMode(enum.IntEnum): + NONE = _apis.ydb_table.QueryStatsCollection.Mode.STATS_COLLECTION_NONE + BASIC = _apis.ydb_table.QueryStatsCollection.Mode.STATS_COLLECTION_BASIC + FULL = _apis.ydb_table.QueryStatsCollection.Mode.STATS_COLLECTION_FULL + + +class ScanQuerySettings(settings_impl.BaseRequestSettings): + def __init__(self): + super(ScanQuerySettings, self).__init__() + self.collect_stats = None + + def with_collect_stats(self, collect_stats_mode): + self.collect_stats = collect_stats_mode + return self + + class ScanQuery(object): def __init__(self, yql_text, parameters_types): self.yql_text = yql_text @@ -1047,10 +1065,16 @@ def _scan_query_request_factory(query, parameters=None, settings=None): if not isinstance(query, ScanQuery): query = ScanQuery(query, {}) parameters = {} if parameters is None else parameters + collect_stats = getattr( + settings, + "collect_stats", + _apis.ydb_table.QueryStatsCollection.Mode.STATS_COLLECTION_NONE, + ) return _apis.ydb_table.ExecuteScanQueryRequest( mode=_apis.ydb_table.ExecuteScanQueryRequest.Mode.MODE_EXEC, query=_apis.ydb_table.Query(yql_text=query.yql_text), parameters=convert.parameters_to_pb(query.parameters_types, parameters), + collect_stats=collect_stats, ) diff --git a/ydb/public/sdk/python/ydb/ydb_version.py b/ydb/public/sdk/python/ydb/ydb_version.py index 707faadc7e..02c476a630 100644 --- a/ydb/public/sdk/python/ydb/ydb_version.py +++ b/ydb/public/sdk/python/ydb/ydb_version.py @@ -1 +1 @@ -VERSION = "2.3.0" +VERSION = "2.4.0" diff --git a/ydb/public/sdk/python/ydb_version.py b/ydb/public/sdk/python/ydb_version.py deleted file mode 100644 index 707faadc7e..0000000000 --- a/ydb/public/sdk/python/ydb_version.py +++ /dev/null @@ -1 +0,0 @@ -VERSION = "2.3.0" |