File size: 1,531 Bytes
065fee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import configparser
import os
import time
import typing

import redshift_connector

conf: configparser.ConfigParser = configparser.ConfigParser()
root_path: str = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
conf.read(root_path + "/config.ini")

root_path = os.path.dirname(os.path.abspath(__file__))
sql: typing.TextIO = open(root_path + "/test.sql", "r", encoding="utf8")
sqls: typing.List[str] = sql.readlines()
sqls = [_sql.replace("\n", "") for _sql in sqls]
sql.close()

conn: redshift_connector.Connection = redshift_connector.connect(
    database=conf.get("ci-cluster", "database"),
    host=conf.get("ci-cluster", "host"),
    port=conf.getint("default-test", "port"),
    user=conf.get("ci-cluster", "test_user"),
    password=conf.get("ci-cluster", "test_password"),
    ssl=True,
    sslmode=conf.get("default-test", "sslmode"),
    iam=False,
)

cursor: redshift_connector.Cursor = conn.cursor()
for _sql in sqls:
    cursor.execute(_sql)

result: typing.Tuple[typing.List[int], ...] = cursor.fetchall()
print("fetch {result} rows".format(result=result))

print("start calculate fetch time")
for val in [True, False]:
    print("merge_socket_read={val}".format(val=val))
    start_time: float = time.time()
    cursor.execute("select * from performance", merge_socket_read=val)
    results: typing.Tuple[typing.List[int], ...] = cursor.fetchall()
    print("Took {0} seconds.".format(time.time() - start_time))
    print("fetch {result} rows".format(result=len(results)))

cursor.close()
conn.commit()