-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_validation.py
50 lines (35 loc) · 1.65 KB
/
gen_validation.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
import subprocess
import sys
import os
import argparse
# TPC-H qgen generates a query from a query template
_qgen = './qgen'
if __name__ == '__main__':
env = os.environ.copy()
p = argparse.ArgumentParser(prog=sys.argv[0])
p.add_argument('--tpch', dest='tpch', default="{HOME}/escience/tpch_2_17_0".format(HOME=env['HOME']))
args = p.parse_args(sys.argv[1:])
# allow specify either root tpch dir or dbgen dir
if os.path.isdir(os.path.join(args.tpch, 'dbgen')):
tpch_utils = os.path.join(args.tpch, 'dbgen')
else:
tpch_utils = args.tpch
here = os.path.abspath(os.path.dirname(__file__))
# used to point qgen to the query templates directory
env['DSS_QUERY'] = '{here}/templates'.format(here=here)
cwd = os.getcwd()
def generate(query):
intermf = '{cwd}/_q{query}.myl'.format(cwd=cwd, query=query)
resultf = '{cwd}/q{query}.myl'.format(cwd=cwd, query=query)
try:
subprocess.check_call('cd {path}; {qgen} -d {query} >{of}'.format(path=tpch_utils, qgen=_qgen, query=query, of=intermf), shell=True, env=env, stderr=sys.stdout)
except subprocess.CalledProcessError as e:
sys.stderr.write('WARN: query {0} failed to generate: {1}\n'.format(query, e))
return False
# qgen puts in windows line endings ^M, remove them;
# also qgen doesn't allow ':' so sub them in for __C__
subprocess.check_call("sed -e 's/{cr}//g' -e 's/__C__/:/g' <{inf} >{of}".format(of=resultf, inf=intermf, query=query, cr=chr(13)), shell=True, stderr=sys.stdout)
os.remove(intermf)
return True
for q in range(1, 22+1):
generate(q)