Skip to content

Commit

Permalink
Fixed list type as field result in sqlalchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby committed Jun 28, 2023
1 parent 2956229 commit c169035
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixed list type as field result in sqlalchemy

## 3.3.4 ##
* Fixed handle stop partition request from server

Expand Down
9 changes: 9 additions & 0 deletions tests/sqlalchemy/test_inspect.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from sqlalchemy import text

import ydb

import sqlalchemy as sa
Expand All @@ -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]
5 changes: 5 additions & 0 deletions ydb/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
}


Expand Down

0 comments on commit c169035

Please sign in to comment.