forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sys_insert_value.py
More file actions
305 lines (281 loc) · 9.62 KB
/
Copy pathtest_sys_insert_value.py
File metadata and controls
305 lines (281 loc) · 9.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/bin/env python
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
test insert into value
Date: 2019-07-24 13:42:40
"""
import sys
import re
sys.path.append("../")
from lib import palo_client
from lib import palo_config
from lib import util
from lib import palo_job
from lib import common
from data import schema as DATA
client = None
config = palo_config.config
def setup_module():
"""
set up
"""
global client
client = palo_client.get_client(config.fe_host, config.fe_query_port, user=config.fe_user,
password=config.fe_password, http_port=config.fe_http_port)
client.set_variables('enable_insert_strict', 0)
def test_insert_value():
"""
{
"title": "test_insert_value",
"describe": "测试insert into value基本用法",
"tag": "function,p1"
}
"""
database_name, table_name, index_name = util.gen_name_list()
client.clean(database_name)
ret = client.create_database(database_name)
assert ret
client.use(database_name)
ret = client.create_table(table_name, DATA.int_column_list, set_null=True)
assert ret
sql = 'insert into %s values(0, 0, 0, 0, 0)' % table_name
ret = client.execute(sql)
assert ret == ()
sql = 'select * from %s' % table_name
ret = client.execute(sql)
assert ret == ((0, 0, 0, 0, 0),)
sql = 'insert into %s values(0, 1, 1, 1, 1)' % table_name
ret = client.execute(sql)
assert ret == ()
sql = 'select * from %s' % table_name
ret = client.execute(sql)
assert ret == ((0, 1, 1, 0, 1),)
client.clean(database_name)
def test_insert_multi_value():
"""
{
"title": "test_insert_multi_value",
"describe": "测试insert into value插入多条数据, set_enable_strict",
"tag": "function,p1"
}
"""
database_name, table_name, index_name = util.gen_name_list()
client.clean(database_name)
ret = client.create_database(database_name)
assert ret
client.use(database_name)
ret = client.create_table(table_name, DATA.int_column_list)
assert ret
sql = 'insert into %s values(0,0,0,0,0),(1,1,1,1,1),(2,2,2,2,2),(null, null, null, null, null)' % table_name
ret = client.execute(sql)
assert ret == ()
sql = 'select * from %s order by k1' % table_name
ret = client.execute(sql)
exp = ((0, 0, 0, 0, 0), (1, 1, 1, 1, 1), (2, 2, 2, 2, 2))
util.check(ret, exp)
table_name += '_s'
ret = client.create_table(table_name, DATA.int_column_list)
assert ret
sql = 'set enable_insert_strict=1'
ret = client.execute(sql)
assert ret == ()
sql = 'insert into %s values(0,0,0,0,0),(1,1,1,1,1),(2,2,2,2,2),(null, null, null, null, null)' % table_name
flag = True
try:
ret = client.execute(sql)
print(ret)
flag = False
except Exception as e:
print(str(e))
assert flag
client.clean(database_name)
def test_insert_value_column_list():
"""
{
"title": "test_insert_value_column_list",
"describe": "测试insert into value指定列顺序",
"tag": "function,p1"
}
"""
database_name, table_name, index_name = util.gen_name_list()
client.clean(database_name)
ret = client.create_database(database_name)
assert ret
client.use(database_name)
ret = client.create_table(table_name, DATA.int_column_list)
assert ret
sql = 'insert into %s (v4, v3, v2, v1, k1) values(1,2,3,4,5)' % table_name
ret = client.execute(sql)
assert ret == ()
sql = 'select * from %s' % table_name
ret = client.execute(sql)
assert ret == ((5, 4, 3, 2, 1),)
sql = 'insert into %s (v4, v3, v2, v1) values(1,2,3,4)' % table_name
flag = True
try:
client.execute(sql)
flag = False
except Exception as e:
print(str(e))
assert flag
client.clean(database_name)
def test_insert_value_default():
"""
{
"title": "test_insert_value_default",
"describe": "测试insert into value缺省列使用默认值",
"tag": "function,p1"
}
"""
database_name, table_name, index_name = util.gen_name_list()
client.clean(database_name)
ret = client.create_database(database_name)
assert ret
client.use(database_name)
ret = client.create_table(table_name, DATA.int_column_list, set_null=True)
assert ret
sql = 'insert into %s (v4, v3, v2, v1) values(1,2,3,4)' % table_name
ret = client.execute(sql)
assert ret == ()
sql = 'select * from %s' % table_name
ret = client.execute(sql)
assert ret == ((None, 4, 3, 2, 1),)
sql = 'insert into %s (v4, v3, v2, v1) values(2,2,3,2), (NULL, NULL, NULL, 3)' % table_name
ret = client.execute(sql)
sql = 'select * from %s order by v1' % table_name
ret = client.execute(sql)
assert ret == ((None, 9, 3, 2, None),)
client.clean(database_name)
def test_insert_value_not_null():
"""
{
"title": "test_insert_value_not_null",
"describe": "测试insert into value的Null值插入",
"tag": "fuzz,p1"
}
"""
database_name, table_name, index_name = util.gen_name_list()
client.clean(database_name)
ret = client.create_database(database_name)
assert ret
client.use(database_name)
ret = client.create_table(table_name, DATA.baseall_column_list)
assert ret
sql = 'insert into %s values(null, null, null, null, null, null, null,' \
' null, null, null, null)' % table_name
flag = True
try:
ret = client.execute(sql)
flag = False
except Exception as e:
print(str(e))
assert flag == True, 'expect insert error'
sql = 'select * from %s' % table_name
ret = client.execute(sql)
assert ret == ()
table_name += '_n'
ret = client.create_table(table_name, DATA.baseall_column_list, set_null=True)
assert ret
sql = 'insert into %s values(null, null, null, null, null, null, null,' \
' null, null, null, null)' % table_name
ret = client.execute(sql)
assert ret == ()
sql = 'select * from %s' % table_name
ret = client.execute(sql)
assert ret == ((None, None, None, None, None, None, None, None, None, None, None),)
client.clean(database_name)
def test_insert_select_not_null():
"""
{
"title": "test_insert_select_not_null",
"describe": "测试insert into select的Null值插入",
"tag": "fuzz,p1"
}
"""
database_name, table_name, index_name = util.gen_name_list()
client.clean(database_name)
ret = client.create_database(database_name)
assert ret
client.use(database_name)
ret = client.create_table(table_name, DATA.int_column_list)
client.set_variables('enable_insert_strict', 0)
assert ret
sql = 'insert into %s SELECT a.k1 AS n1, b.k2 AS n2, 1, 2, 3 FROM %s.baseall a ' \
'LEFT OUTER JOIN %s.bigtable b ON a.k1 = b.k1 + 10' \
% (table_name, config.palo_db, config.palo_db)
ret = client.execute(sql)
assert ret == ()
sql1 = 'select * from %s order by k1' % table_name
ret1 = client.execute(sql1)
sql2 = 'SELECT a.k1 AS n1, b.k2 AS n2, 1, 2, 3 FROM %s.baseall a ' \
'LEFT OUTER JOIN %s.bigtable b ON a.k1 = b.k1 + 10 where b.k2 is not null' \
' order by n1' % (config.palo_db, config.palo_db)
ret2 = client.execute(sql2)
util.check(ret1, ret2)
client.clean(database_name)
def test_insert_value_special_data():
"""
{
"title": "test_insert_value_special_data",
"describe": "测试使用insert into value插入特殊值, insert into tinyint溢出bug",
"tag": "fuzz,p1"
}
"""
database_name, table_name, index_name = util.gen_name_list()
client.clean(database_name)
ret = client.create_database(database_name)
assert ret
client.use(database_name)
ret = client.create_table(table_name, DATA.baseall_column_list, set_null=True)
assert ret
sql = 'insert into %s(k6) values("hello world")' % table_name
flag = True
client.set_variables('enable_insert_strict', 'true')
try:
ret = client.execute(sql)
flag = False
except Exception as e:
print(str(e))
assert flag == True
client.set_variables('enable_insert_strict', 'false')
ret = client.execute(sql)
assert ret == ()
sql = 'insert into %s(k10) values("2001-01-01 10-00-00")' % table_name
ret = client.execute(sql)
assert ret == ()
sql = 'insert into %s(k5) values(100.1005)' % table_name
ret = client.execute(sql)
sql = 'insert into %s(k1) values(-56)' % table_name
ret = client.execute(sql)
sql = 'insert into %s(k1) values(200)' % table_name
flag = True
try:
ret = client.execute(sql)
flag = False
except Exception as e:
print(str(e))
assert flag
sql = 'select * from %s order by k1, k5, k6, k10' % table_name
assert common.check_by_file('./data/LOAD/insert_value.data', sql=sql, client=client)
client.clean(database_name)
def teardown_module():
"""tear down"""
pass
if __name__ == '__main__':
setup_module()