forked from vmware-archive/retail-demo-xd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlf_demo.py
executable file
·62 lines (48 loc) · 1.33 KB
/
sqlf_demo.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
#!/usr/bin/python
import sys
import commands
import os
import config
sqlfire_setup_sql = """
create table realtime_orders
(
customer_id INT NOT NULL,
order_id INT NOT NULL,
order_amount NUMERIC(10,2),
store_id VARCHAR(8),
num_items INT
) REPLICATE;
"""
sqlfire_query_sql = """
--Pull all of the records back
SELECT * FROM realtime_orders ORDER BY order_amount DESC, STORE_ID ASC;
--If spring xd is working, there should not be any orders under 5000
SELECT MIN(order_amount) FROM realtime_orders;
"""
sqlfire_teardown_sql = """
--Cleanup SQL
DROP TABLE realtime_orders;
"""
def setup():
sqlfcmd(sqlfire_setup_sql)
def teardown():
sqlfcmd(sqlfire_teardown_sql)
def query():
sqlfcmd(sqlfire_query_sql)
def shellcmd(cmd):
(status, output) = commands.getstatusoutput(cmd)
print output
def sqlfcmd(sql):
f = open("out.sql", "w")
f.write(sql)
f.close()
shellcmd("%s/bin/sqlf run -client-bind-address=%s -client-port=%s -file=./out.sql" % (config.sqlf_home,config.sqlf_hostname,config.sqlf_client_port))
def main():
args = sys.argv[1:]
if not args:
print "usage (type one option): setup | teardown | query";
sys.exit(1)
functionList = {'setup': setup, 'teardown': teardown, 'query': query}
functionList[args[0]]()
if __name__ == "__main__":
main()