From ff10c76d3b6b9bd07e74b4ebc5988b58bf719abc Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Wed, 28 Jun 2023 12:16:03 +0300 Subject: [PATCH 1/2] Fixed list type as field result in sqlalchemy --- CHANGELOG.md | 2 ++ tests/sqlalchemy/test_inspect.py | 9 +++++++++ ydb/convert.py | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bedccc9..361f05c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Fixed list type as field result in sqlalchemy + ## 3.3.5 ## * Fixed use positional argument instead of named in WriterAsyncIO.__del__ * Fixed release buffer while read topic by one messages 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, } From a434c51c01ab93dec58824ab0174bec7a0db7d5f Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Wed, 28 Jun 2023 16:48:09 +0300 Subject: [PATCH 2/2] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 361f05c0..0751fdf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -* Fixed list type as field result in sqlalchemy +* Add list type to converter from result to native type (fix problem with get list result in dbapi/sqlalchemy) ## 3.3.5 ## * Fixed use positional argument instead of named in WriterAsyncIO.__del__