diff --git a/ydb/tests/olap/lib/ydb_cluster.py b/ydb/tests/olap/lib/ydb_cluster.py index 72ca9679e0bc..573a090d368f 100644 --- a/ydb/tests/olap/lib/ydb_cluster.py +++ b/ydb/tests/olap/lib/ydb_cluster.py @@ -8,7 +8,7 @@ from ydb.tests.olap.lib.utils import get_external_param from copy import deepcopy from time import sleep, time -from typing import List, Optional +from typing import List, Optional, Callable from enum import Enum LOGGER = logging.getLogger() @@ -172,17 +172,20 @@ def get_ydb_driver(cls): return cls._ydb_driver @classmethod - def list_directory(cls, root_path: str, rel_path: str) -> List[ydb.SchemeEntry]: + def list_directory(cls, root_path: str, rel_path: str, kind_order_key: Optional[Callable[[ydb.SchemeEntryType], int]] = None) -> List[ydb.SchemeEntry]: path = f'{root_path}/{rel_path}' if root_path else rel_path LOGGER.info(f'list {path}') result = [] - for child in cls.get_ydb_driver().scheme_client.list_directory(path).children: + entries = cls.get_ydb_driver().scheme_client.list_directory(path).children + if kind_order_key is not None: + entries = sorted(entries, key=lambda x: kind_order_key(x.type)) + for child in entries: if child.name == '.sys': continue child.name = f'{rel_path}/{child.name}' result.append(child) if child.is_directory() or child.is_column_store(): - result += cls.list_directory(root_path, child.name) + result += cls.list_directory(root_path, child.name, kind_order_key) return result @classmethod diff --git a/ydb/tests/olap/scenario/helpers/scenario_tests_helper.py b/ydb/tests/olap/scenario/helpers/scenario_tests_helper.py index 5768867f9f5e..b8039acc5aa1 100644 --- a/ydb/tests/olap/scenario/helpers/scenario_tests_helper.py +++ b/ydb/tests/olap/scenario/helpers/scenario_tests_helper.py @@ -679,8 +679,20 @@ def list_path(self, path: str, folder: str) -> List[ydb.SchemeEntry]: if self_descr is None: return [] + kind_order = [ + ydb.SchemeEntryType.COLUMN_TABLE, + ydb.SchemeEntryType.COLUMN_STORE, + ydb.SchemeEntryType.EXTERNAL_DATA_SOURCE, + ] + + def kind_order_key_reversed(kind): + try: + return -kind_order.index(kind) + except ValueError: + return -len(kind_order) + if self_descr.is_directory(): - return list(reversed(YdbCluster.list_directory(root_path, path))) + [self_descr] + return list(reversed(YdbCluster.list_directory(root_path, path, kind_order_key_reversed))) + [self_descr] else: return self_descr