7 from pathlib
import Path
10 parser = argparse.ArgumentParser(description=
'Basic benchmark for update queries')
11 parser.add_argument(
'-s',
'--host', help=
'HEAVY.AI server address', default=
'localhost')
12 parser.add_argument(
'-p',
'--port', help=
'HEAVY.AI server port', default=
'6273')
13 parser.add_argument(
'-d',
'--db', help=
'HEAVY.AI database name', default=
'heavyai')
14 parser.add_argument(
'-u',
'--user', help=
'HEAVY.AI user name', default=
'admin')
15 parser.add_argument(
'-w',
'--password', help=
'HEAVY.AI password', default=
'HyperInteractive')
16 parser.add_argument(
'-r',
'--num_rows', help=
'Number of rows to benchmark with', type=int, default=1_000_000)
17 parser.add_argument(
'-t',
'--tag', help=
'Tag for test run')
18 return parser.parse_args(args)
22 self.
con = pymapd.connect(user=user, password=pw, dbname=dbname, host=host)
26 return self.cursor.execute(sql)
29 drop_sql = f
"DROP TABLE IF EXISTS {table_name}"
30 create_sql = f
"CREATE TABLE {table_name} (a INTEGER, b INTEGER, c INTEGER, d DOUBLE)"
31 import_sql = f
"COPY {table_name} FROM '{file_path.absolute()}'"
32 heavyai_con.query(drop_sql)
33 heavyai_con.query(create_sql)
34 heavyai_con.query(import_sql)
37 df = pd.DataFrame(np.random.randint(0, num_rows, size=(num_rows, 4)), columns=[
'a',
'b',
'c',
'd'])
38 df = df.astype(np.int32)
42 query = f
"UPDATE {table_name} SET a = a + 10, c = c + b, d = d * 2 WHERE MOD(b, 2) = 0"
45 result = heavyai_con.query(query)
46 query_times.append(result._result.execution_time_ms)
48 print(f
"Test tag: {tag}\nQuery: {query}\nRaw times(ms): {query_times}\n"
49 f
"Avg: {np.average(query_times)}\nMin: {np.min(query_times)}\n"
50 f
"Max: {np.max(query_times)}\nMedian: {np.median(query_times)}")
54 heavyai_con =
HeavyAICon(options.user, options.password, options.db, options.host)
56 file_path = Path(f
"{options.num_rows}_rand.csv")
57 if not file_path.exists():
59 df.to_csv(file_path, index=
False)
61 table_name =
"update_bench_test"
66 if __name__ ==
"__main__":
def create_and_import_into_table