-
Notifications
You must be signed in to change notification settings - Fork 0
/
tpch_ray.py
161 lines (133 loc) · 4.4 KB
/
tpch_ray.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
import os
import time
# TPC-H Dataset Path
path = os.environ['TPCH_DATASET_PATH']
#### MODIN Ray Configuration #############################
import modin.config as modin_cfg
modin_cfg.Engine.put("ray")
os.environ["MODIN_RANGE_PARTITIONING_GROUPBY"] = "False"
os.environ["__MODIN_AUTOIMPORT_PANDAS__"] = "1"
import modin.pandas as pd
# Warmup
for _ in range(100):
print(pd.DataFrame([modin_cfg.MinPartitionSize.get() * modin_cfg.NPartitions.get()]).to_numpy())
#####################################################################################
def q1(li):
df = li[(li.l_shipdate<='1998-09-02')]
df = df[['l_shipdate', 'l_returnflag', 'l_linestatus', 'l_quantity', 'l_extendedprice', 'l_discount', 'l_tax']]
df['a'] = ((df.l_extendedprice) * (1 - (df.l_discount)))
df['b'] = (((df.l_extendedprice) * (1 - (df.l_discount))) * (1 + (df.l_tax)))
df = df \
.groupby(['l_returnflag', 'l_linestatus']) \
.agg(
sum_qty=("l_quantity", "sum"),
sum_base_price=("l_extendedprice", "sum"),
sum_disc_price=("a", "sum"),
sum_charge=("b", "sum"),
avg_qty=("l_quantity", "mean"),
avg_price=("l_extendedprice", "mean"),
avg_disc=("l_discount", "mean"),
count_order=("l_returnflag", "count"),
).reset_index()
df = df.sort_values(by=['l_returnflag', 'l_linestatus'], ascending=[True, True])
return df
###########################################
def q6(li):
df = li[
(li.l_shipdate>='1994-01-01') &
(li.l_shipdate<'1995-01-01') &
(li.l_discount>=0.050) &
(li.l_discount<=0.070) &
(li.l_quantity<24)
]
df = df[['l_shipdate', 'l_discount', 'l_quantity', 'l_extendedprice']]
df['l_extendedpricel_discount'] = ((df.l_extendedprice) * (df.l_discount))
res = (df.l_extendedpricel_discount).sum()
return res
#####################################################################################
def main():
l_columnnames = [
'l_orderkey',
'l_partkey',
'l_suppkey',
'l_linenumber',
'l_quantity',
'l_extendedprice',
'l_discount',
'l_tax',
'l_returnflag',
'l_linestatus',
'l_shipdate',
'l_commitdate',
'l_receiptdate',
'l_shipinstruct',
'l_shipmode',
'l_comment'
]
l_data_types = {
'l_orderkey': int,
'l_partkey': int,
'l_suppkey': int,
'l_linenumber': int,
'l_quantity': float,
'l_extendedprice': float,
'l_discount': float,
'l_tax': float,
'l_returnflag': str,
'l_linestatus': str,
'l_shipinstruct': str,
'l_shipmode': str,
'l_comment': str
}
l_parse_dates = [
'l_shipdate',
'l_commitdate',
'l_receiptdate'
]
print("##############################################")
start = time.time()
li = pd.read_table(path + "lineitem.tbl", sep="|", names=l_columnnames, dtype=l_data_types, parse_dates=l_parse_dates, index_col=False)
end = time.time()
print(">>> Read CSV Time: ", 1000 * (end - start), " ms")
print("##############################################")
print(">>> Q1 Results:")
times = []
for _ in range(5):
start = time.time()
res = q1(li)
end = time.time()
times.append(1000 * (end - start))
print(res)
print("Time: ", sum(times) / len(times), " ms")
print(">>> Q1 Results:")
times = []
for _ in range(5):
start = time.time()
res = q1(li)
end = time.time()
times.append(1000 * (end - start))
print(res)
print("Time: ", sum(times) / len(times), " ms")
print("##############################################")
print(">>> Q6 Results:")
times = []
for _ in range(5):
start = time.time()
res = q6(li)
end = time.time()
times.append(1000 * (end - start))
print(res)
print("Time: ", sum(times) / len(times), " ms")
print(">>> Q6 Results:")
times = []
for _ in range(5):
start = time.time()
res = q6(li)
end = time.time()
times.append(1000 * (end - start))
print(res)
print("Time: ", sum(times) / len(times), " ms")
print("##############################################")
##########################################################
if __name__ == "__main__":
main()