Skip to content

Commit 0a57b8a

Browse files
committed
passing functional test
1 parent a60edef commit 0a57b8a

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

ydb/public/lib/ydb_cli/common/recursive_remove.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ namespace NInternal {
273273

274274
bool MightHaveDependents(ESchemeEntryType type) {
275275
switch (type) {
276+
// directories might contain external data sources, which might have dependent objects (i.e. external tables)
277+
case ESchemeEntryType::Directory:
276278
case ESchemeEntryType::ExternalDataSource:
277279
return true;
278280
default:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
)

ydb/tests/functional/ydb_cli/ya.make

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ PY3TEST()
33
TEST_SRCS(
44
conftest.py
55
test_ydb_backup.py
6-
test_ydb_table.py
7-
test_ydb_scripting.py
8-
test_ydb_impex.py
96
test_ydb_flame_graph.py
7+
test_ydb_impex.py
8+
test_ydb_recursive_remove.py
109
test_ydb_scheme.py
10+
test_ydb_scripting.py
1111
test_ydb_sql.py
12+
test_ydb_table.py
1213
)
1314

1415
ENV(YDB_DRIVER_BINARY="ydb/apps/ydbd/ydbd")

0 commit comments

Comments
 (0)