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" 
7484    class  CustomClass :
7585        pass 
7686
@@ -80,25 +90,29 @@ class CustomClass:
8090
8191
8292def  test_select_implicit_empty_list_raises (pool : ydb .QuerySessionPool ):
93+     query  =  query_template  %  "List<Int64>" 
8394    expected_value  =  []
8495    with  pytest .raises (ValueError ):
8596        pool .execute_with_retries (query , parameters = {"$a" : expected_value })
8697
8798
8899def  test_select_implicit_empty_dict_raises (pool : ydb .QuerySessionPool ):
100+     query  =  query_template  %  "Dict<Int64, Int64>" 
89101    expected_value  =  {}
90102    with  pytest .raises (ValueError ):
91103        pool .execute_with_retries (query , parameters = {"$a" : expected_value })
92104
93105
94106def  test_select_explicit_primitive (pool : ydb .QuerySessionPool ):
107+     query  =  query_template  %  "Int64" 
95108    expected_value  =  111 
96109    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , ydb .PrimitiveType .Int64 )})
97110    actual_value  =  res [0 ].rows [0 ]["value" ]
98111    assert  expected_value  ==  actual_value 
99112
100113
101114def  test_select_explicit_list (pool : ydb .QuerySessionPool ):
115+     query  =  query_template  %  "List<Int64>" 
102116    expected_value  =  [1 , 2 , 3 ]
103117    type_  =  ydb .ListType (ydb .PrimitiveType .Int64 )
104118    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -107,6 +121,7 @@ def test_select_explicit_list(pool: ydb.QuerySessionPool):
107121
108122
109123def  test_select_explicit_dict (pool : ydb .QuerySessionPool ):
124+     query  =  query_template  %  "Dict<Utf8, Utf8>" 
110125    expected_value  =  {"key" : "value" }
111126    type_  =  ydb .DictType (ydb .PrimitiveType .Utf8 , ydb .PrimitiveType .Utf8 )
112127    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -115,6 +130,7 @@ def test_select_explicit_dict(pool: ydb.QuerySessionPool):
115130
116131
117132def  test_select_explicit_empty_list_not_raises (pool : ydb .QuerySessionPool ):
133+     query  =  query_template  %  "List<Int64>" 
118134    expected_value  =  []
119135    type_  =  ydb .ListType (ydb .PrimitiveType .Int64 )
120136    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -123,6 +139,7 @@ def test_select_explicit_empty_list_not_raises(pool: ydb.QuerySessionPool):
123139
124140
125141def  test_select_explicit_empty_dict_not_raises (pool : ydb .QuerySessionPool ):
142+     query  =  query_template  %  "Dict<Utf8, Utf8>" 
126143    expected_value  =  {}
127144    type_  =  ydb .DictType (ydb .PrimitiveType .Utf8 , ydb .PrimitiveType .Utf8 )
128145    res  =  pool .execute_with_retries (query , parameters = {"$a" : (expected_value , type_ )})
@@ -131,6 +148,7 @@ def test_select_explicit_empty_dict_not_raises(pool: ydb.QuerySessionPool):
131148
132149
133150def  test_select_typedvalue_full_primitive (pool : ydb .QuerySessionPool ):
151+     query  =  query_template  %  "Int64" 
134152    expected_value  =  111 
135153    typed_value  =  ydb .TypedValue (expected_value , ydb .PrimitiveType .Int64 )
136154    res  =  pool .execute_with_retries (query , parameters = {"$a" : typed_value })
@@ -139,6 +157,7 @@ def test_select_typedvalue_full_primitive(pool: ydb.QuerySessionPool):
139157
140158
141159def  test_select_typedvalue_implicit_primitive (pool : ydb .QuerySessionPool ):
160+     query  =  query_template  %  "Int64" 
142161    expected_value  =  111 
143162    typed_value  =  ydb .TypedValue (expected_value )
144163    res  =  pool .execute_with_retries (query , parameters = {"$a" : typed_value })
@@ -147,6 +166,7 @@ def test_select_typedvalue_implicit_primitive(pool: ydb.QuerySessionPool):
147166
148167
149168def  test_select_typevalue_custom_type_raises (pool : ydb .QuerySessionPool ):
169+     query  =  query_template  %  "Struct" 
150170    class  CustomClass :
151171        pass 
152172
0 commit comments