Skip to content

Commit c8c8e41

Browse files
authored
Add compatibility test for external data tables (#26435)
1 parent 17ae681 commit c8c8e41

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# -*- coding: utf-8 -*-
2+
import boto3
3+
import pytest
4+
import yatest
5+
import os
6+
7+
from ydb.tests.oss.ydb_sdk_import import ydb
8+
from ydb.tests.library.compatibility.fixtures import MixedClusterFixture, RestartToAnotherVersionFixture, RollingUpgradeAndDowngradeFixture
9+
10+
from ydb.export import ExportToS3Settings
11+
12+
13+
class ExternalDataTableTestBase:
14+
def setup_cluster(self):
15+
if min(self.versions) < (25, 1):
16+
pytest.skip("Only available since 25-1")
17+
18+
output_path = yatest.common.test_output_path()
19+
self.output_f = open(os.path.join(output_path, "out.log"), "w")
20+
self.s3_config = self.setup_s3()
21+
s3_endpoint, s3_access_key, s3_secret_key, s3_bucket = self.s3_config
22+
self.settings = (
23+
ExportToS3Settings()
24+
.with_endpoint(s3_endpoint)
25+
.with_access_key(s3_access_key)
26+
.with_secret_key(s3_secret_key)
27+
.with_bucket(s3_bucket)
28+
)
29+
30+
yield from super().setup_cluster(
31+
extra_feature_flags={
32+
"enable_external_data_sources": True,
33+
}
34+
)
35+
36+
@staticmethod
37+
def setup_s3():
38+
s3_endpoint = os.getenv("S3_ENDPOINT")
39+
s3_access_key = "minio"
40+
s3_secret_key = "minio123"
41+
s3_bucket = "test_bucket"
42+
43+
resource = boto3.resource(
44+
"s3", endpoint_url=s3_endpoint, aws_access_key_id=s3_access_key, aws_secret_access_key=s3_secret_key
45+
)
46+
47+
bucket = resource.Bucket(s3_bucket)
48+
bucket.create()
49+
bucket.objects.all().delete()
50+
bucket.put_object(Key="file.txt", Body="Hello S3!")
51+
52+
return s3_endpoint, s3_access_key, s3_secret_key, s3_bucket
53+
54+
def create_external_data_source(self):
55+
s3_endpoint, s3_access_key, s3_secret_key, s3_bucket = self.s3_config
56+
57+
with ydb.QuerySessionPool(self.driver) as session_pool:
58+
query = f"""
59+
CREATE OBJECT s3_access_key (TYPE SECRET) WITH value="{s3_access_key}";
60+
CREATE OBJECT s3_secret_key (TYPE SECRET) WITH value="{s3_secret_key}";
61+
"""
62+
session_pool.execute_with_retries(query)
63+
64+
query = f"""
65+
CREATE EXTERNAL DATA SOURCE s3_source WITH (
66+
SOURCE_TYPE = "ObjectStorage",
67+
LOCATION = "{s3_endpoint}/{s3_bucket}",
68+
AUTH_METHOD="AWS",
69+
AWS_ACCESS_KEY_ID_SECRET_NAME="s3_access_key",
70+
AWS_SECRET_ACCESS_KEY_SECRET_NAME="s3_secret_key",
71+
AWS_REGION="us-east-1"
72+
);
73+
"""
74+
session_pool.execute_with_retries(query)
75+
76+
def do_test_external_data(self):
77+
s3_endpoint, s3_access_key, s3_secret_key, s3_bucket = self.s3_config
78+
79+
with ydb.QuerySessionPool(self.driver) as session_pool:
80+
query = """
81+
SELECT * FROM s3_source.`file.txt` WITH (
82+
FORMAT = "raw",
83+
SCHEMA = ( Data String )
84+
);
85+
"""
86+
result_sets = session_pool.execute_with_retries(query)
87+
data = result_sets[0].rows[0]['Data']
88+
assert isinstance(data, bytes) and data.decode() == 'Hello S3!'
89+
90+
91+
class TestExternalDataTableMixedCluster(ExternalDataTableTestBase, MixedClusterFixture):
92+
@pytest.fixture(autouse=True, scope="function")
93+
def setup(self):
94+
yield from self.setup_cluster()
95+
96+
def test_external_data_source(self):
97+
self.create_external_data_source()
98+
self.do_test_external_data()
99+
100+
101+
class TestExternalDataTableRestartToAnotherVersion(ExternalDataTableTestBase, RestartToAnotherVersionFixture):
102+
@pytest.fixture(autouse=True, scope="function")
103+
def setup(self):
104+
yield from self.setup_cluster()
105+
106+
def test_external_data_source(self):
107+
self.create_external_data_source()
108+
self.change_cluster_version()
109+
self.do_test_external_data()
110+
111+
112+
class TestExternalDataTableRollingUpgradeAndDowngrade(ExternalDataTableTestBase, RollingUpgradeAndDowngradeFixture):
113+
@pytest.fixture(autouse=True, scope="function")
114+
def setup(self):
115+
yield from self.setup_cluster()
116+
117+
def test_external_data_source(self):
118+
self.create_external_data_source()
119+
for _ in self.roll():
120+
self.do_test_external_data()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
PY3TEST()
2+
INCLUDE(${ARCADIA_ROOT}/ydb/tests/ydbd_dep.inc)
3+
4+
FORK_TEST_FILES()
5+
FORK_TESTS()
6+
FORK_SUBTESTS()
7+
SPLIT_FACTOR(10)
8+
9+
TEST_SRCS(
10+
test_external_data_source.py
11+
)
12+
13+
SIZE(LARGE)
14+
REQUIREMENTS(cpu:16)
15+
INCLUDE(${ARCADIA_ROOT}/ydb/tests/large.inc)
16+
INCLUDE(${ARCADIA_ROOT}/ydb/tests/tools/s3_recipe/recipe.inc)
17+
18+
19+
DEPENDS(
20+
ydb/tests/library/compatibility/binaries
21+
)
22+
23+
PEERDIR(
24+
contrib/python/boto3
25+
ydb/tests/library
26+
ydb/tests/library/compatibility
27+
)
28+
29+
END()

ydb/tests/compatibility/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ PEERDIR(
5151
END()
5252

5353
RECURSE(
54+
federated_queries
5455
s3_backups
5556
olap
5657
)

0 commit comments

Comments
 (0)