4
4
import ydb
5
5
6
6
7
- query = """ SELECT $a AS value"" "
7
+ query_template = "DECLARE $a as %s; SELECT $a AS value"
8
8
9
9
10
10
def test_select_implicit_int (pool : ydb .QuerySessionPool ):
11
+ query = query_template % "Int64"
11
12
expected_value = 111
12
13
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
13
14
actual_value = res [0 ].rows [0 ]["value" ]
14
15
assert expected_value == actual_value
15
16
16
17
17
18
def test_select_implicit_float (pool : ydb .QuerySessionPool ):
19
+ query = query_template % "Double"
18
20
expected_value = 11.1
19
21
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
20
22
actual_value = res [0 ].rows [0 ]["value" ]
21
23
assert expected_value == pytest .approx (actual_value )
22
24
23
25
24
26
def test_select_implicit_bool (pool : ydb .QuerySessionPool ):
27
+ query = query_template % "Bool"
25
28
expected_value = False
26
29
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
27
30
actual_value = res [0 ].rows [0 ]["value" ]
28
31
assert expected_value == actual_value
29
32
30
33
31
34
def test_select_implicit_str (pool : ydb .QuerySessionPool ):
35
+ query = query_template % "Utf8"
32
36
expected_value = "text"
33
37
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
34
38
actual_value = res [0 ].rows [0 ]["value" ]
35
39
assert expected_value == actual_value
36
40
37
41
38
42
def test_select_implicit_bytes (pool : ydb .QuerySessionPool ):
43
+ query = query_template % "String"
39
44
expected_value = b"text"
40
45
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
41
46
actual_value = res [0 ].rows [0 ]["value" ]
42
47
assert expected_value == actual_value
43
48
44
49
45
50
def test_select_implicit_list (pool : ydb .QuerySessionPool ):
51
+ query = query_template % "List<Int64>"
46
52
expected_value = [1 , 2 , 3 ]
47
53
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
48
54
actual_value = res [0 ].rows [0 ]["value" ]
49
55
assert expected_value == actual_value
50
56
51
57
52
58
def test_select_implicit_dict (pool : ydb .QuerySessionPool ):
59
+ query = query_template % "Dict<Utf8, Int64>"
53
60
expected_value = {"a" : 1 , "b" : 2 }
54
61
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
55
62
actual_value = res [0 ].rows [0 ]["value" ]
56
63
assert expected_value == actual_value
57
64
58
65
59
66
def test_select_implicit_list_nested (pool : ydb .QuerySessionPool ):
67
+ query = query_template % "List<Dict<Utf8, Int64>>"
60
68
expected_value = [{"a" : 1 }, {"b" : 2 }]
61
69
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
62
70
actual_value = res [0 ].rows [0 ]["value" ]
63
71
assert expected_value == actual_value
64
72
65
73
66
74
def test_select_implicit_dict_nested (pool : ydb .QuerySessionPool ):
75
+ query = query_template % "Dict<Utf8, List<Int64>>"
67
76
expected_value = {"a" : [1 , 2 , 3 ], "b" : [4 , 5 ]}
68
77
res = pool .execute_with_retries (query , parameters = {"$a" : expected_value })
69
78
actual_value = res [0 ].rows [0 ]["value" ]
70
79
assert expected_value == actual_value
71
80
72
81
73
82
def test_select_implicit_custom_type_raises (pool : ydb .QuerySessionPool ):
83
+ query = query_template % "Struct"
84
+
74
85
class CustomClass :
75
86
pass
76
87
@@ -80,25 +91,29 @@ class CustomClass:
80
91
81
92
82
93
def test_select_implicit_empty_list_raises (pool : ydb .QuerySessionPool ):
94
+ query = query_template % "List<Int64>"
83
95
expected_value = []
84
96
with pytest .raises (ValueError ):
85
97
pool .execute_with_retries (query , parameters = {"$a" : expected_value })
86
98
87
99
88
100
def test_select_implicit_empty_dict_raises (pool : ydb .QuerySessionPool ):
101
+ query = query_template % "Dict<Int64, Int64>"
89
102
expected_value = {}
90
103
with pytest .raises (ValueError ):
91
104
pool .execute_with_retries (query , parameters = {"$a" : expected_value })
92
105
93
106
94
107
def test_select_explicit_primitive (pool : ydb .QuerySessionPool ):
108
+ query = query_template % "Int64"
95
109
expected_value = 111
96
110
res = pool .execute_with_retries (query , parameters = {"$a" : (expected_value , ydb .PrimitiveType .Int64 )})
97
111
actual_value = res [0 ].rows [0 ]["value" ]
98
112
assert expected_value == actual_value
99
113
100
114
101
115
def test_select_explicit_list (pool : ydb .QuerySessionPool ):
116
+ query = query_template % "List<Int64>"
102
117
expected_value = [1 , 2 , 3 ]
103
118
type_ = ydb .ListType (ydb .PrimitiveType .Int64 )
104
119
res = pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -107,6 +122,7 @@ def test_select_explicit_list(pool: ydb.QuerySessionPool):
107
122
108
123
109
124
def test_select_explicit_dict (pool : ydb .QuerySessionPool ):
125
+ query = query_template % "Dict<Utf8, Utf8>"
110
126
expected_value = {"key" : "value" }
111
127
type_ = ydb .DictType (ydb .PrimitiveType .Utf8 , ydb .PrimitiveType .Utf8 )
112
128
res = pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -115,6 +131,7 @@ def test_select_explicit_dict(pool: ydb.QuerySessionPool):
115
131
116
132
117
133
def test_select_explicit_empty_list_not_raises (pool : ydb .QuerySessionPool ):
134
+ query = query_template % "List<Int64>"
118
135
expected_value = []
119
136
type_ = ydb .ListType (ydb .PrimitiveType .Int64 )
120
137
res = pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -123,6 +140,7 @@ def test_select_explicit_empty_list_not_raises(pool: ydb.QuerySessionPool):
123
140
124
141
125
142
def test_select_explicit_empty_dict_not_raises (pool : ydb .QuerySessionPool ):
143
+ query = query_template % "Dict<Utf8, Utf8>"
126
144
expected_value = {}
127
145
type_ = ydb .DictType (ydb .PrimitiveType .Utf8 , ydb .PrimitiveType .Utf8 )
128
146
res = pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -131,6 +149,7 @@ def test_select_explicit_empty_dict_not_raises(pool: ydb.QuerySessionPool):
131
149
132
150
133
151
def test_select_typedvalue_full_primitive (pool : ydb .QuerySessionPool ):
152
+ query = query_template % "Int64"
134
153
expected_value = 111
135
154
typed_value = ydb .TypedValue (expected_value , ydb .PrimitiveType .Int64 )
136
155
res = pool .execute_with_retries (query , parameters = {"$a" : typed_value })
@@ -139,6 +158,7 @@ def test_select_typedvalue_full_primitive(pool: ydb.QuerySessionPool):
139
158
140
159
141
160
def test_select_typedvalue_implicit_primitive (pool : ydb .QuerySessionPool ):
161
+ query = query_template % "Int64"
142
162
expected_value = 111
143
163
typed_value = ydb .TypedValue (expected_value )
144
164
res = pool .execute_with_retries (query , parameters = {"$a" : typed_value })
@@ -147,6 +167,8 @@ def test_select_typedvalue_implicit_primitive(pool: ydb.QuerySessionPool):
147
167
148
168
149
169
def test_select_typevalue_custom_type_raises (pool : ydb .QuerySessionPool ):
170
+ query = query_template % "Struct"
171
+
150
172
class CustomClass :
151
173
pass
152
174
0 commit comments