1
1
import pytest
2
2
from numpy import ndarray
3
+ from typing import Sequence
3
4
4
5
from tests .e2e .test_driver import PySQLPytestTestCase
5
6
@@ -17,7 +18,10 @@ def table_fixture(self, connection_details):
17
18
CREATE TABLE IF NOT EXISTS pysql_test_complex_types_table (
18
19
array_col ARRAY<STRING>,
19
20
map_col MAP<STRING, INTEGER>,
20
- struct_col STRUCT<field1: STRING, field2: INTEGER>
21
+ struct_col STRUCT<field1: STRING, field2: INTEGER>,
22
+ array_array_col ARRAY<ARRAY<STRING>>,
23
+ array_map_col ARRAY<MAP<STRING, INTEGER>>,
24
+ map_array_col MAP<STRING, ARRAY<STRING>>
21
25
)
22
26
"""
23
27
)
@@ -28,7 +32,10 @@ def table_fixture(self, connection_details):
28
32
VALUES (
29
33
ARRAY('a', 'b', 'c'),
30
34
MAP('a', 1, 'b', 2, 'c', 3),
31
- NAMED_STRUCT('field1', 'a', 'field2', 1)
35
+ NAMED_STRUCT('field1', 'a', 'field2', 1),
36
+ ARRAY(ARRAY('a','b','c')),
37
+ ARRAY(MAP('a', 1, 'b', 2, 'c', 3)),
38
+ MAP('a', ARRAY('a', 'b', 'c'), 'b', ARRAY('d', 'e'))
32
39
)
33
40
"""
34
41
)
@@ -38,7 +45,7 @@ def table_fixture(self, connection_details):
38
45
39
46
@pytest .mark .parametrize (
40
47
"field,expected_type" ,
41
- [("array_col" , ndarray ), ("map_col" , list ), ("struct_col" , dict )],
48
+ [("array_col" , ndarray ), ("map_col" , list ), ("struct_col" , dict ), ( "array_array_col" , ndarray ), ( "array_map_col" , ndarray ), ( "map_array_col" , list ) ],
42
49
)
43
50
def test_read_complex_types_as_arrow (self , field , expected_type , table_fixture ):
44
51
"""Confirms the return types of a complex type field when reading as arrow"""
@@ -47,10 +54,10 @@ def test_read_complex_types_as_arrow(self, field, expected_type, table_fixture):
47
54
result = cursor .execute (
48
55
"SELECT * FROM pysql_test_complex_types_table LIMIT 1"
49
56
).fetchone ()
50
-
57
+
51
58
assert isinstance (result [field ], expected_type )
52
59
53
- @pytest .mark .parametrize ("field" , [("array_col" ), ("map_col" ), ("struct_col" )])
60
+ @pytest .mark .parametrize ("field" , [("array_col" ), ("map_col" ), ("struct_col" ), ( "array_array_col" ), ( "array_map_col" ), ( "map_array_col" ) ])
54
61
def test_read_complex_types_as_string (self , field , table_fixture ):
55
62
"""Confirms the return type of a complex type that is returned as a string"""
56
63
with self .cursor (
0 commit comments