Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Ilchuk committed Dec 19, 2023
1 parent 293d9b8 commit 562e367
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
entry_points={
"sqlalchemy.dialects": [
"yql.ydb=ydb_sqlalchemy.sqlalchemy:YqlDialect",
"yql=ydb_sqlalchemy.sqlalchemy:YqlDialect",
"ydb=ydb_sqlalchemy.sqlalchemy:YqlDialect",
]
},
)
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sqlalchemy.dialects import registry

registry.register("yql.ydb", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")
registry.register("ydb", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")
pytest.register_assert_rewrite("sqlalchemy.testing.assertions")

from sqlalchemy.testing.plugin.pytestplugin import * # noqa: E402, F401, F403
14 changes: 7 additions & 7 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _create_table_and_get_desc(connection, metadata, **kwargs):
)
def test_auto_partitioning_by_size(self, connection, auto_partitioning_by_size, res, metadata):
desc = self._create_table_and_get_desc(
connection, metadata, yql_auto_partitioning_by_size=auto_partitioning_by_size
connection, metadata, ydb_auto_partitioning_by_size=auto_partitioning_by_size
)
assert desc.partitioning_settings.partitioning_by_size == res

Expand All @@ -247,7 +247,7 @@ def test_auto_partitioning_by_load(self, connection, auto_partitioning_by_load,
desc = self._create_table_and_get_desc(
connection,
metadata,
yql_auto_partitioning_by_load=auto_partitioning_by_load,
ydb_auto_partitioning_by_load=auto_partitioning_by_load,
)
assert desc.partitioning_settings.partitioning_by_load == res

Expand All @@ -262,7 +262,7 @@ def test_auto_partitioning_partition_size_mb(self, connection, auto_partitioning
desc = self._create_table_and_get_desc(
connection,
metadata,
yql_auto_partitioning_partition_size_mb=auto_partitioning_partition_size_mb,
ydb_auto_partitioning_partition_size_mb=auto_partitioning_partition_size_mb,
)
assert desc.partitioning_settings.partition_size_mb == res

Expand All @@ -283,7 +283,7 @@ def test_auto_partitioning_min_partitions_count(
desc = self._create_table_and_get_desc(
connection,
metadata,
yql_auto_partitioning_min_partitions_count=auto_partitioning_min_partitions_count,
ydb_auto_partitioning_min_partitions_count=auto_partitioning_min_partitions_count,
)
assert desc.partitioning_settings.min_partitions_count == res

Expand All @@ -304,7 +304,7 @@ def test_auto_partitioning_max_partitions_count(
desc = self._create_table_and_get_desc(
connection,
metadata,
yql_auto_partitioning_max_partitions_count=auto_partitioning_max_partitions_count,
ydb_auto_partitioning_max_partitions_count=auto_partitioning_max_partitions_count,
)
assert desc.partitioning_settings.max_partitions_count == res

Expand All @@ -325,7 +325,7 @@ def test_uniform_partitions(
desc = self._create_table_and_get_desc(
connection,
metadata,
yql_uniform_partitions=uniform_partitions,
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
Expand All @@ -347,6 +347,6 @@ def test_partition_at_keys(
desc = self._create_table_and_get_desc(
connection,
metadata,
yql_partition_at_keys=partition_at_keys,
ydb_partition_at_keys=partition_at_keys,
)
assert desc.partitioning_settings.min_partitions_count == res
30 changes: 15 additions & 15 deletions ydb_sqlalchemy/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,30 +344,30 @@ def get_bind_types(

class YqlDDLCompiler(DDLCompiler):
def post_create_table(self, table):
yql_opts = table.dialect_options["yql"]
ydb_opts = table.dialect_options["ydb"]
with_content = []
if yql_opts["auto_partitioning_by_size"] is not None:
auto_partitioning_by_size = "ENABLED" if yql_opts["auto_partitioning_by_size"] else "DISABLED"
if ydb_opts["auto_partitioning_by_size"] is not None:
auto_partitioning_by_size = "ENABLED" if ydb_opts["auto_partitioning_by_size"] else "DISABLED"
with_content.append(f"AUTO_PARTITIONING_BY_SIZE = {auto_partitioning_by_size}")
if yql_opts["auto_partitioning_by_load"] is not None:
auto_partitioning_by_load = "ENABLED" if yql_opts["auto_partitioning_by_load"] else "DISABLED"
if ydb_opts["auto_partitioning_by_load"] is not None:
auto_partitioning_by_load = "ENABLED" if ydb_opts["auto_partitioning_by_load"] else "DISABLED"
with_content.append(f"AUTO_PARTITIONING_BY_LOAD = {auto_partitioning_by_load}")
if yql_opts["auto_partitioning_partition_size_mb"] is not None:
if ydb_opts["auto_partitioning_partition_size_mb"] is not None:
with_content.append(
f"AUTO_PARTITIONING_PARTITION_SIZE_MB = {yql_opts['auto_partitioning_partition_size_mb']}"
f"AUTO_PARTITIONING_PARTITION_SIZE_MB = {ydb_opts['auto_partitioning_partition_size_mb']}"
)
if yql_opts["auto_partitioning_min_partitions_count"] is not None:
if ydb_opts["auto_partitioning_min_partitions_count"] is not None:
with_content.append(
f"AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {yql_opts['auto_partitioning_min_partitions_count']}"
f"AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = {ydb_opts['auto_partitioning_min_partitions_count']}"
)
if yql_opts["auto_partitioning_max_partitions_count"] is not None:
if ydb_opts["auto_partitioning_max_partitions_count"] is not None:
with_content.append(
f"AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = {yql_opts['auto_partitioning_max_partitions_count']}"
f"AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = {ydb_opts['auto_partitioning_max_partitions_count']}"
)
if yql_opts["uniform_partitions"] is not None:
with_content.append(f"UNIFORM_PARTITIONS = {yql_opts['uniform_partitions']}")
if yql_opts["partition_at_keys"] is not None:
with_content.append(f"PARTITION_AT_KEYS = {yql_opts['partition_at_keys']}")
if ydb_opts["uniform_partitions"] is not None:
with_content.append(f"UNIFORM_PARTITIONS = {ydb_opts['uniform_partitions']}")
if ydb_opts["partition_at_keys"] is not None:
with_content.append(f"PARTITION_AT_KEYS = {ydb_opts['partition_at_keys']}")
if with_content:
with_content = ",\n".join(with_content)
return f"\nWITH (\n\t{with_content}\n)"
Expand Down

0 comments on commit 562e367

Please sign in to comment.