44import  ydb 
55
66
7- query  =  """ SELECT $a AS value"" " 
7+ query_template  =  "DECLARE $a as %s;  SELECT $a AS value" 
88
99
1010def  test_select_implicit_int (pool : ydb .QuerySessionPool ):
11+     query  =  query_template  %  "Int64" 
1112    expected_value  =  111 
1213    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
1314    actual_value  =  res [0 ].rows [0 ]["value" ]
1415    assert  expected_value  ==  actual_value 
1516
1617
1718def  test_select_implicit_float (pool : ydb .QuerySessionPool ):
19+     query  =  query_template  %  "Double" 
1820    expected_value  =  11.1 
1921    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
2022    actual_value  =  res [0 ].rows [0 ]["value" ]
2123    assert  expected_value  ==  pytest .approx (actual_value )
2224
2325
2426def  test_select_implicit_bool (pool : ydb .QuerySessionPool ):
27+     query  =  query_template  %  "Bool" 
2528    expected_value  =  False 
2629    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
2730    actual_value  =  res [0 ].rows [0 ]["value" ]
2831    assert  expected_value  ==  actual_value 
2932
3033
3134def  test_select_implicit_str (pool : ydb .QuerySessionPool ):
35+     query  =  query_template  %  "Utf8" 
3236    expected_value  =  "text" 
3337    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
3438    actual_value  =  res [0 ].rows [0 ]["value" ]
3539    assert  expected_value  ==  actual_value 
3640
3741
3842def  test_select_implicit_bytes (pool : ydb .QuerySessionPool ):
43+     query  =  query_template  %  "String" 
3944    expected_value  =  b"text" 
4045    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
4146    actual_value  =  res [0 ].rows [0 ]["value" ]
4247    assert  expected_value  ==  actual_value 
4348
4449
4550def  test_select_implicit_list (pool : ydb .QuerySessionPool ):
51+     query  =  query_template  %  "List<Int64>" 
4652    expected_value  =  [1 , 2 , 3 ]
4753    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
4854    actual_value  =  res [0 ].rows [0 ]["value" ]
4955    assert  expected_value  ==  actual_value 
5056
5157
5258def  test_select_implicit_dict (pool : ydb .QuerySessionPool ):
59+     query  =  query_template  %  "Dict<Utf8, Int64>" 
5360    expected_value  =  {"a" : 1 , "b" : 2 }
5461    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
5562    actual_value  =  res [0 ].rows [0 ]["value" ]
5663    assert  expected_value  ==  actual_value 
5764
5865
5966def  test_select_implicit_list_nested (pool : ydb .QuerySessionPool ):
67+     query  =  query_template  %  "List<Dict<Utf8, Int64>>" 
6068    expected_value  =  [{"a" : 1 }, {"b" : 2 }]
6169    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
6270    actual_value  =  res [0 ].rows [0 ]["value" ]
6371    assert  expected_value  ==  actual_value 
6472
6573
6674def  test_select_implicit_dict_nested (pool : ydb .QuerySessionPool ):
75+     query  =  query_template  %  "Dict<Utf8, List<Int64>>" 
6776    expected_value  =  {"a" : [1 , 2 , 3 ], "b" : [4 , 5 ]}
6877    res  =  pool .execute_with_retries (query , parameters = {"$a" : expected_value })
6978    actual_value  =  res [0 ].rows [0 ]["value" ]
7079    assert  expected_value  ==  actual_value 
7180
7281
7382def  test_select_implicit_custom_type_raises (pool : ydb .QuerySessionPool ):
83+     query  =  query_template  %  "Struct" 
84+ 
7485    class  CustomClass :
7586        pass 
7687
@@ -80,25 +91,29 @@ class CustomClass:
8091
8192
8293def  test_select_implicit_empty_list_raises (pool : ydb .QuerySessionPool ):
94+     query  =  query_template  %  "List<Int64>" 
8395    expected_value  =  []
8496    with  pytest .raises (ValueError ):
8597        pool .execute_with_retries (query , parameters = {"$a" : expected_value })
8698
8799
88100def  test_select_implicit_empty_dict_raises (pool : ydb .QuerySessionPool ):
101+     query  =  query_template  %  "Dict<Int64, Int64>" 
89102    expected_value  =  {}
90103    with  pytest .raises (ValueError ):
91104        pool .execute_with_retries (query , parameters = {"$a" : expected_value })
92105
93106
94107def  test_select_explicit_primitive (pool : ydb .QuerySessionPool ):
108+     query  =  query_template  %  "Int64" 
95109    expected_value  =  111 
96110    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , ydb .PrimitiveType .Int64 )})
97111    actual_value  =  res [0 ].rows [0 ]["value" ]
98112    assert  expected_value  ==  actual_value 
99113
100114
101115def  test_select_explicit_list (pool : ydb .QuerySessionPool ):
116+     query  =  query_template  %  "List<Int64>" 
102117    expected_value  =  [1 , 2 , 3 ]
103118    type_  =  ydb .ListType (ydb .PrimitiveType .Int64 )
104119    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -107,6 +122,7 @@ def test_select_explicit_list(pool: ydb.QuerySessionPool):
107122
108123
109124def  test_select_explicit_dict (pool : ydb .QuerySessionPool ):
125+     query  =  query_template  %  "Dict<Utf8, Utf8>" 
110126    expected_value  =  {"key" : "value" }
111127    type_  =  ydb .DictType (ydb .PrimitiveType .Utf8 , ydb .PrimitiveType .Utf8 )
112128    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -115,6 +131,7 @@ def test_select_explicit_dict(pool: ydb.QuerySessionPool):
115131
116132
117133def  test_select_explicit_empty_list_not_raises (pool : ydb .QuerySessionPool ):
134+     query  =  query_template  %  "List<Int64>" 
118135    expected_value  =  []
119136    type_  =  ydb .ListType (ydb .PrimitiveType .Int64 )
120137    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):
123140
124141
125142def  test_select_explicit_empty_dict_not_raises (pool : ydb .QuerySessionPool ):
143+     query  =  query_template  %  "Dict<Utf8, Utf8>" 
126144    expected_value  =  {}
127145    type_  =  ydb .DictType (ydb .PrimitiveType .Utf8 , ydb .PrimitiveType .Utf8 )
128146    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):
131149
132150
133151def  test_select_typedvalue_full_primitive (pool : ydb .QuerySessionPool ):
152+     query  =  query_template  %  "Int64" 
134153    expected_value  =  111 
135154    typed_value  =  ydb .TypedValue (expected_value , ydb .PrimitiveType .Int64 )
136155    res  =  pool .execute_with_retries (query , parameters = {"$a" : typed_value })
@@ -139,6 +158,7 @@ def test_select_typedvalue_full_primitive(pool: ydb.QuerySessionPool):
139158
140159
141160def  test_select_typedvalue_implicit_primitive (pool : ydb .QuerySessionPool ):
161+     query  =  query_template  %  "Int64" 
142162    expected_value  =  111 
143163    typed_value  =  ydb .TypedValue (expected_value )
144164    res  =  pool .execute_with_retries (query , parameters = {"$a" : typed_value })
@@ -147,6 +167,8 @@ def test_select_typedvalue_implicit_primitive(pool: ydb.QuerySessionPool):
147167
148168
149169def  test_select_typevalue_custom_type_raises (pool : ydb .QuerySessionPool ):
170+     query  =  query_template  %  "Struct" 
171+ 
150172    class  CustomClass :
151173        pass 
152174
0 commit comments