|
| 1 | +from hamcrest import assert_that, only_contains |
| 2 | +import os |
| 3 | +import pytest |
| 4 | + |
| 5 | +import yatest |
| 6 | + |
| 7 | +CLUSTER_CONFIG = dict(extra_feature_flags=["enable_external_data_sources"]) |
| 8 | + |
| 9 | + |
| 10 | +def bin_from_env(var): |
| 11 | + if os.getenv(var): |
| 12 | + return yatest.common.binary_path(os.getenv(var)) |
| 13 | + raise RuntimeError(f"{var} environment variable is not specified") |
| 14 | + |
| 15 | + |
| 16 | +def ydb_bin(): |
| 17 | + return bin_from_env("YDB_CLI_BINARY") |
| 18 | + |
| 19 | + |
| 20 | +def execute_ydb_cli_command(node, database, args, stdin=None): |
| 21 | + execution = yatest.common.execute( |
| 22 | + [ydb_bin(), "--endpoint", f"grpc://{node.host}:{node.grpc_port}", "--database", database] + args, stdin=stdin |
| 23 | + ) |
| 24 | + return execution.std_out.decode("utf-8") |
| 25 | + |
| 26 | + |
| 27 | +def create_table(session, table): |
| 28 | + session.execute_scheme( |
| 29 | + f""" |
| 30 | + CREATE TABLE `{table}` (key Int, value Utf8, PRIMARY KEY(key)); |
| 31 | + """ |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +def create_view(session, view, query="SELECT 42"): |
| 36 | + session.execute_scheme( |
| 37 | + f""" |
| 38 | + CREATE VIEW `{view}` WITH security_invoker = TRUE AS {query}; |
| 39 | + """ |
| 40 | + ) |
| 41 | + |
| 42 | + |
| 43 | +def create_external_data_source(session, external_data_source): |
| 44 | + session.execute_scheme( |
| 45 | + f""" |
| 46 | + CREATE EXTERNAL DATA SOURCE `{external_data_source}` WITH ( |
| 47 | + SOURCE_TYPE="ObjectStorage", |
| 48 | + LOCATION="192.168.1.1:8123", |
| 49 | + AUTH_METHOD="NONE" |
| 50 | + ); |
| 51 | + """ |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +def create_external_table(session, external_table, external_data_source): |
| 56 | + session.execute_scheme( |
| 57 | + f""" |
| 58 | + CREATE EXTERNAL TABLE `{external_table}` ( |
| 59 | + key Utf8 NOT NULL, |
| 60 | + value Utf8 NOT NULL |
| 61 | + ) WITH ( |
| 62 | + DATA_SOURCE="{external_data_source}", |
| 63 | + LOCATION="folder", |
| 64 | + FORMAT="csv_with_names", |
| 65 | + COMPRESSION="gzip" |
| 66 | + ); |
| 67 | + """ |
| 68 | + ) |
| 69 | + |
| 70 | + |
| 71 | +class TestRecursiveRemove: |
| 72 | + @pytest.fixture(autouse=True, scope="function") |
| 73 | + def init_test(self, tmp_path): |
| 74 | + self.tmp_path = tmp_path |
| 75 | + |
| 76 | + def test_various_scheme_objects(self, ydb_cluster, ydb_database, ydb_client, ydb_client_session): |
| 77 | + database_path = ydb_database |
| 78 | + driver = ydb_client(database_path) |
| 79 | + session_pool = ydb_client_session(database_path) |
| 80 | + with session_pool.checkout() as session: |
| 81 | + create_table(session, "table") |
| 82 | + create_view(session, "views/view") |
| 83 | + create_external_data_source(session, "externals/data_source") |
| 84 | + create_external_table(session, "externals/table", "externals/data_source") |
| 85 | + execute_ydb_cli_command( |
| 86 | + ydb_cluster.nodes[1], database_path, ["scheme", "rmdir", "--recursive", "--force", "."] |
| 87 | + ) |
| 88 | + assert_that( |
| 89 | + [child.name for child in driver.scheme_client.list_directory(database_path).children], |
| 90 | + only_contains(".metadata", ".sys"), |
| 91 | + ) |
0 commit comments