5 from heavy.thrift.ttypes
import TDashboard
8 parser = argparse.ArgumentParser(description=
'Basic benchmark for system tables')
9 parser.add_argument(
'--host', help=
'HEAVY.AI server address', default=
'localhost')
10 parser.add_argument(
'--port', help=
'HEAVY.AI server port', default=
'6273')
11 parser.add_argument(
'--user', help=
'HEAVY.AI user name', default=
'admin')
12 parser.add_argument(
'--password', help=
'HEAVY.AI password', default=
'HyperInteractive')
13 parser.add_argument(
'--database_count', help=
'Number of databases to create', default=1)
14 parser.add_argument(
'--table_count', help=
'Number of tables to create', default=100)
15 parser.add_argument(
'--dashboard_count', help=
'Number of dashboards to create', default=100)
16 parser.add_argument(
'--user_count', help=
'Number of users to create', default=10)
17 parser.add_argument(
'--role_count', help=
'Number of roles to create', default=5)
18 parser.add_argument(
'--skip_object_creation', help=
'Skip creation of database objects', default=
False)
19 parser.add_argument(
'--skip_object_deletion', help=
'Skip deletion of database objects', default=
False)
20 parser.add_argument(
'--tag', help=
'Tag for test run')
21 return parser.parse_args(args)
24 def __init__(self, user, password, db_name, host):
25 self.
con = pymapd.connect(user=user, password=password, dbname=db_name, host=host)
29 return self.cursor.execute(sql)
32 dashboard = TDashboard(dashboard_name = dashboard_name)
33 return self.con.create_dashboard(dashboard)
36 heavyai_con.query(f
"CREATE DATABASE test_db_{db_id}")
39 heavyai_con.query(f
"CREATE TABLE test_table_{table_id} (a INTEGER, b TEXT)")
41 heavyai_con.query(f
"INSERT INTO test_table_{table_id} VALUES ({i}, 'abc_{i}')")
42 heavyai_con.query(f
"SELECT AVG(a) FROM test_table_{table_id}")
45 heavyai_con.create_dashboard(f
"test_dashboard_{dashboard_id}")
48 heavyai_con.query(f
"CREATE USER test_user_{user_id} (password = 'test_pass')")
51 heavyai_con.query(f
"CREATE ROLE test_role_{role_id}")
54 heavyai_con.query(f
"GRANT test_role_{role_id} TO test_user_{user_id}")
57 heavyai_con.query(f
"GRANT SELECT ON DATABASE test_db_{db_id} TO test_role_{role_id}")
60 heavyai_con.query(f
"GRANT SELECT ON DATABASE test_db_{db_id} TO test_user_{user_id}")
63 heavyai_con.query(f
"DROP DATABASE test_db_{db_id}")
66 heavyai_con.query(f
"DROP USER test_user_{user_id}")
69 heavyai_con.query(f
"DROP ROLE test_role_{role_id}")
72 query = f
"SELECT COUNT(*) FROM {table_name}"
73 result = heavyai_con.query(query)
74 print(f
"Query: {query}, Execution time: {result._result.execution_time_ms}ms")
75 query = f
"SELECT * FROM {table_name} LIMIT 10"
76 result = heavyai_con.query(query)
77 print(f
"Query: {query}, Execution time: {result._result.execution_time_ms}ms")
80 return HeavyAICon(options.user, options.password, db_name, options.host)
84 default_db =
"heavyai"
87 if not options.skip_object_creation:
88 print(
"Creating database objects")
89 for db_id
in range(options.database_count):
91 db_name = f
"test_db_{db_id}"
93 for table_id
in range(options.table_count):
95 print(f
"{options.table_count} tables created for {db_name}")
96 for dashboard_id
in range(options.dashboard_count):
98 print(f
"{options.dashboard_count} dashboards created for {db_name}")
99 print(f
"{options.database_count} databases created")
102 for user_id
in range(options.user_count):
104 print(f
"{options.user_count} users created")
106 for role_id
in range(options.role_count):
108 print(f
"{options.role_count} roles created")
110 half_roles = int(options.role_count / 2)
111 for user_id
in range(options.user_count):
112 for role_id
in range(half_roles):
115 if options.database_count > 0:
117 for role_id
in range(half_roles):
120 half_users = int(options.user_count / 2)
121 for user_id
in range(half_users):
124 system_tables = [
"tables",
135 print(
"Executing system table queries")
136 for table_name
in system_tables:
139 if not options.skip_object_deletion:
141 print(
"Dropping databases")
142 for db_id
in range(options.database_count):
145 print(
"Dropping users")
146 for user_id
in range(options.user_count):
149 print(
"Dropping roles")
150 for role_id
in range(options.role_count):
153 if __name__ ==
"__main__":
def query_and_time_system_table
def create_insert_and_select_from_table
def grant_user_table_select
def grant_role_table_select