-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add table settings support #22
Changes from 6 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
from decimal import Decimal | ||
from datetime import date, datetime | ||
|
||
import pytest | ||
import sqlalchemy as sa | ||
from sqlalchemy import Table, Column, Integer, Unicode | ||
|
||
from sqlalchemy.testing.fixtures import TestBase, TablesTest | ||
|
||
from datetime import date, datetime | ||
import ydb | ||
|
||
from ydb_sqlalchemy.sqlalchemy import types | ||
|
||
|
||
def clear_sql(stm): | ||
|
@@ -200,3 +203,164 @@ def test_select_types(self, connection): | |
|
||
row = connection.execute(sa.select(tb)).fetchone() | ||
assert row == (1, "Hello World!", 3.5, True, now, today) | ||
|
||
|
||
class TestWithClause(TablesTest): | ||
run_create_tables = "each" | ||
|
||
@staticmethod | ||
def _create_table_and_get_desc(connection, metadata, **kwargs): | ||
table = Table( | ||
"clause_with_test", | ||
metadata, | ||
Column("id", types.UInt32, primary_key=True), | ||
**kwargs, | ||
) | ||
table.create(connection) | ||
|
||
session: ydb.Session = connection.connection.driver_connection.pool.acquire() | ||
return session.describe_table("/local/" + table.name) | ||
|
||
@pytest.mark.parametrize( | ||
"auto_partitioning_by_size,res", | ||
[ | ||
(None, 1), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below: instead of hard-code int values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did I add it correctly?
|
||
(True, 1), | ||
(False, 2), | ||
], | ||
) | ||
def test_auto_partitioning_by_size(self, connection, auto_partitioning_by_size, res, metadata): | ||
desc = self._create_table_and_get_desc( | ||
connection, metadata, ydb_auto_partitioning_by_size=auto_partitioning_by_size | ||
) | ||
assert desc.partitioning_settings.partitioning_by_size == res | ||
|
||
@pytest.mark.parametrize( | ||
"auto_partitioning_by_load,res", | ||
[ | ||
(None, 2), | ||
(True, 1), | ||
(False, 2), | ||
], | ||
) | ||
def test_auto_partitioning_by_load(self, connection, auto_partitioning_by_load, res, metadata): | ||
desc = self._create_table_and_get_desc( | ||
connection, | ||
metadata, | ||
ydb_auto_partitioning_by_load=auto_partitioning_by_load, | ||
) | ||
assert desc.partitioning_settings.partitioning_by_load == res | ||
|
||
@pytest.mark.parametrize( | ||
"auto_partitioning_partition_size_mb,res", | ||
[ | ||
(None, 2048), | ||
(2000, 2000), | ||
], | ||
) | ||
def test_auto_partitioning_partition_size_mb(self, connection, auto_partitioning_partition_size_mb, res, metadata): | ||
desc = self._create_table_and_get_desc( | ||
connection, | ||
metadata, | ||
ydb_auto_partitioning_partition_size_mb=auto_partitioning_partition_size_mb, | ||
) | ||
assert desc.partitioning_settings.partition_size_mb == res | ||
|
||
@pytest.mark.parametrize( | ||
"auto_partitioning_min_partitions_count,res", | ||
[ | ||
(None, 1), | ||
(10, 10), | ||
], | ||
) | ||
def test_auto_partitioning_min_partitions_count( | ||
self, | ||
connection, | ||
auto_partitioning_min_partitions_count, | ||
res, | ||
metadata, | ||
): | ||
desc = self._create_table_and_get_desc( | ||
connection, | ||
metadata, | ||
ydb_auto_partitioning_min_partitions_count=auto_partitioning_min_partitions_count, | ||
) | ||
assert desc.partitioning_settings.min_partitions_count == res | ||
|
||
@pytest.mark.parametrize( | ||
"auto_partitioning_max_partitions_count,res", | ||
[ | ||
(None, 0), | ||
(10, 10), | ||
], | ||
) | ||
def test_auto_partitioning_max_partitions_count( | ||
self, | ||
connection, | ||
auto_partitioning_max_partitions_count, | ||
res, | ||
metadata, | ||
): | ||
desc = self._create_table_and_get_desc( | ||
connection, | ||
metadata, | ||
ydb_auto_partitioning_max_partitions_count=auto_partitioning_max_partitions_count, | ||
) | ||
assert desc.partitioning_settings.max_partitions_count == res | ||
|
||
@pytest.mark.parametrize( | ||
"uniform_partitions,res", | ||
[ | ||
(None, 1), | ||
(10, 10), | ||
], | ||
) | ||
def test_uniform_partitions( | ||
self, | ||
connection, | ||
uniform_partitions, | ||
res, | ||
metadata, | ||
): | ||
desc = self._create_table_and_get_desc( | ||
connection, | ||
metadata, | ||
ydb_uniform_partitions=uniform_partitions, | ||
) | ||
# it not only do the initiation partition but also set up the minimum partition count | ||
assert desc.partitioning_settings.min_partitions_count == res | ||
|
||
@pytest.mark.parametrize( | ||
"partition_at_keys,res", | ||
[ | ||
(None, 1), | ||
((100, 1000), 3), | ||
], | ||
) | ||
def test_partition_at_keys( | ||
self, | ||
connection, | ||
partition_at_keys, | ||
res, | ||
metadata, | ||
): | ||
desc = self._create_table_and_get_desc( | ||
connection, | ||
metadata, | ||
ydb_partition_at_keys=partition_at_keys, | ||
) | ||
assert desc.partitioning_settings.min_partitions_count == res | ||
|
||
def test_several_keys(self, connection, metadata): | ||
desc = self._create_table_and_get_desc( | ||
connection, | ||
metadata, | ||
ydb_auto_partitioning_by_size=True, | ||
ydb_auto_partitioning_by_load=True, | ||
ydb_auto_partitioning_min_partitions_count=3, | ||
ydb_auto_partitioning_max_partitions_count=5, | ||
) | ||
assert desc.partitioning_settings.partitioning_by_size == 1 | ||
assert desc.partitioning_settings.partitioning_by_load == 1 | ||
assert desc.partitioning_settings.min_partitions_count == 3 | ||
assert desc.partitioning_settings.max_partitions_count == 5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import ydb | ||
import time | ||
|
||
|
||
def wait_container_ready(driver): | ||
driver.wait(timeout=30) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: We have to return this session to the pool at the end, but it's not crucial in tests I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be problem in tests too - pool has limited sessions (default 100), if the limit will be reached - code can't get new session.
It is not big problem in one place, but it will be problem in loops or if many tests will not return the session.
especially if reuse connection (and session pool) between tests.
It is better to fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added calling of
delete()
method for session