diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d0a326..91ff395f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Fixed list type as field result in sqlalchemy + ## 3.3.4 ## * Fixed handle stop partition request from server diff --git a/tests/sqlalchemy/test_inspect.py b/tests/sqlalchemy/test_inspect.py index 6cfe5749..f73bf39c 100644 --- a/tests/sqlalchemy/test_inspect.py +++ b/tests/sqlalchemy/test_inspect.py @@ -1,3 +1,5 @@ +from sqlalchemy import text + import ydb import sqlalchemy as sa @@ -18,3 +20,10 @@ def test_get_columns(driver_sync, sa_engine): ] session.execute_scheme("DROP TABLE test") + + +def test_query_list(sa_engine): + with sa_engine.connect() as connection: + result = connection.execute(text("SELECT AsList(1, 2, 3, 4) as c")) + row = next(result) + assert row["c"] == [1, 2, 3, 4] diff --git a/ydb/convert.py b/ydb/convert.py index 4a1b007f..6c4164bc 100644 --- a/ydb/convert.py +++ b/ydb/convert.py @@ -227,6 +227,10 @@ def _optional_type_to_native(type_pb): return types.OptionalType(type_to_native(type_pb.optional_type.item)) +def _list_type_to_native(type_pb): + return types.ListType(type_to_native(type_pb.list_type.item)) + + def _primitive_type_to_native(type_pb): return _primitive_type_by_id.get(type_pb.type_id) @@ -240,6 +244,7 @@ def _null_type_factory(type_pb): "type_id": _primitive_type_to_native, "decimal_type": _decimal_type_to_native, "null_type": _null_type_factory, + "list_type": _list_type_to_native, }