forked from aregm/omniscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_ibis_tests.py
479 lines (446 loc) · 14.8 KB
/
run_ibis_tests.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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
import argparse
import os
import re
import sys
import traceback
from environment import CondaEnvironment
from server import OmnisciServer
from utils import combinate_requirements, find_free_port, str_arg_to_bool
def main():
omniscript_path = os.path.dirname(__file__)
omnisci_server = None
args = None
port_default_value = -1
parser = argparse.ArgumentParser(description="Run internal tests from ibis project")
required = parser._action_groups.pop()
optional = parser.add_argument_group("optional arguments")
omnisci = parser.add_argument_group("omnisci")
benchmark = parser.add_argument_group("benchmark")
mysql = parser.add_argument_group("mysql")
commits = parser.add_argument_group("commits")
possible_tasks = ["build", "test", "benchmark"]
benchmarks = ["ny_taxi", "santander", "census", "plasticc"]
# Task
required.add_argument(
"-task",
dest="task",
required=True,
help=f"Task for execute {possible_tasks}. Use , separator for multiple tasks",
)
# Environment
required.add_argument("-en", "--env_name", dest="env_name", help="Conda env name.")
optional.add_argument(
"-ec",
"--env_check",
dest="env_check",
default=False,
type=str_arg_to_bool,
help="Check if env exists. If it exists don't recreate.",
)
optional.add_argument(
"-s",
"--save_env",
dest="save_env",
default=False,
type=str_arg_to_bool,
help="Save conda env after executing.",
)
optional.add_argument(
"-r",
"--report_path",
dest="report_path",
default=os.path.join(omniscript_path, ".."),
help="Path to report file.",
)
optional.add_argument(
"-ci",
"--ci_requirements",
dest="ci_requirements",
default=os.path.join(omniscript_path, "ci_requirements.yml"),
help="File with ci requirements for conda env.",
)
optional.add_argument(
"-py",
"--python_version",
dest="python_version",
default="3.7",
help="File with ci requirements for conda env.",
)
# Ibis
required.add_argument(
"-i",
"--ibis_path",
dest="ibis_path",
required=True,
help="Path to ibis directory.",
)
# Ibis tests
optional.add_argument(
"-expression",
dest="expression",
default=" ",
help="Run tests which match the given substring test names and their parent "
"classes. Example: 'test_other', while 'not test_method' matches those "
"that don't contain 'test_method' in their names.",
)
# Omnisci server parameters
omnisci.add_argument(
"-executable",
dest="executable",
required=True,
help="Path to omnisci_server executable.",
)
omnisci.add_argument(
"--omnisci_cwd",
dest="omnisci_cwd",
help="Path to omnisci working directory. "
"By default parent directory of executable location is used. "
"Data directory is used in this location.",
)
omnisci.add_argument(
"-port",
dest="port",
default=port_default_value,
type=int,
help="TCP port number to run omnisci_server on.",
)
omnisci.add_argument(
"-http_port",
dest="http_port",
default=port_default_value,
type=int,
help="HTTP port number to run omnisci_server on.",
)
omnisci.add_argument(
"-calcite_port",
dest="calcite_port",
default=port_default_value,
type=int,
help="Calcite port number to run omnisci_server on.",
)
omnisci.add_argument(
"-user",
dest="user",
default="admin",
help="User name to use on omniscidb server.",
)
omnisci.add_argument(
"-password",
dest="password",
default="HyperInteractive",
help="User password to use on omniscidb server.",
)
omnisci.add_argument(
"-database_name",
dest="database_name",
default="agent_test_ibis",
help="Database name to use in omniscidb server.",
)
omnisci.add_argument(
"-table",
dest="table",
default="benchmark_table",
help="Table name name to use in omniscidb server.",
)
omnisci.add_argument(
"-ipc_conn",
dest="ipc_connection",
default=True,
type=str_arg_to_bool,
help="Table name name to use in omniscidb server.",
)
# Benchmark parameters
benchmark.add_argument(
"-bench_name", dest="bench_name", choices=benchmarks, help="Benchmark name.",
)
benchmark.add_argument(
"-data_file", dest="data_file", help="A datafile that should be loaded.",
)
benchmark.add_argument(
"-dfiles_num",
dest="dfiles_num",
default=1,
type=int,
help="Number of datafiles to input into database for processing.",
)
benchmark.add_argument(
"-iterations",
dest="iterations",
default=1,
type=int,
help="Number of iterations to run every query. Best result is selected.",
)
benchmark.add_argument(
"-dnd", default=False, type=str_arg_to_bool, help="Do not delete old table."
)
benchmark.add_argument(
"-dni",
default=False,
type=str_arg_to_bool,
help="Do not create new table and import any data from CSV files.",
)
benchmark.add_argument(
"-validation",
dest="validation",
default=False,
type=str_arg_to_bool,
help="validate queries results (by comparison with Pandas queries results).",
)
benchmark.add_argument(
"-optimizer",
choices=["intel", "stock"],
dest="optimizer",
default="intel",
help="Which optimizer is used",
)
benchmark.add_argument(
"-no_ibis",
default=False,
type=str_arg_to_bool,
help="Do not run Ibis benchmark, run only Pandas (or Modin) version",
)
benchmark.add_argument(
"-pandas_mode",
choices=["Pandas", "Modin_on_ray", "Modin_on_dask", "Modin_on_python"],
default="Pandas",
help="Specifies which version of Pandas to use: "
"plain Pandas, Modin runing on Ray or on Dask",
)
benchmark.add_argument(
"-ray_tmpdir",
default="/tmp",
help="Location where to keep Ray plasma store. "
"It should have enough space to keep -ray_memory",
)
benchmark.add_argument(
"-ray_memory",
default=200 * 1024 * 1024 * 1024,
help="Size of memory to allocate for Ray plasma store",
)
benchmark.add_argument(
"-no_ml",
default=False,
type=str_arg_to_bool,
help="Do not run machine learning benchmark, only ETL part",
)
optional.add_argument(
"-gpu_memory",
dest="gpu_memory",
type=int,
help="specify the memory of your gpu, default 16. "
"(This controls the lines to be used. Also work for CPU version. )",
default=16,
)
# MySQL database parameters
mysql.add_argument(
"-db_server",
dest="db_server",
default="localhost",
help="Host name of MySQL server.",
)
mysql.add_argument(
"-db_port",
dest="db_port",
default=3306,
type=int,
help="Port number of MySQL server.",
)
mysql.add_argument(
"-db_user",
dest="db_user",
help="Username to use to connect to MySQL database. "
"If user name is specified, script attempts to store results in MySQL "
"database using other -db-* parameters.",
)
mysql.add_argument(
"-db_pass",
dest="db_pass",
default="omniscidb",
help="Password to use to connect to MySQL database.",
)
mysql.add_argument(
"-db_name",
dest="db_name",
default="omniscidb",
help="MySQL database to use to store benchmark results.",
)
optional.add_argument(
"-db_table_etl",
dest="db_table_etl",
help="Table to use to store ETL results for this benchmark.",
)
optional.add_argument(
"-db_table_ml",
dest="db_table_ml",
help="Table to use to store ML results for this benchmark.",
)
# Additional information
commits.add_argument(
"-commit_omnisci",
dest="commit_omnisci",
default="1234567890123456789012345678901234567890",
help="Omnisci commit hash to use for tests.",
)
commits.add_argument(
"-commit_ibis",
dest="commit_ibis",
default="1234567890123456789012345678901234567890",
help="Ibis commit hash to use for tests.",
)
try:
args = parser.parse_args()
os.environ["IBIS_TEST_OMNISCIDB_DATABASE"] = args.database_name
os.environ["IBIS_TEST_DATA_DB"] = args.database_name
os.environ["IBIS_TEST_OMNISCIDB_PORT"] = str(args.port)
os.environ["PYTHONIOENCODING"] = "UTF-8"
os.environ["PYTHONUNBUFFERED"] = "1"
if args.port == port_default_value:
args.port = find_free_port()
if args.http_port == port_default_value:
args.http_port = find_free_port()
if args.calcite_port == port_default_value:
args.calcite_port = find_free_port()
required_tasks = args.task.split(",")
tasks = {}
for task in possible_tasks:
tasks[task] = True if task in required_tasks else False
if True not in list(tasks.values()):
print(
f"Only {list(tasks.keys())} are supported, {required_tasks} cannot find possible tasks"
)
sys.exit(1)
if args.python_version not in ["3.7", "3,6"]:
print(
f"Only 3.7 and 3.6 python versions are supported, {args.python_version} is not supported"
)
sys.exit(1)
ibis_requirements = os.path.join(
args.ibis_path, "ci", f"requirements-{args.python_version}-dev.yml"
)
requirements_file = "requirements.yml"
conda_env = CondaEnvironment(args.env_name)
print("PREPARING ENVIRONMENT")
combinate_requirements(
ibis_requirements, args.ci_requirements, requirements_file
)
conda_env.create(args.env_check, requirements_file=requirements_file)
if tasks["build"]:
install_ibis_cmdline = ["python3", os.path.join("setup.py"), "install"]
print("IBIS INSTALLATION")
conda_env.run(install_ibis_cmdline, cwd=args.ibis_path, print_output=False)
if tasks["test"]:
ibis_data_script = os.path.join(args.ibis_path, "ci", "datamgr.py")
dataset_download_cmdline = ["python3", ibis_data_script, "download"]
dataset_import_cmdline = [
"python3",
ibis_data_script,
"omniscidb",
"-P",
str(args.port),
"--database",
args.database_name,
]
report_file_name = (
f"report-{args.commit_ibis[:8]}-{args.commit_omnisci[:8]}.html"
)
if not os.path.isdir(args.report_path):
os.makedirs(args.report_path)
report_file_path = os.path.join(args.report_path, report_file_name)
ibis_tests_cmdline = [
"pytest",
"-m",
"omniscidb",
"--disable-pytest-warnings",
"-k",
args.expression,
f"--html={report_file_path}",
]
print("STARTING OMNISCI SERVER")
omnisci_server = OmnisciServer(
omnisci_executable=args.executable,
omnisci_port=args.port,
http_port=args.http_port,
calcite_port=args.calcite_port,
database_name=args.database_name,
omnisci_cwd=args.omnisci_cwd,
user=args.user,
password=args.password,
)
omnisci_server.launch()
print("PREPARING DATA")
conda_env.run(dataset_download_cmdline)
conda_env.run(dataset_import_cmdline)
print("RUNNING TESTS")
conda_env.run(ibis_tests_cmdline, cwd=args.ibis_path)
if tasks["benchmark"]:
# if not args.bench_name or args.bench_name not in benchmarks:
# print(
# f"Benchmark {args.bench_name} is not supported, only {benchmarks} are supported")
# sys.exit(1)
if not args.data_file:
print(
f"Parameter --data_file was received empty, but it is required for benchmarks"
)
sys.exit(1)
benchmark_script_path = os.path.join(
omniscript_path, "run_ibis_benchmark.py"
)
benchmark_cmd = ["python3", benchmark_script_path]
possible_benchmark_args = [
"bench_name",
"data_file",
"dfiles_num",
"iterations",
"dnd",
"dni",
"validation",
"optimizer",
"no_ibis",
"pandas_mode",
"ray_tmpdir",
"ray_memory",
"no_ml",
"gpu_memory",
"db_server",
"db_port",
"db_user",
"db_pass",
"db_name",
"db_table_etl",
"db_table_ml",
"executable",
"omnisci_cwd",
"port",
"http_port",
"calcite_port",
"user",
"password",
"ipc_connection",
"database_name",
"table",
"commit_omnisci",
"commit_ibis",
]
args_dict = vars(args)
args_dict["data_file"] = f"'{args_dict['data_file']}'"
for arg_name in list(parser._option_string_actions.keys()):
try:
pure_arg = re.sub(r"^--*", "", arg_name)
if pure_arg in possible_benchmark_args:
arg_value = args_dict[pure_arg]
if arg_value:
benchmark_cmd.extend([arg_name, str(arg_value)])
except KeyError:
pass
print(benchmark_cmd)
conda_env.run(benchmark_cmd)
except Exception:
traceback.print_exc(file=sys.stdout)
sys.exit(1)
finally:
if omnisci_server:
omnisci_server.terminate()
if args and args.save_env is False:
conda_env.remove()
if __name__ == "__main__":
main()