Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ai generated test #16003

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions ydb/tests/olap/table_operations/test_table_rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest
from ydb.tests.olap.lib.ydb_cli import YdbCli
from hamcrest import assert_that, has_item, not_, has_property, contains_string


class TestOlapTableRename(object):
@classmethod
def setup_class(cls):
cls.cli = YdbCli()
cls.database = '/my-db'
cls.base_table_path = 'olap_table_rename_test'

cls.table_schema = '''
CREATE TABLE {path} (
id Uint64,
data String,
PRIMARY KEY (id)
) WITH (
STORE = COLUMN,
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 1
)
'''

def setup_method(self, method):
self.table_name = f'{self.base_table_path}_{method.__name__}'
self.cli.execute_scheme(self.table_schema.format(path=self.table_name))

def teardown_method(self, method):
try:
self.cli.execute_scheme(f'DROP TABLE `{self.table_name}`')
except Exception:
pass

@pytest.mark.olap
@pytest.mark.operations
def test_olap_table_rename(self):
new_table_name = f'{self.table_name}_renamed'
test_data = [(1, "Test1"), (2, "Test2")]

self.cli.execute_ydb(f'''
UPSERT INTO `{self.table_name}`
SELECT * FROM AS_TABLE({test_data});
''')

self.cli.execute_scheme(
f'ALTER TABLE `{self.table_name}` RENAME TO `{new_table_name}`'
)

with pytest.raises(Exception) as excinfo:
self.cli.execute_ydb(f'SELECT * FROM `{self.table_name}`')
assert_that(str(excinfo.value), contains_string("Table not found"))

desc = self.cli.describe_table(new_table_name)
assert_that(desc.columns, has_item(has_property('name', 'id')))
assert_that(desc.columns, has_item(has_property('name', 'data')))

result = self.cli.execute_ydb(f'''
SELECT data FROM `{new_table_name}` ORDER BY id
''')
assert [r.data for r in result] == ['Test1', 'Test2']

table_info = self.cli.execute_ydb(f'''
SELECT TableSettings FROM .describe_table('{new_table_name}')
''')
16 changes: 16 additions & 0 deletions ydb/tests/olap/table_operations/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PY3TEST()

SRCS(
GLOBAL
test_table_rename.py
)

PEERDIR(
ydb/tests/olap/lib
ydb/public/sdk/python3
library/python/testing/hamcrest
)

DATA(
arcadia/ydb/tests/olap/config
)
1 change: 1 addition & 0 deletions ydb/tests/olap/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ END()

RECURSE(
lib
table_operations
s3_import
scenario
docs
Expand Down
Loading