forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sys_hll_sc.py
274 lines (245 loc) · 8.42 KB
/
test_sys_hll_sc.py
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
#!/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.
############################################################################
#
# @file test_sys_load.py
# @date 2017-04-10 15:02:22
# @brief This file is a test file for palo small load in complex scenarios.
#
#############################################################################
"""
测试hll data type
"""
import sys
import time
import pytest
sys.path.append("../")
from lib import palo_config
from lib import palo_client
from lib import util
from lib import palo_job
import palo_logger
import palo_exception
client = None
#日志 异常 对象
LOG = palo_logger.Logger.getLogger()
L = palo_logger.StructedLogMessage
PaloClientException = palo_exception.PaloException
config = palo_config.config
compare = 'test_query_qa.test'
def setup_module():
"""
setUp
"""
global client
client = palo_client.PaloClient(config.fe_host, config.fe_query_port, user=config.fe_user, \
password=config.fe_password)
client.init()
def wait_end(database_name):
"""
wait to finished
"""
ret = True
print('waitint for load...')
state = None
while ret:
job_list = client.get_load_job_list(database_name=database_name)
state = palo_job.LoadJob(job_list[-1]).get_state()
if state == "FINISHED" or state == "CANCELLED":
print(state)
ret = False
time.sleep(1)
assert state == "FINISHED"
def execute(line):
"""execte sql"""
print(line)
palo_result = client.execute(line)
print(palo_result)
return palo_result
def init(db_name, table_name):
"""
create db, table, bulk load, batch load
Args:
db_name:
table_name:
create_sql:
key_column:
Returns:
"""
line = 'DROP DATABASE IF EXISTS %s' % db_name
client.execute(line)
client.create_database(db_name)
client.use(db_name)
# client.execute('drop table if exists %s' % table_name)
line = 'CREATE TABLE %s (\
`id` int COMMENT "", \
`id1` tinyint COMMENT "", \
`c_float` float SUM COMMENT "", \
`hll_set` hll hll_union COMMENT "" \
) ENGINE=OLAP \
DISTRIBUTED BY HASH(`id`, `id1`) BUCKETS 5 \
PROPERTIES ( \
"storage_type" = "COLUMN" \
);' % table_name
execute(line)
line = 'insert into %s select k4, k1, k9, hll_hash(k9) from %s' % (table_name, compare)
execute(line)
wait_end(db_name)
@pytest.mark.skip()
def test_sc_add_hll_column():
"""
{
"title": "test_sys_hll_sc.test_sc_add_hll_column",
"describe": "schema change, add column and drop",
"tag": "autotest"
}
"""
"""schema change, add column and drop"""
db_name, table_name, invalied_name_1 = util.gen_name_list()
init(db_name, table_name)
# add column
column = ['hll_add hll hll_union', 'hll_add_1 hll hll_union']
ret = client.schema_change(table_name, add_column_list=column, is_wait=True)
assert ret, 'add hll column failed'
line = 'select hll_union_agg(hll_set), hll_union_agg(hll_add), hll_union_agg(hll_add_1) from %s' \
% table_name
ret1 = client.execute(line)
assert ret1 == ((58797, 0, 0),)
# drop column
column = ['hll_add_1']
ret = client.schema_change(table_name, drop_column_list=column, is_wait=True)
assert ret, 'drop hll column failed'
line = 'select hll_union_agg(hll_add), hll_union_agg(hll_add) from %s' % table_name
ret2 = client.execute(line)
assert ret1[0][2] == ret2[0][1]
assert ret1[0][1] == ret2[0][0]
client.clean(db_name)
def test_sc_drop_hll_column():
"""
{
"title": "test_sys_hll_sc.test_sc_drop_hll_column",
"describe": "schema change, drop column",
"tag": "function,p1,fuzz"
}
"""
"""schema change, drop column"""
db_name, table_name, invalied_name_1 = util.gen_name_list()
init(db_name, table_name)
column = ['hll_set']
ret = client.schema_change(table_name, drop_column_list=column, is_wait=True)
assert ret, 'drop hll column failed'
line = 'select hll_union_agg(hll_set) from %s' % table_name
flag = 0
try:
print(line)
ret = client.execute(line)
flag = 1
except Exception as e:
print(str(e))
assert flag == 0, 'expect select execute ok'
line = 'insert into %s select k4, k1, k9 from %s' % (table_name, compare)
execute(line)
wait_end(db_name)
line = 'select * from %s order by 1, 2, 3 limit 100' % table_name
print(line)
try:
ret = client.execute(line)
except Exception as e:
print(str(e))
assert 0 == 1
line = 'select count(*) from %s ' % table_name
ret = client.execute(line)
assert int(ret[0][0]) > 0, 'select count result error'
client.clean(db_name)
def test_sc_modified_hll_column():
"""
{
"title": "test_sys_hll_sc.test_sc_modified_hll_column",
"describe": "schema change, 将hll列变为其他类型/key",
"tag": "function,p1,fuzz"
}
"""
"""schema change, 将hll列变为其他类型/key"""
db_name, table_name, invalied_name_1 = util.gen_name_list()
init(db_name, table_name)
client.use(db_name)
# modify hll column, expect false
column_list = ['hll_set hll default "0"', 'hll_set int replace default "0" after id1',
'hll_set int replace default "0"', 'hll_set varchar(256) replace default ""',
'hll_set varchar(256) default "" after id1',
'hll_set char(256) replace default ""',
'hll_set bigint replace default ""', 'hll_set double replace default "0.01"',
'hll_set datetime replace default ""']
for column in column_list:
modify_column = [column, ]
flag = 1
try:
ret = client.schema_change(table_name, modify_column_list=modify_column, is_wait=True)
flag = 0
except Exception as e:
print(str(e))
assert flag == 1
order_list = ['id1', 'id', 'c_float', 'hll_set']
ret = client.schema_change(table_name, order_column_list=order_list, is_wait=True)
assert ret
# check order
ret = client.desc_table(table_name)
assert ret[3][0] == 'hll_set'
client.clean(db_name)
def test_sc_rollup_hll_column():
"""
{
"title": "test_sys_hll_sc.test_sc_rollup_hll_column",
"describe": "schema change, create rollup and delete rollup",
"tag": "function,p1"
}
"""
"""schema change, create rollup and delete rollup"""
db_name, table_name, index_name = util.gen_name_list()
init(db_name, table_name)
line1 = 'select id1, id, hll_union_agg(hll_set) from %s group by id1, id order by 1, 2' \
% table_name
ret1_1 = client.execute(line1)
line2 = 'select id1, hll_union_agg(hll_set) from %s group by id, id1 order by 1, 2' % table_name
ret2_1 = client.execute(line2)
index_name_derive = index_name + "_1"
rollup_column = ['id1', 'id', 'hll_set']
r = client.create_rollup_table(table_name, index_name, rollup_column, is_wait=True)
assert r
ret1_2 = client.execute(line1)
# ret2_2 = client.execute(line2)
util.check(ret1_1, ret1_2)
rollup_column_1 = ['id1', 'hll_set']
r = client.create_rollup_table(table_name, index_name_derive, rollup_column_1,
base_index_name=index_name, is_wait=True)
assert r
ret3_2 = client.execute(line2)
util.check(ret2_1, ret3_2)
try:
client.drop_rollup_table(table_name, index_name)
except Exception as e:
print(str(e))
assert 0 == 1
client.clean(db_name)
if __name__ == '__main__':
setup_module()
# test_sc_add_hll_column()
# test_sc_drop_hll_column()
# test_sc_modified_hll_column()
test_sc_rollup_hll_column()